11-07-2012, 11:44 AM
شكراا لك تم الامر الكود بعد التجربة كالاتي :
شكراا مرة اخرى اخي وجزاك الله كل خير
كود :
uses TypInfo;
procedure CloneProperties(const Source: TControl; const Dest: TControl);
var
ms: TMemoryStream;
OldName: string;
begin
OldName := Source.Name;
Source.Name := ''; // needed to avoid Name collision
try
ms := TMemoryStream.Create;
try
ms.WriteComponent(Source);
ms.Position := 0;
ms.ReadComponent(Dest);
finally
ms.Free;
end;
finally
Source.Name := OldName;
end;
end;
procedure CloneEvents(Source, Dest: TControl);
var
I: Integer;
PropList: TPropList;
begin
for I := 0 to GetPropList(Source.ClassInfo, [tkMethod], @PropList) - 1 do
SetMethodProp(Dest, PropList[I], GetMethodProp(Source, PropList[I]));
end;
procedure DuplicateChildren(const ParentSource: TWinControl;
const WithEvents: Boolean = True);
var
I: Integer;
CurrentControl, ClonedControl: TControl;
begin
for I := ParentSource.ControlCount - 1 downto 0 do
begin
CurrentControl := ParentSource.Controls[I];
ClonedControl := TControlClass(CurrentControl.ClassType).Create(CurrentControl.Owner);
ClonedControl.Parent := ParentSource;
CloneProperties(CurrentControl, ClonedControl);
ClonedControl.Name := CurrentControl.Name + '_';
if WithEvents then
CloneEvents(CurrentControl, ClonedControl);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MyTab:TTabSheet;
CurrentControl, ClonedControl: TControl;
i: Integer;
begin
MyTab := TTabSheet.Create(PageControl1);
MyTab.PageControl := PageControl1;
MyTab.Name := 'TabSheet' + IntToStr(PageControl1.PageCount);
for I := PageControl1.Pages[0].ControlCount - 1 downto 0 do
begin
CurrentControl := PageControl1.Pages[0].Controls[I];
ClonedControl := TControlClass(CurrentControl.ClassType).Create(CurrentControl.Owner);
ClonedControl.Parent := MyTab;
CloneProperties(CurrentControl, ClonedControl);
ClonedControl.Name := CurrentControl.Name +IntToStr(PageControl1.PageCount);
end;
end;شكراا مرة اخرى اخي وجزاك الله كل خير

