* * *

Author Topic: Execution (solved)  (Read 1467 times)

Degibbo

  • New member
  • *
  • Posts: 23
Execution (solved)
« on: August 03, 2017, 03:48:23 am »
G'day all,
Well with a lot of help from the resident guru's my ex Delphi program now compiles OK,
so thanks for all the assistance.

When I try and run the program I get the infamous "Execution Stopped" box after
about three seconds, and nothing showing.  I tried inserting break-points to determine
where it is getting hung-up, but none are ever reached.

What is the exact execution order for procedures in the program, what gets called first?
I suspect that it is falling over before it even gets to the main program, but how to debug?
"Execution Stopped" might be accurate, but not very helpful!

Cheers & thanks yet again,
DG
« Last Edit: August 09, 2017, 05:29:59 am by Degibbo »

RAW

  • Hero Member
  • *****
  • Posts: 562
Re: Execution
« Reply #1 on: August 03, 2017, 03:53:42 am »
Do you mean this ???

Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.0RC5 FPC 3.0.4

Degibbo

  • New member
  • *
  • Posts: 23
Re: Execution
« Reply #2 on: August 03, 2017, 04:46:32 am »
G'day Raw,
Yep, that looks like it.
A break-point set at the top of the Create procedure is never executed.
So, is there a way to investigate what happens in the Initialization, or
trace where the execution is stopped  and why?

Thanks,
DG

RAW

  • Hero Member
  • *****
  • Posts: 562
Re: Execution
« Reply #3 on: August 03, 2017, 05:09:41 am »
Is there any code inside Initialization and at the beginning of the LPR ?

Code: Pascal  [Select]
  1. UNIT Unit1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, SysUtils, Forms, Controls;
  7.  
  8.  TYPE
  9.   TForm1 = Class(TForm)
  10.  
  11.   End;
  12.  
  13.  VAR
  14.   Form1: TForm1;
  15.  
  16. Implementation
  17.  {$R *.LFM}
  18.  
  19.  
  20. INITIALIZATION
  21.   ??????????????
  22.  
  23. FINALIZATION
  24.  
  25. END.

Code: Pascal  [Select]
  1. PROGRAM Project1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4.  USES
  5.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  6.    cThreads,
  7.   {$ENDIF}{$ENDIF}
  8.    Interfaces,
  9.    Forms,
  10.    Unit1;
  11.  
  12.   {$R *.RES}
  13.  
  14. BEGIN
  15.  ??????????
  16.  
  17.  RequireDerivedFormResource:= True;
  18.   Application.Initialize;
  19.   Application.CreateForm(TForm1, Form1);
  20.   Application.Run;
  21. END.
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.0RC5 FPC 3.0.4

RAW

  • Hero Member
  • *****
  • Posts: 562
Re: Execution
« Reply #4 on: August 03, 2017, 05:16:23 am »
Can you reproduce the ERROR with a little test program that uses the same starting routines ???

EDIT: do you see INTERFACES inside the LPR... ?
« Last Edit: August 03, 2017, 05:36:53 am by RAW »
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.0RC5 FPC 3.0.4

Degibbo

  • New member
  • *
  • Posts: 23
Re: Execution
« Reply #5 on: August 04, 2017, 01:18:21 am »
G'day Raw,
Interestingly the main program does not appear to have a
defined "INITIALIZATION" or "FINALIZATION" section!

Maybe that is the problem??

Also the LPR has no "INTERFACES" section, just a users clause and
begin
  Application.Initialize;
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
  MainForm.Free;
end.

I will try break-points in the LPR to see where it gets to.

I will also dummy up something and try your suggestion.
Cheers & thanks,
DG

RAW

  • Hero Member
  • *****
  • Posts: 562
Re: Execution
« Reply #6 on: August 04, 2017, 01:30:30 am »
Quote
Interestingly the main program does not appear to have a
defined "INITIALIZATION" or "FINALIZATION" section!
This is optional you don't need it, but you can use it if you want...  :)

LPR:
Code: Pascal  [Select]
  1.  MainForm.Free;
This looks crazy .... weird... something like that...  :D

You need probably INTERFACES and you don't need MAINFORM.FREE...  :)

EDIT: Normally you should get a warning if you don't have INTERFACES inside the main program.
« Last Edit: August 04, 2017, 01:46:34 am by RAW »
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.0RC5 FPC 3.0.4

Degibbo

  • New member
  • *
  • Posts: 23
Re: Execution
« Reply #7 on: August 04, 2017, 03:50:20 am »
G'day,
OK, I cut down the main program to just a button and an editbox.
It ran OK, no execution stop.

Interestingly if I comment out the calls in the LPR file and with the original
main file I still get the error, so I guess that is the fall-back position for
anything that doesn't work as expected.  So I still can't confirm that the
problem is with the LPR or the main file

The next step I guess is to comment out everything step by step and
see if I can get it to run.

Cheers,
DG

RAW

  • Hero Member
  • *****
  • Posts: 562
Re: Execution
« Reply #8 on: August 04, 2017, 06:40:17 am »
Hi Degibbo,
if the debugger couldn't help then it's probably the best idea to comment out everything that is inside OnCreate, OnResize, OnShow, OnActivate, OnPaint and everything that is at the beginning of the LPR-file. That way you'll sooner or later find the problem...
Don't give up... it's usually something very simple... ...the wood for the trees...  :)

btw: Did you check the project options: compiler options: config and target: is there everything right? Right widgetset, platform and so on... ?

Another way would be to use a very simple logging... (if there is a real exception...)
Code: Pascal  [Select]
  1. Procedure Log(strInfo: String);
  2.   Var
  3.    slSave : TStringlist;
  4.    strFile: String;
  5.    strLog : String;
  6.    wnd    : TForm;
  7.    lab    : TLabel;
  8.  Begin
  9.   Try
  10.    Try
  11.     strFile:= Application.Location+'Error.log';
  12.  
  13.     slSave:= TStringlist.Create;
  14.      Try
  15.       If FileExists(strFile)
  16.       Then
  17.        Begin
  18.         Try
  19.          slSave.LoadFromFile(strFile);
  20.         Except
  21.         End;
  22.        End;
  23.  
  24.       slSave.Text:=
  25.  
  26.        DateTimeToStr(Now) +sLineBreak+
  27.        strInfo            +sLineBreak+
  28.        ''                 +sLineBreak+
  29.        slSave.Text;
  30.  
  31.       strLog:= slSave.Text;
  32.       slSave.SaveToFile(strFile);
  33.      Finally
  34.       slSave.Free;
  35.      End;
  36.    Except
  37.    End;
  38.  
  39.    If strLog = '' Then strLog:= strInfo;
  40.  
  41.    wnd:= TForm.Create(Nil);
  42.     Try
  43.      wnd.BorderStyle          := bsSizeable;
  44.      wnd.BorderIcons          := [biSystemMenu, biMaximize];
  45.      wnd.Caption              := Application.Title+'.log';
  46.      wnd.Constraints.MinHeight:= 200;
  47.      wnd.Constraints.MinWidth := 300;
  48.      wnd.Height               := 300;
  49.      wnd.Width                := 400;
  50.      wnd.AutoScroll           := True;
  51.      wnd.HorzScrollBar.Visible:= False;
  52.      wnd.Position             := poDesktopCenter;
  53.  
  54.      lab             := TLabel.Create(wnd);
  55.      lab.Align       := alClient;
  56.      lab.Caption     := strLog;
  57.      lab.Font.Size   := 15;
  58.      lab.Font.Quality:= fqAntialiased;
  59.      lab.Font.Style  := [fsBold];
  60.      lab.Transparent := True;
  61.      lab.WordWrap    := True;
  62.      lab.AutoSize    := False;
  63.      lab.Parent      := wnd;
  64.  
  65.      wnd.ShowModal;
  66.     Finally
  67.      wnd.Release;
  68.      wnd:= Nil;
  69.     End;
  70.   Except
  71.   End;
  72.  End;
  73.  
  74.  
  75. Procedure TForm1.FormCreate(Sender: TObject);
  76.  Begin
  77.   Try
  78.    // ....
  79.  
  80.   Except
  81.    On E: Exception
  82.    Do Log('FormCreate'+sLineBreak+E.ClassName+sLineBreak+E.Message);
  83.   End;
  84.  End;
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.0RC5 FPC 3.0.4

Degibbo

  • New member
  • *
  • Posts: 23
Re: Execution
« Reply #9 on: August 04, 2017, 06:46:14 am »
G'day,
Moving on:  As there doesn't seem to be a way to comment-out code that contains comments,
it is a slow job stripping down my main file (about 1000 lines of code).

As expected, I get all sorts of errors, such as an EReadError at 100049635.  Is there an easy
way, from this information, to get to the actual source code line that caused the error?

Cheers & thanks,
DG

RAW

  • Hero Member
  • *****
  • Posts: 562
Re: Execution
« Reply #10 on: August 04, 2017, 07:01:08 am »
Do you read from a stream ??? (EReadError)
Use an easy exception handling then you'll know where the problem is...  :)
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.0RC5 FPC 3.0.4

Degibbo

  • New member
  • *
  • Posts: 23
Re: Execution
« Reply #11 on: August 09, 2017, 05:29:33 am »
G'day,
Well the execution failure has bee "fixed" but not explained.
It turned out that any call that was likely to fail caused the error,
even if it was not actually called!  The calls were to hardware drivers
where the hardware was not fitted.

Temporary comment-outing of the lines solved the problem.
Thanks for all the help, ideas & encouragement.

Cheers,
DG

molly

  • Hero Member
  • *****
  • Posts: 1960
Re: Execution
« Reply #12 on: August 10, 2017, 12:31:30 am »
Quote
Interestingly the main program does not appear to have a
defined "INITIALIZATION" or "FINALIZATION" section!
This is optional you don't need it, but you can use it if you want...  :)

@RAW: sorry in advance for the nitpick but wanted to make sure there is no misunderstanding when someone reads through.

It is optional to have a initialization or finalization section inside your main program file ?

Either we have a different understanding of what is meant by main program or i would very much like to see how that is able to compile.

For me "main program" means that particular file that starts with the reserved word "program".
« Last Edit: August 10, 2017, 12:39:02 am by molly »

Degibbo

  • New member
  • *
  • Posts: 23
Re: Execution (solved)
« Reply #13 on: August 10, 2017, 01:47:45 am »
G'day Raw,
Thanks for the nitpic.  You are right of course.  What I refer to as the "main program" is
the unit that is called first, and everything else is called from it (my "master").

I guess that stems from my structural ignorance, and so of course the "main" program is
actually the LPR file.

Sorry about the confusion.
Cheers & thanks,
DG

RAW

  • Hero Member
  • *****
  • Posts: 562
Re: Execution (solved)
« Reply #14 on: August 10, 2017, 02:13:26 am »
Hey molly  :P ...
btw: I attached in "Reply #3" a unit ...

Yes he wrote main program... I can see that now...  :)
Maybe I overlooked that a little bit... just a little bit... only to give you the chance to nitpick...

(What do you mean you cannot compile INITIALIZATION inside your LPR... It's probably your computer... something is wrong with it... obviously...)



@Degibbo
Quote
...and everything else is called from it (my "master").

Oh thanks, but unfortunately I'm not a master, not even a "master"... and it's molly's nitpick... so molly shame on you...  :D
Ok, Ok, it's more a matter of exactness not really a nitpick... whatever... (heretic..  :D)

Quote
Sorry about the confusion.
No problem at all, I'm not confused...
Nice to hear that you've got it running...  :)
« Last Edit: August 10, 2017, 02:19:33 am by RAW »
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.0RC5 FPC 3.0.4

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus