Board index » delphi » Saving and retrieving commatext from Ini (Config) file?

Saving and retrieving commatext from Ini (Config) file?

Delphi 5.0 Pro

I want to save the contents of a combo box to an Ini file (Config) and then
load it back up on form Activate.

Here is what I have....

var
  SiteList: String;

procedure TfrmAddItemDlg.FormShow(Sender: TObject);
begin
cbSite.Items.Clear;
cbSite.Items.CommaText:= SiteList;
end;

procedure TfrmAddItemDlg.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 SiteList:= edtSite.Items.CommaText;
end;

This is what shows in the ini file....

[SITES]
List="Ogdenburg Public Library","Lisbon Beach"

However, this is what I get in the combobox...

Ogdensburg
Public
Library"
Lisbon
Beac

Can anyone help me?

Shane
Sh...@Holmes.net

 

Re:Saving and retrieving commatext from Ini (Config) file?


Quote
In article <89jp2d$m...@bornews.borland.com>, THolmes wrote:
> I want to save the contents of a combo box to an Ini file (Config) and then
> load it back up on form Activate.

I have already asked a question about this query in another thread.

Please give us time to respond before asking again.

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
 (Unsolicited e-mail replies will most likely be ignored)

Re:Saving and retrieving commatext from Ini (Config) file?


I debugged until I was blue in the face, I am now using the following
methods to accomplish what I was hoping the commatext property would.

Thanks for your input though!

Shane

function TfrmTracker.WriteStrings(List: TStrings; Separator: Char): String;
var I: Integer;
begin
 Result:= '';
 for I:= 0 to List.Count-1 do
 begin
  if I <> List.Count-1 then
   Result:= Result+List.Strings[I]+Separator
  else
   Result:= Result+List.Strings[I];
 end;
end;

procedure TfrmTracker.ReadStrings(Str: String; Separator: Char;
                                  List: TStrings);
var I: Integer;
    S: String;
begin
 List.Clear;
 for I:= 1 to length(Str) do
  if (Str[I] =  Separator) OR (I = length(Str)+1) then
  begin
   List.Add(S);
   S:= '';
  end
  else
   S:= S + Str[I];
   if S <> '' then
   List.Add(S);
end;

procedure TfrmTracker.ReadIniFile(IFile: TIniFile);
begin
 //.................
 ReadStrings(IFile.ReadString('SITES','List',''),',',SiteList);
end;

procedure TfrmTracker.WriteIniFile(IFile: TIniFile);
begin
  //.................
 IFile.WriteString('SITES','List',WriteStrings(SiteList,','));
end;

Re:Saving and retrieving commatext from Ini (Config) file?


This might be ok for SMALL lengths of text, but for larger amounts of text, it
is VERY inefficient and would be slow by comparison to the commatext method.
Please tell me exactly what you want to achieve and I can help you. I don't
have your original post. Sorry.

I TOO use the commatext a bit for different reasons. One thing I wanted to do
was to take a memo field that the user could type a bunch of stuff into and
needed to save it into an INI file into ONE LINE. I found a cool way to do it
and when I read it back in the memo field looks perfect and it even handles
memos with several lines of text, ie: carriage returns to produce multiple
paragraphs.

TIP: When writing out the  commatext field, do this:

writemethod('"'+????.CommaText+'"');

instead of this:

writemethod(????.CommandText);

Davie

Quote
THolmes wrote:
> I debugged until I was blue in the face, I am now using the following
> methods to accomplish what I was hoping the commatext property would.

> Thanks for your input though!

> Shane

> function TfrmTracker.WriteStrings(List: TStrings; Separator: Char): String;
> var I: Integer;
> begin
>  Result:= '';
>  for I:= 0 to List.Count-1 do
>  begin
>   if I <> List.Count-1 then
>    Result:= Result+List.Strings[I]+Separator
>   else
>    Result:= Result+List.Strings[I];
>  end;
> end;

> procedure TfrmTracker.ReadStrings(Str: String; Separator: Char;
>                                   List: TStrings);
> var I: Integer;
>     S: String;
> begin
>  List.Clear;
>  for I:= 1 to length(Str) do
>   if (Str[I] =  Separator) OR (I = length(Str)+1) then
>   begin
>    List.Add(S);
>    S:= '';
>   end
>   else
>    S:= S + Str[I];
>    if S <> '' then
>    List.Add(S);
> end;

> procedure TfrmTracker.ReadIniFile(IFile: TIniFile);
> begin
>  //.................
>  ReadStrings(IFile.ReadString('SITES','List',''),',',SiteList);
> end;

> procedure TfrmTracker.WriteIniFile(IFile: TIniFile);
> begin
>   //.................
>  IFile.WriteString('SITES','List',WriteStrings(SiteList,','));
> end;

Other Threads