Recent

Author Topic: Why is an exe not running when Lazarus IDE is not used ?  (Read 12681 times)

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #30 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 ? 

WimVan

  • Jr. Member
  • **
  • Posts: 85
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #31 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
« Last Edit: December 14, 2018, 03:18:58 pm by WimVan »

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #32 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?

WimVan

  • Jr. Member
  • **
  • Posts: 85
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #33 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

rvk

  • Hero Member
  • *****
  • Posts: 6056
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #34 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)

Josh

  • Hero Member
  • *****
  • Posts: 1270
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #35 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.
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

WimVan

  • Jr. Member
  • **
  • Posts: 85
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #36 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.

Josh

  • Hero Member
  • *****
  • Posts: 1270
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #37 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?
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #38 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

« Last Edit: December 15, 2018, 10:44:53 am by BrunoK »

WimVan

  • Jr. Member
  • **
  • Posts: 85
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #39 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. 

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #40 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).

WimVan

  • Jr. Member
  • **
  • Posts: 85
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #41 on: December 15, 2018, 11:22:02 pm »
Acts the same way as if it is filled in.
Application pops up, and the closes ...


rvk

  • Hero Member
  • *****
  • Posts: 6056
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #42 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.


WimVan

  • Jr. Member
  • **
  • Posts: 85
Re: Why is an exe not running when Lazarus IDE is not used ?
« Reply #43 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