Show: Object Pascal C++
Display Preferences

Loading and Saving String Lists

From Appmethod Topics
Jump to: navigation, search

Go Up to Working with String Lists

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:

Object Pascal:

 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;

C++:

void __fastcall EditWinIni()
{
AnsiString FileName = "C:\\WINDOWS\\MyFile.INI";// set the file name
Form1->Memo1->Lines->LoadFromFile(FileName); // load from file
Form1->Memo1->Lines->SaveToFile(ChangeFileExt(FileName, ".BAK")); // save to backup
}

See Also

Personal tools
In other languages