Forum > Beginners
<solved> command line
Handoko:
Done.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Dialogs; type { TForm1 } TForm1 = class(TForm) procedure FormActivate(Sender: TObject); procedure FormCreate(Sender: TObject); private Data: array of string; end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormActivate(Sender: TObject);const RunOnce: Boolean = False;var S: string; i: Integer;begin if RunOnce then Exit; RunOnce := True; S := 'Command line parameters:' + LineEnding; for i := 0 to Length(Data)-1 do S := S + 'Param' + i.ToString + ': ' + Data[i] + LineEnding; ShowMessage(S);end; procedure TForm1.FormCreate(Sender: TObject);var i: Integer;begin SetLength(Data, ParamCount+1); for i := 0 to ParamCount do Data[i] := ParamStr(i);end; end.
* We should not put any screen/display related operations in FormCreate event because OnCreate event is just for initializating data, many screen objects haven't really prepared for displaying. So I put ShowMessage command in the FormActivate event, see line #42.
* A small trick I used for make it runs only once, see line #32.
* Because ParamStr starts from 0, ParamCount needs to be added with 1, see line #49.
* No need to free the Data, because dynamic arrays are finalized automatically when program comes to end.To supply command line parameters in Lazarus:
Lazarus main menu > Run > Run Parameters
You can download the source code below for testing.
ASerge:
--- Quote from: Handoko on May 11, 2024, 05:09:19 am ---A small trick I used for make it runs only once, see line #32.
--- End quote ---
Another version of the trick:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---... procedure AppInit(Data: PtrInt);...procedure TForm1.FormCreate(Sender: TObject);begin Application.QueueAsyncCall(@AppInit, 0);end; The AppInit will be called after all OnActivate, OnShow and before the first OnIdle.
Handoko:
A new trick. I haven't known about. I will surely use it next time. Thank you for sharing it.
Sprek Skik:
Thanks for all the replies!
Sprek Skik:
--- Quote from: Handoko on May 11, 2024, 05:09:19 am ---Done.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Dialogs; type { TForm1 } TForm1 = class(TForm) procedure FormActivate(Sender: TObject); procedure FormCreate(Sender: TObject); private Data: array of string; end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormActivate(Sender: TObject);const RunOnce: Boolean = False;var S: string; i: Integer;begin if RunOnce then Exit; RunOnce := True; S := 'Command line parameters:' + LineEnding; for i := 0 to Length(Data)-1 do S := S + 'Param' + i.ToString + ': ' + Data[i] + LineEnding; ShowMessage(S);end; procedure TForm1.FormCreate(Sender: TObject);var i: Integer;begin SetLength(Data, ParamCount+1); for i := 0 to ParamCount do Data[i] := ParamStr(i);end; end.
* We should not put any screen/display related operations in FormCreate event because OnCreate event is just for initializating data, many screen objects haven't really prepared for displaying. So I put ShowMessage command in the FormActivate event, see line #42.
* A small trick I used for make it runs only once, see line #32.
* Because ParamStr starts from 0, ParamCount needs to be added with 1, see line #49.
* No need to free the Data, because dynamic arrays are finalized automatically when program comes to end.To supply command line parameters in Lazarus:
Lazarus main menu > Run > Run Parameters
You can download the source code below for testing.
--- End quote ---
I will test it, because I have the experience that FormActivate doesn't work in my code...( example program klokje from https://wiskunst.nl/index.php/programmeren1/delphi-lazarus/lazarus-klokje-intro/)
Navigation
[0] Message Index
[#] Next page
[*] Previous page