Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 12 total
Thread Free a modal form.
Wed, Oct 28 2015 5:41 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

I create my modal forms on demand using, for example, frmAddUser:=TfrmAddUser.Create(nil); and everything works fine.

However, I can't seem to call frmAddUser.Free; without generating an error ($t.tinterfacecontroller_felement is null). This sort of implies to me that it's been destroyed already, but can someone please confirm this as I've done nothing to explicitly do this other than set the form's mrResult.

Thanks.
Wed, Oct 28 2015 6:04 AMPermanent Link

Matthew Jones

squiffy wrote:

> TfrmAddUser.Create(nil)

I usually create them with the Application as the owner. Does that fix
it? If not, then it may be I just don't ever free my forms so it
doesn't matter.

Also, make sure you are referencing the same variable.

--

Matthew Jones
Wed, Oct 28 2015 6:18 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

No, that doesn't make any difference.

I tried calling a method on the form reference and it returned a valid value, so the form is definitely still alive and consuming memory.

Here's the code in full (well, extracted from a bigger unit)  :

// This is the Add New User button click event.
procedure TfrmClientDetail2.icoButEditLoginClick(Sender: TObject);
begin
  frmAddUser:=TfrmAddUser.Create(nil);  // Makes no difference if I use Application here.
  frmAddUser.OnClose:=addUserClosed;
  frmAddUser.setID(itemID);
  frmAddUser.setClientID(clientID);
  frmAddUser.ShowModal;
end;

// This is the onClose method referred to above.
procedure TfrmClientDetail2.addUserClosed(Sender:TObject);
begin
  if frmAddUser.ModalResult=mrOk then fetchClientData;
  log('Client id=' + IntToStr(frmAddUser.getClientID)); // This returns a valid value.
  //frmAddUser.Free;  // This causes the error.
end;

Interestingly, that log displays 4 times for a single show/close cycle in the debugger.
Wed, Oct 28 2015 7:13 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

I seem to be doing what is suggested here, too :

http://www.elevatesoft.com/manual?action=viewtopic&id=ewb2&topic=Creating_Showing_Forms

It says do this :

uses ProgFrm;

procedure TMainForm.ProgressFormClose(Sender: TObject);
begin
  ProgressForm.Free;
end;

procedure TMainForm.LaunchButtonClick(Sender: TObject);
begin
  ProgressForm:=TProgressForm.Create(nil);
  ProgressForm.OnClose:=ProgressFormClose;
  ProgressForm.ShowModal;
end;

What on earth could I be doing wrong?
Wed, Oct 28 2015 7:55 AMPermanent Link

Matthew Jones

squiffy wrote:

> What on earth could I be doing wrong?

I suspect that the callback for OnClose is then doing something with
the form, and that of course just got killed off. Is it the .Free it
fails at, or when it returns? I think following it in the Chrome
debugger may help a lot.

--

Matthew Jones
Wed, Oct 28 2015 8:17 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

Ok, fails in line 21438 which is this :

webctrls_tcontrol.$p.hide = function()
{
  var $t = this;   <---- chrome breakpoint set here.
  $t.tinterfacecontroller_felement.hide();     <--------------line 21438 : fails
};

It enters this code and triggers the breakpoint 3 times, first time :

$t = unitadduser2_tfrmadduser {tcomponent_fowner: webforms_tapplication, tcomponent_fname: "frmAddUser", tcomponent_fdata: null, tcomponent_ftag: 0, tcomponent_finitializing: false…}
21438
  $t.tinterfacecontroller_felement.hide();
21439
};
21440
&#8203;
21441
webctrls_tcontrol.$p.definelayout = function()
21442
{
21443
  var $t = this;
21444
  $t.tinterfacecontroller_felement.definelayout();
21445
};
21446
&#8203;
21447
webctrls_tcontrol.$p.canfocus = function()
21448
{
21449
  var $t = this;
21450
  return $t.tcontrol_getisvisible() && $t.tcontrol_getenabled();
21451
};
21452
&#8203;
21453
webctrls_tcontrol.$p.setfocus = function()
21454
{


second time :
$t = webforms_tmodaloverlay {tcomponent_fowner: webforms_tsurface, tcomponent_fname: "", tcomponent_fdata: null, tcomponent_ftag: 0, tcomponent_finitializing: false…}
21438
  $t.tinterfacecontroller_felement.hide();
21439
};
21440
&#8203;
21441
webctrls_tcontrol.$p.definelayout = function()
21442
{
21443
  var $t = this;
21444
  $t.tinterfacecontroller_felement.definelayout();
21445
};
21446
&#8203;
21447
webctrls_tcontrol.$p.canfocus = function()
21448
{
21449
  var $t = this;
21450
  return $t.tcontrol_getisvisible() && $t.tcontrol_getenabled();
21451
};
21452
&#8203;
21453
webctrls_tcontrol.$p.setfocus = function()
21454
{
21455
  var $t = this;


Third time (and error is triggered) : :

$t = unitadduser2_tfrmadduser {tcomponent_fowner: null, tcomponent_fname: "", tcomponent_fdata: null, tcomponent_ftag: 0, tcomponent_finitializing: false…}
21438
  $t.tinterfacecontroller_felement.hide();
21439
};
21440
&#8203;
21441
webctrls_tcontrol.$p.definelayout = function()
21442
{
21443
  var $t = this;
21444
  $t.tinterfacecontroller_felement.definelayout();
21445
};
21446
&#8203;
21447
webctrls_tcontrol.$p.canfocus = function()
21448
{
21449
  var $t = this;
21450
  return $t.tcontrol_getisvisible() && $t.tcontrol_getenabled();
21451
};
21452
&#8203;
21453
webctrls_tcontrol.$p.setfocus = function()
21454
{
21455
  var $t = this;



No idea if this is any help.
Wed, Oct 28 2015 8:29 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

Ok, I cannot reproduce it in a simple project that just creates, launches and frees a modal form.

So it's definitely something I'm doing, by the looks of it.

But cover me in eggs and flour and baste me for 40 minutes if I can see what.
Wed, Oct 28 2015 8:33 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

Time to get the eggs & flour out ...

I had a rogue
   Self.Close;
on my "X" button on my form. So if I cancelled it that way it all blew up.

Removed that and all is well.

Think I need a trip to specsavers ...
Wed, Oct 28 2015 8:36 AMPermanent Link

Matthew Jones

squiffy wrote:

> Time to get the eggs & flour out ...

I would, but the local police have signs up in all the shops saying not
to sell them to kids due to halloween. I think I might pass as an
adult, but coding is like that so well done finding it.

--

Matthew Jones
Wed, Oct 28 2015 8:41 AMPermanent Link

Ronald

squiffy wrote:

Time to get the eggs & flour out ...

I had a rogue
   Self.Close;
on my "X" button on my form. So if I cancelled it that way it all blew up.

Removed that and all is well.

Think I need a trip to specsavers ...

Hi,

Do you use a TServerRequest in your detailform that has not finished yet? I mean that the Request expects the OnComplete event, but since you have freed the form it is not available any more and generates the errormessage.

Greetings,
Ronald
Page 1 of 2Next Page »
Jump to Page:  1 2
Image