Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Copy component  properties

Posted on 2002-06-07
2
570 Views
Last Modified: 2010-04-04
Hello,

Is there a general way to copy component properties (Only the published) from component A to B  (same type)
I  assume that not every component that descendent from TComponent have update assign procedure.

thank u
Asi
0
Comment
Question by:asi
2 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 7061428
Yes it is possible. This trick is often used to implement Assign.
Component A writes itself to a TMemoryStream and component B reads itself from that same stream.
Have a look at TWriter.WriteComponent in the help for a starter.
0
 
LVL 1

Accepted Solution

by:
alx512 earned 50 total points
ID: 7061685
function CopyComponent(Component: TComponent; NewComponentName: String): TComponent;
var
  Stream: TMemoryStream;
  S: String;
begin
  Result := TComponentClass(Component.ClassType).Create(Component.Owner);
  S := Component.Name;
  Component.Name := NewComponentName;
  Stream := TMemoryStream.Create;
  try
    Stream.WriteComponent(Component);
    Component.Name := S;
    Stream.Seek(0, soFromBeginning);
    Stream.ReadComponent(Result);
  finally
    Stream.Free;
  end;
end;

procedure TForm1.CopyButtonClick(Sender: TObject);
var
  NumberEdit2: TNumberEdit;
begin
  NumberEdit2 := CopyComponent(NumberEdit1, 'NumberEdit2') as TNumberEdit;
  NumberEdit2.Top := NumberEdit2.Top + 50;
  InsertControl(NumberEdit2);
end;
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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