Solved

Copy component  properties

Posted on 2002-06-07
2
524 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

11 Experts available now in Live!

Get 1:1 Help Now