Jump to content
azrael_11

How can i retrive components from a dat file;

Recommended Posts

Based to this Implementing Object Persistence using Streams i think i manage to save all the runtime created components of my form in a dat file.

 

with this code when the form closes

 

procedure TForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
  strm: TFileStream;
  vi: integer;
begin
  strm := TFileStream.Create('MyComponentList.txt', fmCreate);
  for vi := 0 to ComponentCount - 1 do
    strm.WriteComponent(Components[vi]);
  strm.Free;
end;

Now how can i load all the components in FormCreate or In FormShow event.

 

In tutorial can read-load a component by its name.

So how can i get the name of all components in the dat file so i can read-load?

Share this post


Link to post

Try streaming Tpanel with child objects in it 

object Panel1: TPanel
  Left = 536
  Top = 24
  Width = 251
  Height = 106
  Caption = 'Panel1'
  ParentBackground = False
  TabOrder = 0
  object Button2: TButton
    Left = 24
    Top = 16
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Left = 112
    Top = 72
    Width = 121
    Height = 21
    TabOrder = 1
    Text = 'Edit1'
  end
end

Simply copy paste these into a form in design window. then follow  delphi - How to save and restore a form? - Stack Overflow  

 

 

  • Like 1

Share this post


Link to post
On 4/25/2021 at 2:17 AM, azrael_11 said:

Based to this Implementing Object Persistence using Streams i think i manage to save all the runtime created components of my form in a dat file.

That article is written for saving a single component to a file, not for saving multiple components.  I would suggest saving the TForm itself rather than each of its child components individually.

  • Thanks 1

Share this post


Link to post
20 hours ago, Remy Lebeau said:

 I would suggest saving the TForm itself rather than each of its child components individually.

I think this is the best way. Thanks

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×