Recent

Author Topic: Program compiles, links, ... no window seen  (Read 1010 times)

PaulRowntree

  • Full Member
  • ***
  • Posts: 132
    • Paul Rowntree
Program compiles, links, ... no window seen
« on: September 30, 2019, 07:29:44 am »
I have been working on a complex code for about a month ... it has worked well, and never throws errors etc.  Tonight I decided to remove the debugging code, and now it compiles without errors, links without errors, but the execution doesn't seem to even get into the OnCreate event handler (where I have several ShowMessage() calls to track progress) before it pops out without a message.  The taskbar flashes, but no new icon appears, the red square on the IDE toolbar flashes on for a few seconds, then disappears.  The executable behaves the same way.  Turning the debugging code back on changes nothing.  Have restarted computer ... no change.  Previous executable versions still run fine.

I am running Win10, Laz 1.8.4.
I would be extremely grateful if anyone could offer any guidance here ... it must be something simple, right?Cheers!pr
Paul Rowntree
- coding for instrument control, data acquisition & analysis, CNC systems

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: Program compiles, links, ... no window seen
« Reply #1 on: September 30, 2019, 08:26:16 am »
Did you fix all warnings the compiler throws in your own code? Ground zero.
Did you obtain a stacktrace? (my first thing to look, because I always fix all warnings in my own code... almost always  :()
And did you use F7/F8/F9 and breakpoints?
See how far it runs trouble free and then add some watches on critical variables. Remove any breakpoints before that point that you know works, so it doesn't get cluttered.
Also compile with -glh, run. and see what that gives you. Or see screenshot for lazarus settings..
You can additionally enable valgrind - if you are familiar with it and your platform supports it.
Also if your application is multi-threaded, name your threads!! Really important for debugging them!!
Also, replace most of the showmessages with assertions and add assertions to the critical parts of your start up.

Complex code belongs in a version control system and the best are free...
Do you use a version control system like git or svn?
Then you can simply diff the code and examine the changes one by one.
Otherwise, try to remember what and where you made changes, revert them, compile again and when it finally works, use a version control system....
You may also want to apply some of https://wiki.freepascal.org/Defensive_programming_techniques (note to self: I have to complete that still)

The screenshot shows my own - extreme - debug settings for hard to find cases. On Linux I sometimes also enable valgrind. (But valgrind tools are not very user friendly in my opinion, steep learning curve)

And maybe, if you tend to use FreeAndNil, that hides many bugs rather than solve them, use this one instead:
Code: Pascal  [Select][+][-]
  1.   procedure FreeAndNil<T:class>(var obj:T);  // just  prefix with generic in mode objfpc.
  2.   var
  3.     temp: T;
  4.   begin
  5.     temp := obj;
  6.     obj := nil;
  7.     temp.free;
  8.   end;

That's because that version is type safe...It solves some of the issues related to FreeAndNil(var obj), which is untyped.....
« Last Edit: September 30, 2019, 09:24:34 am by Thaddy »
Specialize a type, not a var.

PaulRowntree

  • Full Member
  • ***
  • Posts: 132
    • Paul Rowntree
SOLVED : Program compiles, links, ... no window seen
« Reply #2 on: October 02, 2019, 03:42:17 am »
Thanks Thaddy!  All good advice; I am poor at removing warnings, but ...
The problem seems to have been a flakey USB drive used to store the code.  I did a Cobian backup, which against Murphy's Law was a FULL backup, and the USB drive died the next morning ... WinDoze claimed it needed formatting.  New USB key, grabbed the full backup, the code compiled without a murmur, and the code executes as expected...  Life is once again good, career back on track.
Cheers!
Paul Rowntree
- coding for instrument control, data acquisition & analysis, CNC systems

 

TinyPortal © 2005-2018