Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-02

Examples of IniPropStorage?

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

David W Noon

Hi all,

Are there any examples of the usage of TIniPropStorage objects? I have searched the examples supplied with Lazarus, but could find none.

If there are none, could somebody please give me a quick sample they have knocked up for their own use? Thanks in advance.

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================

Reply by email

Luca Olivetti
to David W Noon

En/na David W Noon ha escrit:

Show quoted text 8 lines
Hi all, Are there any examples of the usage of TIniPropStorage objects? I have searched the examples supplied with Lazarus, but could find none. 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;

Bye

Luca

Reply by email

David W Noon
to Luca Olivetti
Luca Olivetti wrote
En/na David W Noon ha escrit:

[snip]

Show quoted text 21 lines
> 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 Noon) =======================================================================

Reply by email

Luca Olivetti
to David W Noon

En/na David W Noon ha escrit:

Show quoted text 29 lines
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?

I don't know, and actually I don't really care: I just set the values I want to save/restore using SessionProperties of the form.

Show quoted text 5 lines
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;

Why don't you just put Name_field.Text in SessionProperties?

Bye

Luca

Reply by email

Michael Van Canneyt
to David W Noon: [snip] Thanks for that, Luca. The code is putting me in the right direction. Now, how do…
David W Noon wrote 44 lines
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://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090222/7d9eb00d/attachment-0001.bin

Reply by email

David W Noon
to Michael Van Canneyt
Michael Van Canneyt wrote 10 lines
On Sat, 21 Feb 2009, David W Noon wrote: > 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 ?

That patch fixes the problem. Many thanks!

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================

Reply by email

Michael Van Canneyt
to David W Noon
David W Noon wrote 14 lines
On Sun, 2009-02-22 at 13:39 +0100, Michael Van Canneyt wrote: > On Sat, 21 Feb 2009, David W Noon wrote: > > > 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 ? That patch fixes the problem. Many thanks!

In that case:

To the Lazarus Crew: OK if I commit the patch ?

Michael.

Reply by email

Vincent Snijders
to Michael Van Canneyt
Michael Van Canneyt wrote 11 lines
On Sun, 22 Feb 2009, David W Noon wrote: > On Sun, 2009-02-22 at 13:39 +0100, Michael Van Canneyt wrote: >> Attached is a patch for propertystorage; Could you please test if >> you still get the access violation when the patch was applied ? > That patch fixes the problem. Many thanks! In that case: To the Lazarus Crew: OK if I commit the patch ?

Yes, that is OK.

Thanks,
Vincent

Reply by email