Recent

Author Topic: "Run without Debugging" and "Command line parameters"  (Read 1871 times)

cvpas

  • Newbie
  • Posts: 2
"Run without Debugging" and "Command line parameters"
« on: September 25, 2018, 11:28:28 pm »
Hi,

  I did a fresh install of Lazarus 1.8.4 (lazarus-1.8.4-fpc-3.0.4-win32.exe) on Windows 10 64 bit.
I set the value of "Run parameters - Command line parameters" to: "first second third" (without quotes).
Running this simple program:

Code: Pascal  [Select]
  1. program test_params;
  2.  
  3. {$IFDEF FPC}
  4.   {$MODE DELPHI}
  5. {$ELSE}
  6.   {$APPTYPE CONSOLE}
  7. {$ENDIF}
  8.  
  9. var
  10.   i: Integer;
  11. begin
  12.   for i := 1 to ParamCount do
  13.     WriteLn('Param(', i, ')=', ParamStr(i));
  14.   WriteLn('Press Enter to exit ...');
  15.   ReadLn;
  16. end.
  17.  

from Lazarus IDE using "Run" (F9) the output is:

Param(1)=first
Param(2)=second
Param(3)=third
Press Enter to exit ...

wich is what I expect.
  But when I run the program using "Run without Debugging" (Shift+Ctrl+F9) the output is:

Param(1)=first second third
Press Enter to exit ...

  It seems that in the second case Lazarus IDE will send the content of "Command line parameters" as a single parameter to the executable.
  Is this a bug or is it "by design" ?

Thank you.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 724
Re: "Run without Debugging" and "Command line parameters"
« Reply #1 on: September 26, 2018, 01:10:17 am »
I did a fresh install of Lazarus 1.8.4 (lazarus-1.8.4-fpc-3.0.4-win32.exe) on Windows 10 64 bit.
I set the value of "Run parameters - Command line parameters" to: "first second third" (without quotes).
Running this simple program:

Code: Pascal  [Select]
  1. program test_params;
  2.  
  3. {$IFDEF FPC}
  4.   {$MODE DELPHI}
  5. {$ELSE}
  6.   {$APPTYPE CONSOLE}
  7. {$ENDIF}
  8.  
  9. var
  10.   i: Integer;
  11. begin
  12.   for i := 1 to ParamCount do
  13.     WriteLn('Param(', i, ')=', ParamStr(i));
  14.   WriteLn('Press Enter to exit ...');
  15.   ReadLn;
  16. end.
  17.  

from Lazarus IDE using "Run" (F9) the output is:

Param(1)=first
Param(2)=second
Param(3)=third
Press Enter to exit ...

wich is what I expect.
  But when I run the program using "Run without Debugging" (Shift+Ctrl+F9) the output is:

Param(1)=first second third
Press Enter to exit ...

  It seems that in the second case Lazarus IDE will send the content of "Command line parameters" as a single parameter to the executable.
I can confirm both situations on Microsoft Windows 7.
And I can add that Command Line behavior is correct. See image.
Code: Pascal  [Select]
  1. program Project1;
  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. var
  13.   i: Integer;
  14. begin
  15.   for i := 1 to ParamCount do
  16.     WriteLn('Param(', i, ')=', ParamStr(i));
  17.   WriteLn('Press Enter to exit ...');
  18.   ReadLn;
  19. end.
Quote
  Is this a bug or is it "by design" ?
I believe it's a bug because "Run" (F9) and  "Run without Debugging" (Shift+Ctrl+F9) should have the same behavior and produce the same output.
Please, fill in a bug report.

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 213
Re: "Run without Debugging" and "Command line parameters"
« Reply #2 on: September 26, 2018, 09:53:38 am »
Patch attached.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3609
  • I like bugs.
Re: "Run without Debugging" and "Command line parameters"
« Reply #3 on: September 26, 2018, 10:34:37 am »
Patch attached.
Thanks. I applied it in r59168. Please test everybody. It will be merged to 2.0 branch later.

cvpas

  • Newbie
  • Posts: 2
[SOLVED] "Run without Debugging" and "Command line parameters"
« Reply #4 on: September 26, 2018, 03:22:19 pm »
Hi,

  Using the patch provided by Ondrej Pokorny I did the following changes to the method TMainIDE.DoRunProjectWithoutDebug in \lazarus\ide\main.pp from Lazarus 1.8.4 original sources:

- declared two additional variables:
Code: Pascal  [Select]
  1. var
  2.   ExeFile, Params: string;
  3.  

- replaced the lines:
Code: Pascal  [Select]
  1.  
  2.     Process.Executable := Copy(ExeCmdLine, ExeFileStart, ExeFileEnd-ExeFileStart);
  3.     Process.Parameters.Text := Copy(ExeCmdLine, ExeFileEnd+ExeFileStart, High(Integer));
  4.  
with:
Code: Pascal  [Select]
  1.     SplitCmdLine(ExeCmdLine, ExeFile, Params);
  2.     Process.Executable := ExeFile;
  3.     if Params <> '' then
  4.       CommandToList(Params, Process.Parameters);
  5.  

After rebuilding Lazarus IDE I can confirm that "Run without Debugging" produces the same output as "Run".

   Thank you for your help and for this great IDE

totya

  • Sr. Member
  • ****
  • Posts: 499
Re: "Run without Debugging" and "Command line parameters"
« Reply #5 on: May 19, 2019, 09:53:43 pm »
This problem is stay in Lazarus rev61198 (fixes), fpc 3.0.5(fixes)

Run with debugging, or run directly exe with parameters, okay. But run without debugging, the first parameter ParamStr(1) invalid, because my code won't work.

My code in formcreate about:

Code: Pascal  [Select]
  1. if UpperCase(ParamStr(1)) = UpperCase('XX') then XCheckBox.Visible := True;
  2.  

But, this code works in same place without debugging:
Code: Pascal  [Select]
  1. ShowMessage('"'+ParamStr(1)+'"');
  2.  

I like Lazarus, but I always got many impossible errors... :)

Environment: Win7, x64, compiled to x86.

Edit1.:
After this project lps file deleted, now above code works without debugging. LOL.
Edit2.:
... because build mode changed to "default". But with "release" build mode, the above code doesn't work without debugging. In debug build mode - works.
« Last Edit: May 19, 2019, 10:07:40 pm by totya »

totya

  • Sr. Member
  • ****
  • Posts: 499
Re: "Run without Debugging" and "Command line parameters"
« Reply #6 on: June 02, 2019, 01:03:37 pm »
Hi!

Any news with this bug?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5390
    • wiki

totya

  • Sr. Member
  • ****
  • Posts: 499
Re: "Run without Debugging" and "Command line parameters"
« Reply #8 on: June 04, 2019, 05:07:12 pm »
https://bugs.freepascal.org/view.php?id=35649

Thanks for the info!

I thought this bug is forgotten, because last message from this bug in this topic almost one years old. I have a "fixes 2.0" Lazarus, so I can try it , when arrive this patch to the fixes.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5390
    • wiki
Re: "Run without Debugging" and "Command line parameters"
« Reply #9 on: June 04, 2019, 05:45:17 pm »
Actually, if you check the comment by Juha, it had been fixed. However it had somehow later been broken again.

Asking here an the forum, is a first step. Especially if it is something you are not sure it is a bug.

But the forum is not a replacement for the bugtracker. It always needs to go to the bugtracker, unless someone (who is part of the Lazarus team /developer with svn write access) acknowledges the issue here on the forum, *and* explicitly says that there is no need to report on the bugtracker.

totya

  • Sr. Member
  • ****
  • Posts: 499
Re: "Run without Debugging" and "Command line parameters"
« Reply #10 on: June 05, 2019, 09:28:17 pm »
Thanks again for this information...

totya

  • Sr. Member
  • ****
  • Posts: 499
Re: "Run without Debugging" and "Command line parameters"
« Reply #11 on: June 13, 2019, 06:02:38 pm »
I have the fpcupdeluxe, and my settings is fixes 2.0. I noticed, this branch freshed, now my Lazarus version is rev 61376, and seems to me the topic problem is solved, it's works. Thanks for the Lazarus developers!