Re:GP error - second request
Quote
Derek Rogers wrote:
> Can anybody suggest a solution for this bug? I asked before, but there
> were no respondents.
> The application is an MDI application in Delphi 1, with an MDI parent
> (Form1) and multiple instances of a single type of MDI child (Form2).
> Clicking on Form1 creates a new instance of Form2; closing a Form2
> deletes that instance of it.
> The bug is that if you close- - and therefore remove -- the newest
> instance of Form2, then resize a remaining Form2, the application
> returns a GP error saying that Form2 has no ClientWidth. (In the real
> application, I use ClientWidth to make the resized form look neat and
> tidy.)
> How can the user be allowed to close and remove Form2's without this
> happening?
> Code and executable is at http://www.derek.co.uk/bughelp
> Thanks.
If you are creating multiple instances of TForm2 you cannot
assign them all to the same variable (Form2).
unit P1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormClick(Sender: TObject);
end;
var
Form1: TForm1;
implementation uses P2;
{$R *.DFM}
procedure TForm1.FormClick(Sender: TObject);
begin
// P2.Form2 := P2.TForm2.Create(Application);
TForm2.Create( Self );
end;
end.
*******************************************
unit P2;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs;
type
TForm2 = class(TForm)
procedure FormResize(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
end;
// var
// Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormResize(Sender: TObject);
var
TempNo: word;
begin
// TempNo := Form2.ClientWidth;
TempNo := ClientWidth;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
end.