RAD Studio |  |

Loading and Saving String Lists
See Also
Collapse All

String-list objects provide SaveToFile and LoadFromFile methods that let you store a string list in a text file and load a text file into a string list. Each line in the text file corresponds to a string in the list. Using these methods, you could, for example, create a simple text editor by loading a file into a memo component, or save lists of items for combo boxes.

The following example loads a copy of the MyFile.ini file into a memo field and makes a backup copy called MyFile.bak.

Copy Code

    procedure EditWinIni;
    var  FileName: string;{ storage for file name }
    begin  FileName := 'c:\Program Files\MyProgram\MyFile.ini'{ set the file name }

      with Form1.Memo1.Lines do   begin
        LoadFromFile(FileName);{ load from file }
        SaveToFile(ChangeFileExt(FileName, '.bak'));{ save into backup file }
      end;
    end;

Copy Code

    void __fastcall EditWinIni()
    {
      AnsiString FileName = "C:\\Program Files\\MyFile.ini";
      Form1->Memo1->Lines->LoadFromFile(FileName);      // load from file

Copy Code

See Also

Manipulating Strings in a List

Creating a New String List

Associating Objects with a String List

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!