Solved

SAVE TCOMPONENTLIST

Posted on 2002-05-29
3
169 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

9 Experts available now in Live!

Get 1:1 Help Now