Recent

Author Topic: Error while execution - Can someone help me with the debugger information  (Read 9085 times)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Error while execution - Can someone help me with the debugger information
« Reply #15 on: February 06, 2016, 11:07:27 am »
Thaddy is right about 'BringToFront', although I have not had problems with it.

I set the conditions in the Object Inspector. I always believed that closing a form like this destroyed it.

The attachment shows the OI settings for the button. The form is just a normal form in my case so that several forms are active at the same time.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Error while execution - Can someone help me with the debugger information
« Reply #16 on: February 06, 2016, 11:10:56 am »
that is half the solution. The other half is to set the frmPopup to nil when the form is destroyed.

How can i set frmPopup to nil when the form is destroyed?
select the mainform that calls the frmpopup, go to the object inspector change to the events tab and locate the ondestroy event. Double click it to create the event and in there write something along the lines of
Code: Delphi  [Select][+][-]
  1.   if Sender = frmPopup then frmPopup := nil;
Now go to the object inspector and make sure that the ondestroy event is empty (you do not need it on the main form) then change your code to
Code: Delphi  [Select][+][-]
  1.   if PopUpRandom <> nil then
  2.     frmPopup.Show
  3.   else begin
  4.     frmPopup := TPopUpRandom.Create(Application);
  5.     frmPopup.OnDestroy := @FormDestroy;
  6.     frmPopup.ShowModal;
  7.   end;
and you are ready. Keep in mind that the event will only be available from the main form if the frmPopup is used from other forms the above procedure has to be written for those forms too. Do not be smart about this and merge it inside the frmPopup that will constrain you in to a single variable and that might interfere with forms other than the intended one, then again it might save you a lot of typing if this form has a singleton logic.
« Last Edit: February 06, 2016, 11:15:21 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Error while execution - Can someone help me with the debugger information
« Reply #17 on: February 06, 2016, 11:22:52 am »
Thaddy is right about 'BringToFront', although I have not had problems with it.

I set the conditions in the Object Inspector. I always believed that closing a form like this destroyed it.
No the default behavior is determined from the type of form. If my memory serves me right all mdi child forms have a default behavior caMinimize not caFree and as always an onclose event can change that behavior to what ever the programmer needs it to be.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Error while execution - Can someone help me with the debugger information
« Reply #18 on: February 06, 2016, 11:46:20 am »
I just remembered making a wiki entry a while ago. see http://wiki.lazarus.freepascal.org/Testing,_if_form_exists

The missing part is:

Code: Pascal  [Select][+][-]
  1. procedure TMyForm.Formclose(Sender: Tobject; var Closeaction: Tcloseaction);
  2. begin
  3.   CloseAction := caFree;
  4.   MyForm := nil;
  5. End;

However, I do not have this in my code, and I do not get memory leaks.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Error while execution - Can someone help me with the debugger information
« Reply #19 on: February 06, 2016, 12:05:19 pm »
I just remembered making a wiki entry a while ago. see http://wiki.lazarus.freepascal.org/Testing,_if_form_exists

The missing part is:

Code: Pascal  [Select][+][-]
  1. procedure TMyForm.Formclose(Sender: Tobject; var Closeaction: Tcloseaction);
  2. begin
  3.   CloseAction := caFree;
  4.   MyForm := nil;
  5. End;

However, I do not have this in my code, and I do not get memory leaks.
All autocreated forms are created with the Application as owner. That means that when application is destroyed it auto destroys all owned forms as well. As a consequence the trace unit will never show a memory leak. Your code shows that you also create the popup form with the application as the owner. Just to make things a bit clear when I said "do not be smart about it" on my last message that is the kind of code I mend. Personally I do not use the global variables at all and in the finished product they are all deleted before delivery to the client to avoid that kind of situations.
« Last Edit: February 06, 2016, 12:10:02 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Error while execution - Can someone help me with the debugger information
« Reply #20 on: February 06, 2016, 04:23:36 pm »
No the default behavior is determined from the type of form. If my memory serves me right all mdi child forms have a default behavior caMinimize not caFree and as always an onclose event can change that behavior to what ever the programmer needs it to be.

Huhmmmm... TS wanted behavior similar to a modal form, but with behavior like a normal form.
In that case, bring to front. It is not ideal, but at least the form shows and stays there for a little ;)

So if you can't live with a modal  form (which is still not properly fixed for all platforms in Lazarus! and I am not going to fix basics) use BringToFront.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Error while execution - Can someone help me with the debugger information
« Reply #21 on: February 06, 2016, 04:50:12 pm »
No the default behavior is determined from the type of form. If my memory serves me right all mdi child forms have a default behavior caMinimize not caFree and as always an onclose event can change that behavior to what ever the programmer needs it to be.

Huhmmmm... TS wanted behavior similar to a modal form, but with behavior like a normal form.
That is not what he asked for though. He asked why although in surface he took all the measures to avoid SIGSEGV errors he still managed to get one. At least this is the one I answered.
In that case, bring to front. It is not ideal, but at least the form shows and stays there for a little ;)

So if you can't live with a modal  form (which is still not properly fixed for all platforms in Lazarus! and I am not going to fix basics) use BringToFront.
Well there are different solutions to this problem if this is the problem he is facing. You can set the form to fsStayontop you can call bringtofront and because it might not work the first time around sendtoback and brigntofront again or you can use the popupParent to make sure that it will always stay on top of the calling form. If he has that problem. In any case since he did not post any problems I'm guessing we were successful pin pointing the problem he had and probably some he will get.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Error while execution - Can someone help me with the debugger information
« Reply #22 on: February 06, 2016, 06:00:11 pm »
@Taazz
For know I consider fsStayontop as "wherever I decide I want you to stay.." op.cit Platform you choose, NOT you, but the platform.

That's why I still am not fully comfortable with Lazarus, although I try to be (even polte, sometimes ;) ....

[edit]
Just checked some code in the lcl. Scared the shit out of me...
 and uhmmm, what does stay on top do: major sins all over the place. That's not proper in any case.
« Last Edit: February 06, 2016, 06:02:59 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Error while execution - Can someone help me with the debugger information
« Reply #23 on: February 06, 2016, 09:56:14 pm »
@Taazz
For know I consider fsStayontop as "wherever I decide I want you to stay.." op.cit Platform you choose, NOT you, but the platform.

That's why I still am not fully comfortable with Lazarus, although I try to be (even polte, sometimes ;) ....

[edit]
Just checked some code in the lcl. Scared the shit out of me...
 and uhmmm, what does stay on top do: major sins all over the place. That's not proper in any case.
I aggree. I tried long and hard to find a legitimate use of fsStayontop for an every day application and the only thing I come up with was on eye droper tool that selects a color from your desktop you create a fsStayontop form to show a dummy image of the desktop to let the user select a color after all those years of programming I come up with one legitimate use for it. Even the popupMode/PopupParent I only use under 2 or 3 conditions which they are less aggressive than the fsstayontop. Keep in mind that fsStayontop on lazarus does not have the same usage as the one in delphi. It supposed to stay on top of all the forms of your application only and fsSystemStayontop is suppose to stay on top of everything.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018