المشاركات : 71
المواضيع 21
:
: 0
الإنتساب : Dec 2011
السلام عليكم ورحمة الله وبركاته
في PageControl عندا اضافة اول صفحة ووضعنا فيها المكونات
كيفيــة اضهار صفحة ثانية وثالثة بنفس المكونات
وشكراا
المشاركات : 975
المواضيع 50
:
: 218
الإنتساب : Feb 2008
السلام عليكم
الكود معدل على السريع للعمل على PageControl
المصدر
كود :
http://stackoverflow.com/questions/239002/duplicating-components-at-run-time
مجرب على دلفي 7...
كود :
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;
procedure TForm1.CloneProperties(const Source: TControl; const Dest: TControl);
var
ms: TMemoryStream;
OldName: string;
begin
OldName := Source.Name;
Source.Name := '';
try
ms := TMemoryStream.Create;
try
ms.WriteComponent(Source);
ms.Position := 0;
ms.ReadComponent(Dest);
finally
ms.Free;
end;
finally
Source.Name := OldName;
end;
end;
السلام عليكم و رحمة الله
و لرب نازلة يضيق لها الفتى ذرعا و عند الله منها المخرج
ضاقت فلما استحكمت حلقاتها فرجت و كنت اضنها لا تفرج
المشاركات : 71
المواضيع 21
:
: 0
الإنتساب : Dec 2011
شكراا لك تم الامر الكود بعد التجربة كالاتي :
كود :
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;
شكراا مرة اخرى اخي وجزاك الله كل خير
المشاركات : 975
المواضيع 50
:
: 218
الإنتساب : Feb 2008
CloneEvents لست بحاجة الى هذا الاجراء الكود الذي وضعته يكفيك بالتمام و الكمال الا في حالة اردت ان تكون للمكونات الجديدة نفس Events ...
و لرب نازلة يضيق لها الفتى ذرعا و عند الله منها المخرج
ضاقت فلما استحكمت حلقاتها فرجت و كنت اضنها لا تفرج
المشاركات : 975
المواضيع 50
:
: 218
الإنتساب : Feb 2008
السلام عليكم
هناك طريقة اخرى افضل بكثير و هي عن طريق استخدام الـ frame تضع المكونات في الفرام ثم تقوم بدمجها في الـ tab
http://www.delphi4arab.net/forum/showpos...ostcount=2
و لرب نازلة يضيق لها الفتى ذرعا و عند الله منها المخرج
ضاقت فلما استحكمت حلقاتها فرجت و كنت اضنها لا تفرج
المشاركات : 2,293
المواضيع 157
:
: 81
الإنتساب : Dec 2008
وعليكم السلام ورحمة الله
استخدم TTabControl
اللهم احقن دماء المسلمين، لا تنسوهم بالدعاء...