Jessica Loriena
2004-09-16 16:52:24 UTC
Hi.. I hope someone will help be with a strange problem I'm having:
I create tab sheets dynamically and attach a form to it at runtime
like this:
***************************************************************
MainForm:
***************************************************************
public
{ Public declarations }
MyTabSheet: TcxTabSheet; (a DevExpress Tab Sheet Component)
procedure TMainForm.actionNewTabSheet(Sender: TObject);
begin
// MyTabSheet always set to nil after freed see below)
if not Assigned(MyTabSheet) then
begin
MyTabSheet := TcxTabSheet.Create(Application);
MyTabSheet.PageControl := MyPageControl;
MyTabSheet.Caption := 'Sheet One';
MyTabSheet.Show;
MyForm := MyForm.Create(Application);
MyForm.Parent := MyTabSheet;
MyForm.Show;
end
else
MyPageControl.ActivePageIndex := MyTabSheet.PageIndex;
end;
---------------------------------------------------------------
As you can see, if MyTabSheet is already Assigned (created), I just
make it the active sheet instead of creating a new one.
In MyForm (contained in MyTabSheet), I have an OnClose event like
this:
***************************************************************
MyForm
***************************************************************
procedure TMyForm.FormClose(Sender: TObject; var Action:
TCloseAction);
begin
Release;
MainForm.MyTabSheet.Free;
MainForm.MyTabSheet := nil;
end;
---------------------------------------------------------------
The strange thing here is that this code works, but SOMETIMES (NOT
rarely), an Access Violation error comes up after closing the tabbed
form (which frees the tab sheet). After the error message, the sheet
closes normally and execution continues as normal.
What's wrong with the code?? I searched for many hours and still can't
find where a logical error might be. The error message is really
annoying.
I'd very much appreciate your help.
Thanks!
I create tab sheets dynamically and attach a form to it at runtime
like this:
***************************************************************
MainForm:
***************************************************************
public
{ Public declarations }
MyTabSheet: TcxTabSheet; (a DevExpress Tab Sheet Component)
procedure TMainForm.actionNewTabSheet(Sender: TObject);
begin
// MyTabSheet always set to nil after freed see below)
if not Assigned(MyTabSheet) then
begin
MyTabSheet := TcxTabSheet.Create(Application);
MyTabSheet.PageControl := MyPageControl;
MyTabSheet.Caption := 'Sheet One';
MyTabSheet.Show;
MyForm := MyForm.Create(Application);
MyForm.Parent := MyTabSheet;
MyForm.Show;
end
else
MyPageControl.ActivePageIndex := MyTabSheet.PageIndex;
end;
---------------------------------------------------------------
As you can see, if MyTabSheet is already Assigned (created), I just
make it the active sheet instead of creating a new one.
In MyForm (contained in MyTabSheet), I have an OnClose event like
this:
***************************************************************
MyForm
***************************************************************
procedure TMyForm.FormClose(Sender: TObject; var Action:
TCloseAction);
begin
Release;
MainForm.MyTabSheet.Free;
MainForm.MyTabSheet := nil;
end;
---------------------------------------------------------------
The strange thing here is that this code works, but SOMETIMES (NOT
rarely), an Access Violation error comes up after closing the tabbed
form (which frees the tab sheet). After the error message, the sheet
closes normally and execution continues as normal.
What's wrong with the code?? I searched for many hours and still can't
find where a logical error might be. The error message is really
annoying.
I'd very much appreciate your help.
Thanks!