Lazarus

Free Pascal => Windows => Topic started by: WimVan on December 13, 2018, 08:23:04 am

Title: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 08:23:04 am
All,
I have a very strange behavour and I hope someone can help me.
Situation
2 different PC's.
  One with Windows10, Intel I7, 16 GB RAM, 64bit.  I'll name this PC
  The other one is also WIndows10, but i5, 16 GB RAM, 64 bit . A Laptop.  I'll name it laptop
On both I installed the same Lazarus
1.8.4,
SVN; 57972 
X86-64-win64-win32/win64

No extra packages are installed.
Next components are used:
-SQLconnect
-SQLtransaction
-SQLQuery
-Datasource
-DBgrid
-Buttom
Pagecontrol and tabsheets, labels, panels, edit ... and TImage

When I edit sources on the PC and compile them, the application opens and I can test it.
Outside Lazarus, the executable  also runs correct on the PC and on the Laptop
Development of the same application (with the same sources) on the laptop is successful and created exe's runs also on the PC as on the Laptop.
SO far so good.

BUT,  suddenly (I assume when adding a second form to the project) I have a very strange behavour.
1) development on the Laptop and on the PC can be done
But and now it becomes tricky
Any development on the PC is successful.  I can even test the application by compiling and running it in the IDE.
Leaving Lazarus, the created exe is running correct on the PC.
But, when trying to run that exe on the Laptop, the exe is loaded and directly the exe is left. I see a flashup of blank window and directly the exe closes.
2) Move all sources to the Laptop.  When I open Lazarus I can edit the project, sources.
But now, I can't run it.  Compiling is successful without any error-remark.  But, the application just flashes up and closes.  I can't run the exe while developing.
Leaving Lazarus and trying to run the created executable is NOT successful. the exe is loaded and directly the exe is left. I see a flashup of blank window and directly the exe closes.

Someone can help me in this for me severe problem.
In the past I developed several little apps that run on the PC as well on the laptop, even when edited, created on the Laptop.
I think there is a problem with the second form but I'm not sure and I tried to test it, writing new little apps, bt I can not really place when.  The only thing I know, once you can run it no more, you may delete the added form, remove all links to that forms, you can no more run it.  In Lazarus, neither outside Lazarus and NO error is reported.

What the most strange item is, is the fact that the exe that was produced on the LAPTOP and can't been run there, is usable on the PC.  Running the exe there is successful
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: CCRDude on December 13, 2018, 09:18:47 am
Sounds a lot like a DLL is missing or the wrong version on the laptop. Since you use a database, possibly one of those.

What I would do is use the debugger. Might be tedious, but step through the code line by line, and you'll find the culprit.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 01:56:56 pm
The Lazarus-deployement was and is identical on the Laptop and the PC,
The database is the same (works on an external HD) which is mounted with USB
the database-dll is the same on the Laptop ant the PC.

Next, I'll try the debugger.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: wp on December 13, 2018, 02:04:27 pm
Sounds a lot like a DLL is missing or the wrong version on the laptop.
Or an antivirus issue. Antivirus software has become the enemy of software development these days. Do both computers have the same antivirus? Deactivate the antivirus on the laptop and see if it fixes the issue. I had to remove my BitDefender because it used to delete fpc and related tools. I am using now Windows Defender, no problems so far with it (although putting the Lazarus program and project folders on the white list is a MUST here too).
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: Thaddy on December 13, 2018, 02:16:35 pm
I am using now Windows Defender, no problems so far with it (although putting the Lazarus program and project folders on the white list is a MUST here too).
Yes? I also use just Windows Defender (which is quite good, actually) I didn't white-list anything. May be an OPM issue? Because I have no issues at all.

I also suspect that a database dll is missing or of the wrong bitness. So what's the database?
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 02:25:51 pm
Laptop has another Anti-virus (Symantec).  PC has Avast.
But, I run the debugger ....
After a long time I got an error
External SIGILL
Looking further I got the concerned pas
LAZUTF8.PAS
Line 3451

It is a part a a function ...  When looking to it, I saw that even before the begin-statement another function is inserted

The inserted code starts at line 3395, line 3451 is the end; -statement at te bottom of the listed code
Code: Pascal  [Select][+][-]
  1. function ConvertUTF8ToUTF16(Dest: PWideChar; DestWideCharCount: SizeUInt;
  2.   Src: PChar; SrcCharCount: SizeUInt; Options: TConvertOptions;
  3.   out ActualWideCharCount: SizeUInt): TConvertResult;
  4. var
  5.   DestI, SrcI: SizeUInt;
  6.   B1, B2, B3, B4: Byte;
  7.   W: Word;
  8.   C: Cardinal;
  9.  
  10.   function UnfinishedCharError: Boolean;
  11.   begin
  12.     if toUnfinishedCharToSymbol in Options then
  13.     begin
  14.       Dest[DestI] := System.WideChar('?');
  15.       Inc(DestI);
  16.       Result := False;
  17.     end
  18.     else
  19.       if toUnfinishedCharError in Options then
  20.       begin
  21.         ConvertUTF8ToUTF16 := trUnfinishedChar;
  22.         Result := True;
  23.       end
  24.       else Result := False;
  25.   end;
  26.  
  27.   function InvalidCharError(Count: SizeUInt): Boolean; inline;
  28.   begin
  29.     if not (toInvalidCharError in Options) then
  30.     begin
  31.       if toInvalidCharToSymbol in Options then
  32.       begin
  33.         Dest[DestI] := System.WideChar('?');
  34.         Inc(DestI);
  35.       end;
  36.  
  37.       Dec(SrcI, Count);
  38.  
  39.       // skip trailing UTF-8 char bytes
  40.       while (Count > 0) do
  41.       begin
  42.         if (Byte(Src[SrcI]) and %11000000) <> %10000000 then Break;
  43.         Inc(SrcI);
  44.         Dec(Count);
  45.       end;
  46.  
  47.       Result := False;
  48.     end
  49.     else
  50.       if toInvalidCharError in Options then
  51.       begin
  52.         ConvertUTF8ToUTF16 := trUnfinishedChar;
  53.         Result := True;
  54.       end;
  55.   end;
  56.  
  57. begin
  58.   ActualWideCharCount := 0;
  59.              
  60.  

Can't stop antivirus because we do not have enough privilages ... So no test on that.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: marcov on December 13, 2018, 02:28:40 pm
See if you can add excludes to the antivirus, all dirs that are relevant to lazarus

That is not as watertight as disabling, but it sometimes makes things more bearable.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 02:33:57 pm
All, once more time.
1) Database is Mariadb and is installed and running on an external HD.
2) Used libmysql.dll for the database-access resides on the HD en is also copied into the application-map where the application is developed and is run.
3) Used libmysql.dll is also copied into the lazarus-development-folder
4) The error that I can run the application ... (It starts up and immediately closes) appears

I'll try to make a little schema with the conditions when this strange behavour appears.  I nowhere get an error.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 02:40:01 pm
@marcov
I'll see if I can do this, n-but, it seems very strange to me, that suddenly this things appears after.  I have several applications developped with lazarus that run on the PC and Laptop without any problem.
The problem appears (I think) after adding a second form.  As long I was in developmode, I could test and run the application.
Leaving the Lazarus and restarting I can edit it an run.  I even can run it out the Lazarus-development, so as a stand alone app.
BUT, restarting the laptop and then trying ... I got the strange behavour.  The stand-alone app starts and closes immediately.  Opening Lazarus and trying to run the application ...  No erros, compiled ok, but I got never focus to the app.  It opens and immediately closes ...

So I do not understand why the antivirus in some case renders a problem ...
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: CCRDude on December 13, 2018, 03:50:25 pm
The biggest ObjectPascal AV issue ever was Delphi using a fixed timestamp (always the same 1992 date) in PE headers. After one Delphi malware was identified by AVs, they took the timestamp as a "perfect heuristic value" and flagged all software ever compiled with Delphi as malware :D

On a broader scope, these poor heuristics is what affects software developers the most. Files that change over time are a typical sign for polymorph viruses trying to avoid detection, so the executables created and recreated by developers share one common thing with malware.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 04:40:02 pm
Updated situation.
When I use another laptop with AVAS on it (same avas as on the PC), the behavour is the same as the other laptop.  Application starts up and closed immediately.
Wen compiling on that laptop, the application does not open.  Only execution broken and returns to development.

Jezus, what a mess, what a mess ...  Time, a huge amount of time lost and still nothing I can deliver to my boss ...
I understand some problems, but he doesn't ...  Just a push-the-button-guy ...

This I can't explain to him.  I made the choice to Lazarus, Free Pascal ...  And yes, I know the Delphi-troubles too.  I once started with Delphi 1, where with Delphi 4 it was a catastrophe.  And any time all components must be revised

Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: Thaddy on December 13, 2018, 04:49:48 pm
Not a mess: missing dll. What database do you expect.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 06:21:30 pm
Nothing missing about Database.  Please read from the start.
libmysql.dll is used for all laptop, PC.  It is the same version.
Mariadb. 3.4.1

I have applications using the same database and they run on the both laptops and PC.  So, I'm sure that is correct.

Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: Josh on December 13, 2018, 06:30:27 pm
Hi

Can you compile for the win 32 i386 target, does this work? (note you will need the 32bit dll's).

Just a test to see if issue with the x64 exe.


Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: wp on December 13, 2018, 06:35:55 pm
Try to find out how far the exe is running on the laptop: Remove the checkmark of "Win32 gui application" on page "Config and target" of the project options, and add WriteLn(<unit name>, <procedure name>) at the beginning of important procedures through which the programm will be running. Then run the exe and watch on the console window which procedures are reached and which are not. For example put such a WriteLn before and after the statement which loads the DLL of the database: if you see only the statement "before", but not the one "after", you know that something is wrong with the DLL.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 08:12:28 pm
@Josh
I did the test.  Nothing is resolved.  While compiling a cmd-box opens and I see a quick run of messages ...  to quick to follow. cmd-box closes automatically and popup of application and closing immediately.  No error-message seen.

@wp
I'll try it, but whom procedures must I change by inserting the writeln ... ?
procedures of the application, or even procedures called in existent units ?
If the last one, how can obtain a list of all procedures whom are used ?

When I trace step by step while compiling I get out in LAZutf8.pas at line 3451, erro-message: External SIGILL
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: wp on December 13, 2018, 08:31:08 pm
Ah, I forgot that you can step through the code with the debugger. Then the WriteLn's can be avoided.

When the debugger stops with the error in LazUTF8 you should look at the stack-trace: View > Debug windows > Call stack. It shows the crashing line at the top, and, going down, the code lines which were called by the preceding line. Look at the source code at or before these lines and try to find if there is something strange. The error probably means that one of the PChar or PWideChar arguments of the Convert... function points to unassigned memory.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 09:43:27 pm
Remark: I did that step to step-debugging already.

I let de debugger compile till the formcreate (*************-mark) 

Code: Pascal  [Select][+][-]
  1. ********************** procedure TMASTERform.FormCreate(Sender: TObject);
  2. var
  3.   cFile, cappl : string;
  4.   ntmp : integer;
  5. begin
  6. ##############  cappl := ExtractFileName( Application.ExeName);
  7.   ntmp  := length(cappl)  ;
  8.   cappl := copy( cappl, 1, ntmp - 4);
  9.   cFile := ExtractFilePath( Application.ExeName) + cappl + '.def';
  10.  

The debugger stops at (second marker###################) and from there I step throw the code ...

Code: Pascal  [Select][+][-]
  1. program collectie_beheer;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, collectie_beheer_1, collection_image_viewer
  11.   { you can add units after this };
  12.  
  13. {$R *.res}
  14.  
  15. begin
  16.   RequireDerivedFormResource:=True;
  17. ***********  Application.Initialize;
  18.   Application.CreateForm(TMASTERform, MASTERform);
  19.   Application.CreateForm(TVIEWERform, VIEWERform);
  20.   Application.Run;
  21. end.
  22.  

Then I step further ...
Application.inc is already open where the last procedures compiled successfully:
Code: Pascal  [Select][+][-]
  1. {------------------------------------------------------------------------------
  2.   Method: TApplication.GetTitle
  3.   Returns: title of application
  4.  ------------------------------------------------------------------------------}
  5. function TApplication.GetTitle: string;
  6. begin
  7.   Result := inherited Title;
  8.   if Result = '' then
  9.     Result := ExtractFileNameOnly(GetExeName);
  10. end;

Then LazUTF8.pas is used and the debugger jumps to line 3734 (marker)
I can step further where at the second  line (indicated with ######### the debugger stops with the error : External SIGILL
Hitting OK gives me the line 3451

Code: Pascal  [Select][+][-]
  1. {------------------------------------------------------------------------------
  2.   Name:    UTF8ToUTF16
  3.   Params:  S - Source UTF-8 string
  4.   Returns: UTF-16 encoded string
  5.  
  6.   Converts the specified UTF-8 encoded string to UTF-16 encoded (system endian)
  7.   Avoid copying the result string since on windows a widestring requires a full
  8.   copy
  9.  ------------------------------------------------------------------------------}
  10. *********** function UTF8ToUTF16(const S: AnsiString): UnicodeString;
  11. begin
  12.   Result:=UTF8ToUTF16(PChar(S),length(S));
  13. end;
  14.  
  15. function UTF8ToUTF16(const P: PChar; ByteCnt: SizeUInt): UnicodeString;
  16. var
  17.   L: SizeUInt;
  18. begin
  19.   if ByteCnt=0 then
  20.     exit('');
  21.   SetLength(Result, ByteCnt);
  22.   // wide chars of UTF-16 <= bytes of UTF-8 string
  23. #############  if ConvertUTF8ToUTF16(PWideChar(Result), Length(Result) + 1, P, ByteCnt,
  24.     [toInvalidCharToSymbol], L) = trNoError
  25.   then SetLength(Result, L - 1)
  26.   else Result := '';
  27. end;
  28.  

I copied the function in LAZUTF8.pas where the debuggers finally stops and hitting F7 again I got the message execution broken ... wihtout an error-message.
Line 3451 is marked in red !

Code: Pascal  [Select][+][-]
  1.   function InvalidCharError(Count: SizeUInt): Boolean; inline;
  2.   begin
  3.     if not (toInvalidCharError in Options) then
  4.     begin
  5.       if toInvalidCharToSymbol in Options then
  6.       begin
  7.         Dest[DestI] := System.WideChar('?');
  8.         Inc(DestI);
  9.       end;
  10.  
  11.       Dec(SrcI, Count);
  12.  
  13.       // skip trailing UTF-8 char bytes
  14.       while (Count > 0) do
  15.       begin
  16.         if (Byte(Src[SrcI]) and %11000000) <> %10000000 then Break;
  17.         Inc(SrcI);
  18.         Dec(Count);
  19.       end;
  20.  
  21.       Result := False;
  22.     end
  23.     else
  24.       if toInvalidCharError in Options then
  25.       begin
  26.         ConvertUTF8ToUTF16 := trUnfinishedChar;
  27.         Result := True;
  28.       end;
  29.   end;
  30.  
  31. **************  begin
  32.   ActualWideCharCount := 0;
  33.  
  34.   if not Assigned(Src) then
  35.   begin
  36.     Result := trNullSrc;
  37.     Exit;
  38.   end;
  39.  
  40.   if not Assigned(Dest) then
  41.   begin
  42.     Result := trNullDest;
  43.     Exit;
  44.   end;
  45.   SrcI := 0;
  46.   DestI := 0;
  47.  

I hope this brings us somewhat further.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: rvk on December 13, 2018, 10:37:01 pm
Still think the problem is not in code.
Is the location of the database on the same.path with both pc and laptop?
If not, how are you filling those values (for databasepath/name)?
Do you have any connection.active set to true in design time or is active false and you set it in run-time?

Ps. Why do you, as a developer, don't have access to the antivirus-settings?
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 13, 2018, 11:06:32 pm
database is installed and running on an external HD.  Driveletter F:
On the laptop 1, and Laptop 2 and the PC, taht external disk is knwon as the F-drive.
Databse Mariadb is started up on the F:-disk
So, whatever I use, the database is the same, paths are the same .. used libmysql.dll is the same.

Why I have no priviledge to stop the anti-virus or modify it behaviour ?  Simple, that laptop resides in the network of the company where I work.  It is a request from audit, security that nobody has full admin-rights.  Only local and the several parameters of the laptop can't be change.

The second laptop, I own full admin rights. When stopping Aanti-virus for some minutes, the application still not run !
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: wp on December 14, 2018, 10:13:03 am
Remark: I did that step to step-debugging already.
...
Sorry I cannot follow these steps... Do I understand correctly that the crash happens in Application.CreateForm(TMasterForm, MasterForm) somewhere related to Application.GetTitle? But AFAICS this does not require the UTF8-to-UTF16 conversion... And what did you do that you can step into LCL units? Normally this is not possible.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: rvk on December 14, 2018, 10:21:52 am
You said all this happened after adding the second form to the program (I guess TVIEWERform).

What happens if you remove it?
What is included in the uses of TVIEWERform what is missing in TMASTERform?

You can look at the code all you want but I don't think you'll find the solution there (unless it is to debug where the crash happens). The .exe from the other machine also won't run on the laptop (while it runs on the PC just fine). To me, that says it must be an environment issue.

Also, the fact you see a blank window just before the crash (TMasterform?) says the crash happens after FormCreate and even after FormShow. Try setting a Showmessage at the end of FormCreate and one in FormShow and see if that's true.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 14, 2018, 12:56:37 pm
I'm out of resources ...

32bit Laptop164bit Laptop132bit Laptop264bit Laptop32bit PC64bit PC
Run on developmentNoNoNoNoYesYes


Laptop1Laptop2PC
Run as exeNoNoYes
Run as exe created on Laptop1 32bitNoNoYes
Run as exe created on Laptop1 64bitNoNoYes
Run as exe created on Laptop2 32bitNoNoYes
Run as exe created on Laptop2 64bitNoNoYes
Run as exe created on PC 32bitNoNoYes
Run as exe created on PC 64bitNoNoYes

That the environment has an impact ? Laptop 2 and PC have the same windowsbuild (except of course of drivers, ... but Win10 was installed the same way and it owns the same updates.

Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: rvk on December 14, 2018, 01:03:17 pm
Did you try any of the things I mentioned below?

i.e. removing TVIEWERForm again and/or putting Showmessage at several places.

I still think some other program just kills the program when it started.
Do you have some entries in the Windows Event Viewer (in Applications)?


You said all this happened after adding the second form to the program (I guess TVIEWERform).

What happens if you remove it?
What is included in the uses of TVIEWERform what is missing in TMASTERform?

You can look at the code all you want but I don't think you'll find the solution there (unless it is to debug where the crash happens). The .exe from the other machine also won't run on the laptop (while it runs on the PC just fine). To me, that says it must be an environment issue.

Also, the fact you see a blank window just before the crash (TMasterform?) says the crash happens after FormCreate and even after FormShow. Try setting a Showmessage at the end of FormCreate and one in FormShow and see if that's true.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: af0815 on December 14, 2018, 01:05:00 pm
a) What kind of exe have you compiled Win32 or Win64 ? Have you used the correct dlls and are this dlls available for the programm. Maybe in the same dir like the executable.
b)Have you tried to start the executable from a commandline ? Normally you see more information on the commandline. What is the message here ?
c) Not the windowsbuild have the great impact, more impact have the installed libraries.

 
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: BrunoK on December 14, 2018, 01:55:58 pm
It smells a too small buffer for conversion.

Try to change line  (3786 ?) in LazUTf8
SetLength(Result, ByteCnt);
to
SetLength(Result, ByteCnt+8); // +8 or maybe a bigger value

if it works you had a buffer overrun due to a bug (?), maybe due to the type of Utf8 char that could not be correctly be translated to UCS-2 (UTF-16).

If that's the case you have to be very careful about what caused the ConvertUTF8ToUTF16 to put out an Unfinished character.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: rvk on December 14, 2018, 01:59:47 pm
It smells a too small buffer for conversion.
I wouldn't trust the debugger (note that we are talking about gdb here) to pinpoint the exact crash location in this case.

When another program just kills the process, the gdb debugger will go completely nuts.

Since the same .exe (both the one compiled on laptop and PC) runs just fine on PC, I can't imagine it is something in code.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 14, 2018, 02:36:16 pm
Removed form2 then asked a clean build ...  No result. Same popup andclosing directly
remove/add form2 and a clean build ... Nothing changes

I have a form1create-procedure;
putting a showmessage at the beginning and at the end let see both messages while compiling ...
popup and closure ..

For the rest, I have now & form with some components and I have about 15 procdures that are fired when the application got focus and when, then you request for something.

Stupied question (more and more I will ask such). Can there be something about the path ?

I also changed the value in LAZUTF8.pas as mentioned ... No impact at all...
If someone wants the resources ... just ask for them. The DB I can deliver as  a ZIpped SQL

 :( %) :'(
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: rvk on December 14, 2018, 02:44:03 pm
You could still try something else... to determine it is something from the outside...

*) Put Dialogs in the uses of your project.lpr and put a Showmessage('a'); above Application.Initialize;
If the program still quits it is really something from the outside.
Showmessage is run before Application.Initialize but a second later (before you can press OK) some other program realizes you started this program and kills it.

*) What happens if you just create an empty project? Does that still work? (Just one form with a button and nothing else)

(Did you already look in the Event Viewer of Windows?)
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 14, 2018, 02:53:19 pm
1) I inserted your suggestion.  While compiling I got the message. Hitting ok, form pops up and closes immediately?
2) I can start a new project ...  as long this strange behaviour does not appear I can edit, modify, build, run that application.  So do I have several tools I made that are running.
The development for these tools is done on Laptop1 and when I'm at home on the PC.  The sources resides on an external portable HD.  Lazarus is installed the same way and on the Laptop or PC.
But, once the error appears (when I edited the application on the PC and then moves to the Laptop) is it done for infinity.
Problem is, it does not always happens and I can't tell when it happens because I edit several items and not just one line

program collectie_beheer;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, collectie_beheer_1, Dialogs;

{$R *.res}

begin
  RequireDerivedFormResource:=True;
  Application.Initialize;
  Application.CreateForm(TMASTERform, MASTERform);
  Showmessage('a');
  Application.Run;
end.


When I put the message after creation of the form, I got that message too.  So, problem somewhere when running

Note. PC and Laptop & owns a Intel-rpocessor, Laptopé is an AMD



It rends me sick ...
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: BrunoK on December 14, 2018, 03:00:36 pm
Quote
It smells a too small buffer for conversion.
I was thinking about something like Issue : 33296  corrected in Revision: 57429 that did nicely crash programs.
I wouldn't trust the debugger (note that we are talking about gdb here) to pinpoint the exact crash location in this case.

When another program just kills the process, the gdb debugger will go completely nuts.
I just find (Window 32bits) that GDB7.7.1 works bloody well for programs compiled :
-O1
-gw2
-godwarfsets
-gl

@WimVan

Can you post a minimal zipped project that cause the crash ? 
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 14, 2018, 03:16:35 pm
Here the request for the project.
I added to exe too, and the libmysql.dll
32bit
Be ware, the connector point to fotospotter_web ...
If needed, I can send an extract of the database too
Form2 is removed from the project and all it's references too
Exe is made on this setup

Zip seems to great, it can be downloaded from here: https://fotospotter.be/download/collectie_beheer.zip

Thanks
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: wp on December 14, 2018, 04:32:27 pm
Yes please post something to be used as database - right now the program is crashing when it is trying to connect to the DB because the DB is not found. Or don't you get this far? And do the folders DIR_SLIDE, DIR_THUMB, DIR_ORIGINAL have to be created manually or are they created by the program?
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 14, 2018, 04:50:41 pm
I'll leave the connection so the program is not looking for data.  Even then it fails to open it.
GIve now some time
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: rvk on December 14, 2018, 04:54:59 pm
You could try stripping the program (first make a backup).
Strip all the database components.
Then strip all other components.
In between test the program to see if it runs.

Once it runs you'll know what components are causing the problem.
(But my guess is still that it is from the outside but stripping components might provide some insight to when that process is going to kill your program)
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: Josh on December 14, 2018, 04:55:35 pm
Hi

Had a quick look at the code.
Some things to check in form create
What happens to these values when file is not found, also what happens if the file structure is not as you expect.
strtoint could cause a crash if text is not an integer maybe use strtointdef instead, as it has extra parameter to set a default value if strtoint is invalid.

Code: [Select]
if fileexists( cFile ) then
  begin
    with tStringList.create do
      try
        LoadFromFile( cFile );
        MASTERform.Top    := strtoint(Strings[0]);
        MASTERform.Left   := strtoint(Strings[1]);
        schijfeenheid.Text := trim( Strings[2] );
        folder.Text        := trim( Strings[3] );
        appl.Text          := trim( Strings[4] );
        foto_base.Text     := trim( Strings[5] );
        thumbhoogte.Text   := trim( Strings[6] );
      finally
        free;
      end;
  end;

at end of form.create put a breakpoint and check all the values are what you think they should be.

noticed various strtoint same as above.
noticed that your dividing /  what would happen if this value is very low or even 0; I would add some checks before any division to stop odd behaviour/crashes.  Data is not always valid so always check data before any operations are done on them.

Not sure of the use of thebutton in your button click event; when your assigning it to sender.
could you use ?
Code: [Select]
if sender is tbutton then
begin
  if tbutton(sender).tag=1 then

Just some quick observations; not have time to compile/test.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 15, 2018, 08:45:20 am
@Josh

I left some stuff to render a smaller application.
1) all  used var are always initialized
2) When a file with parameter-values is not found, default values are used.
3) Division by zero ?  These were values that I normally enter and check.
4) The code for the button is working as it should.

Why is that not present,
I left all stuff till it should work.
Be aware that the sources I send are a grabage-collection, a base without any control.

@Josh @rvk

This night I did the proposal stripping all stuff in the pas-source (Put in comment).

And yes, suddenly I could run it again on the Laptop !  I put the same garbage-written source on the PC and as I expected ir run there too.
Finally I found the place were things go wrong.

As the little app must serve to access several database I try to modify the SQLConnection.
While developing it is set to into the component.  This permits to see all needed info while developing (fdatafields ...)
When you choose another database (in setup) I close all connection and enter a new databasename and reopen the connection.
Strange, on the PC this runs !! however, on the Laptop this causes the strange behavour.
You try to run and all is compiling correctly, BUT, the app pops up and closes directly without any error ..
The new, read other databasename is stored in the 'parameter'-file and the default is fe 'test' which works correct.
This parameter can been entered in setup and is the edit-component 'foto_base'
At startup 'rerun) the stored value is entered in the SQLconnection-component.  This gives no error, but the application does not give focus on the Laptop.  The app pops up and closes immediately.  On the PC however it continues and there I get focus, but now I see that it does not change to another database if requested.

Code: Pascal  [Select][+][-]
  1.   MasterQuery.Close;
  2.   MasterQuery.Active              := False;
  3.   MasterSQLTransaction.Active := False;
  4.   DBConnection.Connected      := False;
  5.   DBConnection.d
  6. //  DBConnection.DatabaseName   := foto_base.Text;
  7.   DBConnection.HostName       := 'Localhost';
  8.   DBConnection.UserName       := 'root';
  9.   DBConnection.Connected      := True;
  10.   MasterSQLTransaction.Active := True;
  11.   MasterQuery.Active          := True;
  12.  

For Information.  The application is for the moment a kind of POC, because I'll have to adap some components (new components) so they act as I, we want.  But before starting the real app, I must be sure that what we wish is possible and acts as we hope ...  So sorry if it looks like a program which should never have been made.  And I now, sometimes that may be dangerous.  No errorchecks, ....
Now I'll look further why I can't change that database.
Meanwhile I do not understand why on the PC it runs and gives focus, on the Laptop it runs too but closes.
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: Josh on December 15, 2018, 09:49:44 am
do you have a delay between closing and re-opening a new database SQLConnection?.
is the opening and closing in a try except block?
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: BrunoK on December 15, 2018, 10:42:50 am
Try to run this little program on both the PC and the laptop.
Code: Pascal  [Select][+][-]
  1. program pgmCodePage;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes
  10.   { you can add units after this };
  11.  
  12. begin
  13.   WriteLn('DefaultSystemCodePage=',DefaultSystemCodePage);
  14.   WriteLn('DefaultUnicodeCodePage=',DefaultUnicodeCodePage);
  15.   { the code page to use when sending paths/file names to OS file system API
  16.     calls using single byte strings, and to interpret the results gotten back
  17.     from such API calls }
  18.   WriteLn('DefaultFileSystemCodePage=',DefaultFileSystemCodePage);
  19.   { the code page to use to return file names from single byte file system calls
  20.     in the RTL that return ansistrings (by default, same as a above) }
  21.   WriteLn('DefaultRTLFileSystemCodePage=',DefaultRTLFileSystemCodePage);
  22.   WriteLn('UTF8CompareLocale=',UTF8CompareLocale);
  23.   WriteLn;
  24.   WriteLn('Copy results and press enter to finish.');
  25.   ReadLn;
  26. end.
  27.  
Are the results identical on all the systems.

Do you have accents in the paths/filenames ? This is regarding automatic conversions from UTF-16 to UTF-8 and back.

Supposing you have a debug  version on the problematic laptop(s) and with the application you  published :
place a stop (F5) at the beginning of TMASTERform.FormCreate and trace F8 from here. If the procedure finishes then
so the same in
TMASTERform.setup_uitvoerenClick F5 at beginind and F8 from there.
so the same in
TMASTERform.MASTERgridDrawColumnCell
and
TMASTERform.MASTERgridCellClick

In the 2 last one I have doubts about the FieldByName('foto_dir').AsString and FieldByName('foto').AsString. Maybe they should be .AsText .Text

Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 15, 2018, 02:40:11 pm
@josh

closing and opening .... setup of all database-related components are set in a try -excep - block

Code: Pascal  [Select][+][-]
  1.    DBConnection.Close(true);
  2. showmessage('hier 3');
  3.    DBConnection.DatabaseName   := foto_base.Text;    // default value is fotospotter_web, it should be changed to fe 'test' (Content of foto_base.Text is 'test')
  4. showmessage('hier 4');
  5.     DBConnection.HostName       := 'Localhost';
  6.     DBConnection.UserName       := 'root';
  7.     MasterQuery.SQL.Text           := 'SELECT * FROM img_fotos ORDER BY foto_id DESC';  (table exists in fotospotter_web, aswel as in 'test'
  8. showmessage('hier 5');
  9.     DBConnection.Open;
  10. showmessage('hier 6');
  11.     DBConnection.Connected      := True;
  12. showmessage('hier 7');
  13.     MasterSQLTransaction.Active := True;
  14. showmessage('hier 8');
  15.      MasterQuery.Active          := True;
  16. showmessage('hier 9');
  17.      MasterQuery.Open;
  18. showmessage('hier 10');
  19.   except
  20.   on E: EDatabaseError do
  21.     begin
  22.       MessageDlg('Error', 'A database error has occurred. Technical error message: ' +
  23.         E.Message, mtError, [mbOK], 0);
  24.     end;
  25.   end;
  26. showmessage('hier 11');
  27.  

In this code, all messages appear from 1 to 11
Between message 5 to 6 there is a latency of some seconds ...
After message 11 the program closes directly. 
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: wp on December 15, 2018, 07:15:34 pm
This night I did the proposal stripping all stuff in the pas-source (Put in comment).

And yes, suddenly I could run it again on the Laptop !  I put the same garbage-written source on the PC and as I expected ir run there too.
Finally I found the place were things go wrong.

As the little app must serve to access several database I try to modify the SQLConnection.
While developing it is set to into the component.  This permits to see all needed info while developing (fdatafields ...)
When you choose another database (in setup) I close all connection and enter a new databasename and reopen the connection.
Strange, on the PC this runs !! however, on the Laptop this causes the strange behavour.
You try to run and all is compiling correctly, BUT, the app pops up and closes directly without any error ..
The new, read other databasename is stored in the 'parameter'-file and the default is fe 'test' which works correct.
This parameter can been entered in setup and is the edit-component 'foto_base'
At startup 'rerun) the stored value is entered in the SQLconnection-component.  This gives no error, but the application does not give focus on the Laptop.  The app pops up and closes immediately.  On the PC however it continues and there I get focus, but now I see that it does not change to another database if requested.

Code: Pascal  [Select][+][-]
  1.   MasterQuery.Close;
  2.   MasterQuery.Active              := False;
  3.   MasterSQLTransaction.Active := False;
  4.   DBConnection.Connected      := False;
  5.   DBConnection.d
  6. //  DBConnection.DatabaseName   := foto_base.Text;
  7.   DBConnection.HostName       := 'Localhost';
  8.   DBConnection.UserName       := 'root';
  9.   DBConnection.Connected      := True;
  10.   MasterSQLTransaction.Active := True;
  11.   MasterQuery.Active          := True;
  12.  
Did you try to save the project with DatabaseName cleared? Then, at runtime, you can set the DatabaseName (like you actually do).
Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 15, 2018, 11:22:02 pm
Acts the same way as if it is filled in.
Application pops up, and the closes ...

Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: rvk on December 15, 2018, 11:40:59 pm
Could you try creating a small project with just a dbgrid and the database components on the laptop and trying to run it. Just a minimalistic example. Just to make sure the dlls and database work.

Because you reach point 11 I still think something is messing with the process.

Btw. Close and active := false and open and active := true are the same on a query. So you don't need to do them both.
The same goes for open and connected on the dbconnection. Just use one or the other but not both.

Title: Re: Why is an exe not running when Lazarus IDE is not used ?
Post by: WimVan on December 16, 2018, 10:24:42 am
Reposition of the behaviour.
1) When the application is build, I have entered all neede parameters in TMySQL57Connection.
All linked items are only made active when the application is build and run. Run in development, run as an only exe.

2) This runs good on the PC and on the Laptops

3) When I add an edit-component, so I can change the database while running, the I have following
On the laptops, the application pops up and directly closes.  The value from the edit-component is inserted in the TMysql57Connection-component.
On the PC it runs, BUT, the database has not changed.  Still data from the Database that was assigned at development.

I'll check if perhaps that active and open ... is not the origine of that misbehviour.  Who knows ?
TinyPortal © 2005-2018