Çalışma zamanında PageControl Tabsheet ve form oluşturuyorum.
oluşturulan sheeti kapatıp aynı formu yeniden oluşturmak istediğimde Invalid Pointer hatası alıyorum.
Sorunu aşamadım.
Aynı sayfayı oluşturuken aşağıdaki satırda hataya düşüyor.
TForm(Reference).Parent := tsMain;
Kod: Tümünü seç
private
procedure pcMainOnCanClose(Sender: TObject; var ACanClose: Boolean);
public
pcMain: TcxPageControl;
tsMain: TcxTabSheet;
procedure AFormCreate(AFormClass: TComponentClass; var Reference); overload;
end;
procedure TfmMain.AFormCreate(AFormClass: TComponentClass; var Reference);
var
I: Integer;
Instance, pcComp, tsComp: TComponent;
begin
pcComp := FindComponent('pc');
tsComp := FindComponent('ts' + Copy(AFormClass.ClassName, 4, 20));
if not Assigned(pcComp) then
begin
pcMain := TcxPageControl.Create(Self);
with pcMain do
begin
Name := 'pc';
Parent := pnlClientMain;
Align := alClient;
AlignWithMargins := True;
Margins.Top := 2;
Margins.Left := 2;
Margins.Right := 2;
Margins.Bottom := 2;
Focusable := False;
LookAndFeel.NativeStyle := False;
LookAndFeel.SkinName := 'Office2013White';
LookAndFeel.AssignedValues := [lfvNativeStyle, lfvSkinName];
Properties.Style := 11;
Properties.TabWidth := 150;
Properties.TabHeight := 20;
Properties.Images := ImgSmall;
Properties.ShowFrame := True;
Properties.OwnerDraw := True;
Properties.ShowButtonHints := True;
Properties.AllowTabDragDrop := True;
Properties.CloseButtonMode := cbmActiveAndHoverTabs;
Properties.Options :=
[pcoAlwaysShowGoDialogButton,
pcoCloseButton,
pcoGoDialog,
pcoGradient,
pcoGradientClientArea,
pcoRedrawOnResize];
Options :=
[pcoAlwaysShowGoDialogButton,
pcoCloseButton,
pcoGoDialog,
pcoGradient,
pcoGradientClientArea,
pcoRedrawOnResize];
OnCanClose := pcMainOnCanClose;
end;
end;
if not Assigned(tsComp) then
begin
tsMain := TcxTabSheet.Create(Self);
with tsMain do
begin
Name := 'ts' + Copy(AFormClass.ClassName, 4, 20);
Caption := TForm(Reference).Caption;
PageControl := pcMain;
Highlighted := True;
ImageIndex := 3;
PageControl.ActivePageIndex := TabIndex;
end;
if Pointer(Reference) = nil then
begin
Instance := TComponent(AFormClass.NewInstance);
TComponent(Reference) := Instance;
try
Instance.Create(Self);
except
TComponent(Reference) := nil;
raise;
end;
end;
TForm(Reference).Parent := tsMain; // oluşturulan tabsheet kapatalıp yeniden oluşturulduğunda invalid pointer hatası alınıyor.
TForm(Reference).BorderStyle := bsNone;
TForm(Reference).Align := alClient;
TForm(Reference).Show;
TForm(Reference).SetFocus;
end else
begin
for I := 0 to pcMain.PageCount - 1 do
begin
if pcMain.Pages[I].Name = tsComp.Name then
begin
pcMain.ActivePageIndex := I;
end;
end;
end;
end;
procedure TfmMain.btnMaterialsClick(Sender: TObject);
begin
AFormCreate(TfmMaterials, fmMaterials);
end;
procedure TfmMain.pcMainOnCanClose(Sender: TObject; var ACanClose: Boolean);
begin
if pcMain.PageCount = 1 then
begin
ACanClose := False;
pcMain.Free;
end;
end;