On Sat, 2009-02-21 at 19:06 +0100, Luca Olivetti wrote: > En/na David W Noon ha escrit: [snip] > > If there are none, could somebody please give me a quick sample they > > have knocked up for their own use? Thanks in advance. > > Drop a TIniPropStorage on the form, let's call it FormStorage. > Put all properties you want to preserve in the form SessionProperties > (there's a nice dialog to add what you want). > If you know beforehand the location of the .ini file, just set it in the > TIniPropstorage at design time, otherwise assign it in FormCreate. > Also in FormCreate call restore. > When you want to save, just call save, e.g.: > > procedure TSettingsForm.FormCreate(Sender: TObject); > begin > FormStorage.IniFileName:=SettingsFilename; > FormStorage.Restore; > end; > > procedure TFormAjustes.SaveButtonClick(Sender: TObject); > begin > FormStorage.Save; > end;
Thanks for that, Luca. The code is putting me in the right direction. Now, how do I actually extract key/value pairs from it and store key/value pairs into it? The only property I have found that looks likely is the StoredValues collection, but this is too kludgey to be true, e.g.: Name_field.Text := Ini_props.StoredValues['Name'].Value; That seems to be the sequence required to get a string, and it seems to segfault if the .INI file is empty. Moreover, the ReadString() method also segfaults if I use that method instead of the property, e.g.: Name_field.Text := Ini_props.ReadString('Name', '<missing>'); The second approach has much neater syntax, plus it allows me to specify a default value if the required section of the .INI file lacks a value for that key. But I get access violations when the .INI file is empty. So, any more tips down at the key/value pair level? -- Regards, Dave [RLU #314465] ======================================================================= david.w.n...@ntlworld.com (David W Noon) ======================================================================= _______________________________________________ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus