Board index » delphi » GP error - second request

GP error - second request

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.

*
* http://www.derek.co.uk : Resources for Language Learners
* de...@derek.co.uk : 0845-456-3951 : +44(0)141-334-8902
* Derek Rogers Professional Software
* 21 Hamilton Drive GLASGOW G12 8DN UK

 

Re:GP error - second request


Derek Rogers <langu...@derek.co.uk> wrote in
news:f6hufv82pinhnu5a9u1cv1mlej7cuka136@4ax.com:

Quote
> http://www.derek.co.uk/bughelp

var
  Form2: TForm2;
implementation
...

procedure TForm1.FormClick(Sender: TObject);
begin
    P2.Form2 := P2.TForm2.Create(Application);
end;

The problem is that there is only one instance of the Form2 variable.

The first click on Form1 creates an instance of TForm2 and assigns the
object to the Form2 variable. The second click on Form1 creates a second
instance of TForm2 and assigns it to the Form2 variable OVERWRITING the
previous value (the first instance of TForm2). If the second instance of
TForm2 is closed and freed, the Form2 variable is left "pointing to" the
store that had been used for the recently departed second instance of Form2,
hence the GPF.

HTH

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.

Other Threads