Delphi Can
Tabsheet içinde Form Create, Close olayları - Baskı Önizleme

+- Delphi Can (https://www.delphican.com)
+-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3)
+--- Forum: Genel Programlama (https://www.delphican.com/forumdisplay.php?fid=6)
+--- Konu Başlığı: Tabsheet içinde Form Create, Close olayları (/showthread.php?tid=7400)



Tabsheet içinde Form Create, Close olayları - YILDIRIMBEY - 24-08-2023

Merhaba Arkadaşlar,

aşağıdaki kod bloğu ile bir formu özelleştirilmiş (kapatma düğmesi olan) PageControlCloseButton objesi içinde create ediyorum.

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;

aşağıdaki kod blogu ile de bu sayfayı ve içindeki formu kapatmaya çalışıyorum, 
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;


ama ne yaparsam yapayım sanırım formu free ve nil yapamadığımdan kapatılan form tekrar açılmaya çalışınca access violation hatası veriyor. hatayı nerede yapıyorum, önerilerinizi alabilir miyim