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.
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;
void __fastcall EditWinIni() { AnsiString FileName = "C:\\Program Files\\MyFile.ini"; Form1->Memo1->Lines->LoadFromFile(FileName); // load from file
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|