Kod:
procedure TsysfrmAna.YeniSayfa(ChildClass: TComponentClass; var sayfaadi; multi: integer = 0);
var
tabSheet: TCloseTabSheet;
AComponent: TComponent;
begin
try
Screen.Cursor := crHourGlass;
if not assigned(TObject(sayfaadi) as TForm) then
begin
tabSheet := TCloseTabSheet.Create(PageControlCloseButton);
tabSheet.PageControl := PageControlCloseButton;
tabsheet.OnClose := CloseTabeProc;
//IntToStr(PageControlCloseButton.PageCount);
//if aIndex > -1 then
//tabSheet.PageIndex := aIndex; //Set the index of the new TabSheet
//(TObject(sayfaadi) as TForm).BringToFront;
Application.CreateForm(ChildClass, sayfaadi);
(TObject(sayfaadi) as TForm).Parent := tabsheet;
(TObject(sayfaadi) as TForm).borderstyle := bsNone;
(TObject(sayfaadi) as TForm).windowstate := wsMaximized;
//tabSheet.Caption := (TObject(sayfaadi) as TForm).Caption;
tabsheet.Name := 'sayfa_' + (TObject(sayfaadi) as TForm).name;
(TObject(sayfaadi) as TForm).Show;
PageControlCloseButton.ActivePageIndex := tabsheet.PageIndex;
end
else
begin
{AComponent := FindComponent('sayfa_' + (TObject(sayfaadi) as TForm).name);
showmessage('b');
showmessage('xxx' + FindComponent('sayfa_' + (TObject(sayfaadi) as TForm).name).name);
if Assigned(TCloseTabSheet(AComponent)) then
//showmessage('c');
//if TObject(AComponent) is TCloseTabSheet then
// showmessage('d'); }
AComponent := FindComponent((TObject(sayfaadi) as TForm).name);
//if Assigned(AComponent) then
// showmessage('c');
//if TObject(AComponent) is TForm then
//showmessage('d');
PageControlCloseButton.ActivePageIndex := TCloseTabSheet((TObject(sayfaadi) as TForm).Parent).PageIndex; //get the index of the 'TabSheet1'
end;
Screen.Cursor := crDefault;
except
on e: exception do
showmessage('Exception -> CreateChildForm ' + e.message);
end;
end;
Kod:
procedure TCloseTabSheet.DoClose;
var
i: integer;
begin
if Assigned(FOnClose) then
FOnClose(Self);
for i := 0 to Application.ComponentCount - 1 do
if (pos('frm', Lowercase(Application.Components[i].Name)) > 0) and
(Application.Components[i] <> Application.MainForm) and
(TForm(Application.Components[i]).Parent = self) then
begin
//(TObject(Application.Components[i]) as TForm).Close;
//freeandnil(i);
end;
//freeandnil(self);
end;