[Lazarus] Examples of IniPropStorage?

Michael Van Canneyt michael at freepascal.org
Sun Feb 22 13:39:05 CET 2009



On Sat, 21 Feb 2009, David W Noon wrote:

> 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.

Attached is a patch for propertystorage; Could you please test if
you still get the access violation when the patch was applied ?

Michael.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: propertystorage.diff
Type: text/x-patch
Size: 565 bytes
Desc: 
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20090222/7d9eb00d/attachment-0007.bin>


More information about the Lazarus mailing list