Recent

Author Topic: [solved for now] Form1 calling Form2 via Command-Line-param  (Read 1082 times)

Zvoni

  • Hero Member
  • *****
  • Posts: 3136
[solved for now] Form1 calling Form2 via Command-Line-param
« on: March 10, 2022, 10:33:22 am »
Hi Folks,

program starts, code in the lpr Creates Form1, there with Menus i call Form2

So far, so good

Now i want to offer the option to start the program from the CLI with passing some options (e.g. "myapp.exe -report ODBC")

In the lpr i check HasOption and use GetOptionValue if True. Works!

BUT: How can i show Form2 only AFTER Form1 is completely painted?
I'm looking for something like "AfterShow"-Event.
NB: i already tried OnActivate of Form1, but for some unknown reason that one doesn't fire

Form2 is Modal with Form1 as Parent

Pseudo-code
Code: Pascal  [Select][+][-]
  1. //in lpr
  2. If Application.HasOption('r','report') Then Report:=Application.GetOptionValue('r','report');
  3. Form1.Show;
  4. //In Form1
  5. If Report='ODBC' Then
  6.         If Form1 is completely visbile Then Form2.ShowModal;
  7.  

EDIT: Right, easy to workaround with a Timer set to 500, but..... seriously?
And i got Activate to fire. No idea what i did wrong in the first run
« Last Edit: March 10, 2022, 10:59:44 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

MarkMLl

  • Hero Member
  • *****
  • Posts: 8504
Re: [solved for now] Form1 calling Form2 via Command-Line-param
« Reply #1 on: March 10, 2022, 11:04:53 am »
I normally use something like this

Code: Pascal  [Select][+][-]
  1. (* This is called when the wm_After_Show message is dequeued, which is
  2.   guaranteed to be after form creation has completed.
  3. *)
  4. procedure TWatchxxxForm.OnAfterShow(afterShowParam: PtrInt);
  5. ...
  6.  
  7. (* The form is being created, but sizes might not yet be known particularly if
  8.   there's rescaling due to DPI variation.
  9. *)
  10. procedure TWatchxxxForm.FormCreate(Sender: TObject);
  11.  
  12. begin
  13. ...
  14.   if Screen.Width < 854 then            (* Last-ditch attempt to handle small   *)
  15.     Width := 768;                       (* screens for support via VNC etc.     *)
  16.   Application.QueueAsyncCall(@OnAfterShow, WatchxxxCodeMagicNumber) (* Keep at end *)
  17. end { TWatchxxxForm.FormCreate } ;
  18.  

But I don't know whether than delays until after everything has been displayed or just until everything has been created/initialised.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Zvoni

  • Hero Member
  • *****
  • Posts: 3136
Re: [solved for now] Form1 calling Form2 via Command-Line-param
« Reply #2 on: March 10, 2022, 12:30:11 pm »
Mark,

i take it the "WatchxxxCodeMagicNumber" is the WM_AFTER_SHOW?
You got a value for me?
All i could find was WM_AFTER_SHOW=WM_USER+1
I'd at least try it out
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

MarkMLl

  • Hero Member
  • *****
  • Posts: 8504
Re: [solved for now] Form1 calling Form2 via Command-Line-param
« Reply #3 on: March 10, 2022, 12:44:48 pm »
Mark,

i take it the "WatchxxxCodeMagicNumber" is the WM_AFTER_SHOW?
You got a value for me?
All i could find was WM_AFTER_SHOW=WM_USER+1
I'd at least try it out

Sorry, no: it's just an arbitrary number which is checked at the point of consumption. In practice I use a datecode, declared private to the unit.

Back in the Delphi era that was a windows message, but when I started using Lazarus somebody suggested an asynccall instead.

There's a complete example at https://github.com/MarkMLl/Contec_cms50dplus/blob/main/cms50dplus4v6/cms50dpluscode.pas

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018