Reputation: 181
I have a TForm which contains a lot of TFrame's
and i want to be able to save all properties like TEdit.text
, TCheckbox.checked
and so on of the TFrame's
to one shared storage. How do i accomplish that with TJvFormStorage
and TJvAppIniFileStorage
?
Workflow is the following:
TJvAppIniFileStorage
there, set the FileName
property.TjvFormStorage
there, set the AppStoragePath
property..text
property to the TJvFormStorage
with the Form Storage Designer.I tried to make it happen with passing a TJvAppIniStorage
created in the TForm
to the TFrame's
and to set the .AppStorage
of the TJvFormStorage
property at runtime. This did not save the predefined properties, but writeString
worked.
// FormShow event of the Main Form
procedure TMainForm.FormShow(Sender: TObject);
begin
frFrame.init(fs_AppIniStorage); // fs_AppIniStorage is the component on the MainForm
end;
// The init function of the TFrame
procedure TfrFrame.init(var FormStorage : TJvAppIniFileStorage);
begin
fs_FrameStorage.AppStorage := FormStorage;
fs_FrameStorage.WriteString('test','test'); // <- is written into the storage
end;
This has written the following into the file:
[Test] // fs_FrameStorage.AppStoragePath
test=test// fs_FrameStorage.WriteString
Also i tried to manually save and load the component properties with:
fs_FrameStorage.SaveFormPlacement; // At .FormClose of TMainForm
fs_FrameStorage.RestoreFromPlacement; // At TfrFrame.init
After this the file looked like that:
[Test] // fs_FrameStorage.AppStoragePath
test=test// fs_FrameStorage.WriteString
FormVersion=0 // new
Then I tried to set the TFrame.fs_FrameStorage.AppStoragePath
in TMainForm
in the Delphi Designer.
Which resulted into the same.
Calling StoredProps
results in the entered edit.text
:
ShowMessage(fs_FrameStorage.StoredProps.Text);
// Shows ed_Frame.text
When I add both components on the Same TForm
, TMainForm
in this case, it works as expected, saving all entered properties. But I can't access the Frames
child components from the MainForm
with the TJvFormStorage
placed in the MainForm
.
Upvotes: 1
Views: 742
Reputation: 1
Had the same Problem today, but with saving grid related properties.
As TJvFormStorage is a Class of TJvFormPlacement, calling TJvFormPlacement.RestorePlacement
and TJvFormPlacement.SavePlacement
worked for me.
Here my situation and solution, if anybody else falls into the same pit:
I had one main form with a TJvFormStorage (A) (working like a charm) and a panel, loaded with an external VCL-Frame at runtime, including a TjvUltimGrid. The goal was to load and save the grid-properties into the same AppStorage.
TJvFormPlacement.RestorePlacement
on Storage B after loading the frameTJvFormPlacement.SavePlacement
on the close event of the main formUpvotes: 0