So funktioniert die Sache mit ner beliebigen Komponente (evtl. im initialization-Abschnitt die Klasse Registrieren):
Delphi-Quellcode:
function CloneComponent(Component: TComponent): TComponent;
var
Stream: TStream;
OldName, NewName: string;
i: Integer;
begin
Stream := TMemoryStream.Create;
try
OldName := Component.Name;
i := 0;
repeat
Inc(i);
NewName := RightStr(Component.ClassName, Pred(Length(Component.ClassName))) + IntToStr(i);
until not Assigned(Component.Owner.FindComponent(NewName));
Component.Name := NewName;
Stream.WriteComponent(Component);
Component.Name := OldName;
Stream.Seek(0, soFromBeginning);
Result := TComponentClass(FindClass(Component.ClassName)).Create(Component.Owner);
Stream.ReadComponent(Result);
finally
FreeAndNil(Stream);
end;
end;
MfG
Stefan