Solved

SAVE TCOMPONENTLIST

Posted on 2002-05-29
3
170 Views
Last Modified: 2010-04-04
SAVE TCOMPONENTLIST

How to save context of TComponentList ?

Thanks.
0
Comment
Question by:zuipo
3 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 7042293
Please be more precise on "context".
Any tComponent is derived from TPersistend and can save itself to a file. The .dfm files are nothing but the saved Forms.
0
 

Author Comment

by:zuipo
ID: 7042405
In my TComponentList are different components including TForm. Do you have solution how to save it in file ?

Thanks.
0
 
LVL 9

Accepted Solution

by:
ITugay earned 300 total points
ID: 7043995
hi all,

function ComponentToString(Component: TComponent): string;

var
  BinStream:TMemoryStream;
  StrStream: TStringStream;
  s: string;
begin
  BinStream := TMemoryStream.Create;
  try
    StrStream := TStringStream.Create(s);
    try
      BinStream.WriteComponent(Component);
      BinStream.Seek(0, soFromBeginning);
      ObjectBinaryToText(BinStream, StrStream);
      StrStream.Seek(0, soFromBeginning);
      Result:= StrStream.DataString;
    finally
      StrStream.Free;

    end;
  finally
    BinStream.Free
  end;
end;



procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  L: TStringList;
  I: Integer;
begin
  L := TStringList.Create;
  for I := 0 to Panel1.ControlCount - 1 do
    L.Add(ComponentToString(Panel1.Controls[I]));
  L.SaveToFile('F:\comps.txt');
  L.Free;
end;

-----
Igor.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now