Recent

Author Topic: Anatomy of a Lazarus/LCL Gui Application  (Read 609 times)

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Anatomy of a Lazarus/LCL Gui Application
« on: September 19, 2024, 12:39:54 am »
hello, this is the result of my searching and collecting relevant bits and pieces of info and then compiling them into a single document. I hope this will be a useful resource, especially to total newbies and beginners. I would be grateful if you all would have a look see and comment or give some feedback. Thank you.

( It is a lot of work and time consuming and I do not want to continue if no one feels this can be useful.)
EDIT: Do we have anything similar in our Lazarus documentation?
EDIT:  Thu, Sep 19th 2024 @ 4:50 AM: Title renamed as suggested by @Martin_fr [ was: Lazarus IDE defaults when first opened]
« Last Edit: September 19, 2024, 10:50:30 am by Aruna »
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

MarkMLl

  • Hero Member
  • *****
  • Posts: 7720
Re: Lazarus IDE defaults when first opened
« Reply #1 on: September 19, 2024, 08:31:08 am »
Below is the result of a certain amount of digging around, but basically resulted in a .lpr which was usable by anything in the range implied by the banner... at least on Linux.

Code: Pascal  [Select][+][-]
  1. (* Lazarus+FPC 0.9.24+2.2.4 on Linux Lazarus+FPC 0.9.24+2.2.4 on Linux Lazarus+ *)
  2. (* Lazarus+FPC 2.2.4+3.2.2 on Linux Lazarus+FPC 2.2.4+3.2.2 on Linux Lazarus+FP *)
  3.  
  4. program calibration;
  5.  
  6. {$mode objfpc}{$H+}
  7.  
  8. uses
  9.   {$IFDEF UNIX}
  10.   cthreads,
  11.   {$ENDIF}
  12.   {$IFDEF HASAMIGA}
  13.   athreads,
  14.   {$ENDIF}
  15.   Interfaces, // this includes the LCL widgetset
  16.   Forms, IniFilesAbout, calibrate, TelnetServer, TelnetBuffer,
  17.                                         TelnetTextRec, TelnetCommon;
  18.  
  19. (* Note the conditional compilation here specifically to support "old-style"    *)
  20. (* resources etc. as used by a pre-v1 Lazarus typically with a pre-v2.4 FPC. In *)
  21. (* practice that means FPC 2.2.4, since no attempt is made to support older     *)
  22. (* versions due to their lack of the FPC_FULLVERSION predefined.                *)
  23.  
  24. {$if FPC_FULLVERSION >= 020400 }
  25.   {$R *.res}
  26. {$endif FPC_FULLVERSION        }
  27.  
  28. begin
  29.  
  30. (* Lazarus v1 (roughly corresponding to FPC 3.0) introduced this global         *)
  31. (* variable, defaulting to false. It controls error reporting at startup if an  *)
  32. (* expected .lfm is missing, so may be omitted if unsupported by the target LCL *)
  33. (* etc. version e.g. by using the test $if LCL_FULLVERSION >= 1000000...$ifend. *)
  34.  
  35. {$if declared(RequireDerivedFormResource) }
  36.   RequireDerivedFormResource:=True;
  37. {$endif declared                          }
  38.  
  39. (* Lazarus v2 or later might insert  Application.Scaled := true  here if the    *)
  40. (* project-level application settings include "Use LCL scaling". We probably    *)
  41. (* don't want this since it might have the effect of messing up the pixel-level *)
  42. (* operations we're trying to calibrate, and in any event will make this file   *)
  43. (* incompatible with older versions if that's what's on the hardware in use. If *)
  44. (* required guard using the test $if LCL_FULLVERSION >= 1080000...$ifend.       *)
  45.  
  46.   if (ParamCount() > 0) and (Pos('-version', LowerCase(ParamStr(1))) > 0) then begin
  47.     WriteLn(AboutText);
  48.     Halt(0)
  49.   end;
  50.   Application.Initialize;
  51.   Application.CreateForm(TForm1, Form1);
  52.   Application.Run;
  53. end.
  54.  

There's a few other potential hacks which are very useful to know about, albeit not in the standard IDE output. In particular

Code: Pascal  [Select][+][-]
  1. program B5k5;
  2.  
  3. (* This is a non-graphical frontend to the B5k5 central control unit, running   *)
  4. (* in the context of the program's main thread. MarkMLl.                        *)
  5.  
  6. {$mode objfpc}{$H+}
  7.  
  8. {$ifndef UNIX }
  9.   {$error Requires a unix-type operating system }
  10. {$endif UNIX }
  11.  
  12. {$ifndef USE_CTHREADS }
  13.   {$error Requires -dUSE_CTHREADS in Project -> Compiler -> Other -> Custom Options }
  14. {$endif USE_CTHREADS }
  15.  
  16. (* Note manual addition of cmem below, this is required to allow strings and    *)
  17. (* objects to be shared/transferred between the main program and a shared       *)
  18. (* library. Note also relative position of HeapTrc, if cmem is used it is not   *)
  19. (* possible to specify this at the project level (i.e. to use FPC's -gh option).*)
  20.  
  21. uses
  22. {$ifdef USE_CMEM }
  23.   cmem, {$ifdef USE_HEAPTRC } HeapTrc, {$endif USE_HEAPTRC }
  24. {$endif USE_CMEM }
  25.   {$IFDEF UNIX}
  26.   cwstring,
  27.   {$IFDEF USE_CTHREADS}
  28.   cthreads,
  29.   {$ENDIF}{$ENDIF}
  30.  
  31. ...
  32.  

Also considering "defaults" in a wider context: much of the IDE behaviour including what packages are installed is stored in ~/.lazarus (or equivalent on Windows etc.) unless overridden by the --pcp= option. This can be tailored to some extent using the Options -> Set compiler options as default checkbox, but there are a few things this doesn't include notably the output file name.

Hope this is of some minor interest.

MarkMLl
« Last Edit: September 19, 2024, 08:48:25 am by 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

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10310
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus IDE defaults when first opened
« Reply #2 on: September 19, 2024, 10:10:40 am »
It doesn't currently have all the methods, but some can be found here. https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tapplication.html

Your work is nice, but I would propose to change the title. "Lazarus IDE Defaults" will be more associated with settings, like hotkeys, and stuff in menu Tools > Options.
You really are looking at the "Anatomy of a Lazarus/LCL Gui Application". And for that it is certainly interesting.

Mind that before the first line in the project's code is even run, code from initialization sections in other units will have been run. Such as initializing the Widgetset (Interfaces) and registration of graphic types (so forms can later load icons).

You may find the image on this page of interest https://wiki.freepascal.org/Widgetset



You may also consider to break your work into 2 sections. Currently you go through the code line by line.

Maybe (maybe not / just think about it) separate the explanation into
- the Pascal structure
- the functional elements

Pascal Structure are keywords like program, begin, end, uses. Those are just telling the compiler what the rest of the code means.

The functional bits then is the rest. The $mode turning on/off certain options in the compiler. (there is a list somewhere). The uses, which includes triggering initialization. Or the code in begin/end.

Then there may be as an extension, how this code is controlled. In Project > Project Options, you can specify which forms (you can have many) are auto-created. And code like Application.CreateForm is automatically removed or inserted.

LBoxPO

  • New Member
  • *
  • Posts: 15
Re: Anatomy of a Lazarus/LCL Gui Application
« Reply #3 on: September 19, 2024, 12:05:54 pm »
hello, this is the result of my searching and collecting relevant bits and pieces of info and then compiling them into a single document. I hope this will be a useful resource, especially to total newbies and beginners. I would be grateful if you all would have a look see and comment or give some feedback. Thank you.

( It is a lot of work and time consuming and I do not want to continue if no one feels this can be useful.)
EDIT: Do we have anything similar in our Lazarus documentation?
EDIT:  Thu, Sep 19th 2024 @ 4:50 AM: Title renamed as suggested by @Martin_fr [ was: Lazarus IDE defaults when first opened]

Thank you very much  8)👍

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Anatomy of a Lazarus/LCL Gui Application
« Reply #4 on: September 19, 2024, 02:39:10 pm »
<snip>..
Thank you very much  8)👍
Your very welcome. Do me a favour? Please check out these two links and tell me which one you like more:
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Lazarus IDE defaults when first opened
« Reply #5 on: September 19, 2024, 02:48:29 pm »
It doesn't currently have all the methods, but some can be found here. https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tapplication.html
Thank you.

Your work is nice, but I would propose to change the title. "Lazarus IDE Defaults" will be more associated with settings, like hotkeys, and stuff in menu Tools > Options.
You really are looking at the "Anatomy of a Lazarus/LCL Gui Application". And for that it is certainly interesting.
I have changed the title and thank you agin for the kind words but personally I would have preferred 'useful' over 'nice'  :P

Mind that before the first line in the project's code is even run, code from initialization sections in other units will have been run. Such as initializing the Widgetset (Interfaces) and registration of graphic types (so forms can later load icons).
I never thought about that until you pointed this out  :-\

Currently you go through the code line by line.
Yes for a very good reason, when "I" was very new something like this would have clarified a whole lot of things for me. There may be others out there who like me can use a line by line breakdown?


Maybe (maybe not / just think about it) separate the explanation into
- the Pascal structure
- the functional elements
I have thought about it and am going to comply and implement, when I cannot say. As and when I have free time :-)
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Lazarus IDE defaults when first opened
« Reply #6 on: September 19, 2024, 02:53:23 pm »
Hope this is of some minor interest.
Hello Mark this is of great interest to me. Thank you for sharing. Listen,what do you feel about what I put together so far? Carry on and host on my server? Or slowly integrate into our wiki? Would be nice to have a community consensus on this? What do you think? Do let me know.
« Last Edit: September 19, 2024, 03:02:05 pm by Aruna »
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

MarkMLl

  • Hero Member
  • *****
  • Posts: 7720
Re: Lazarus IDE defaults when first opened
« Reply #7 on: September 19, 2024, 05:54:17 pm »
Listen,what do you feel about what I put together so far? Carry on and host on my server? Or slowly integrate into our wiki? Would be nice to have a community consensus on this? What do you think? Do let me know.

Hmm. I think there's a good argument for having two copies: one on the FPC wiki plus what you consider to be your definitive one (e.g. on a Github wiki page ** ). That way you could learn from the edits that other people put into the FPC version, but would still have somewhere where you could focus on what you were trying to say and wouldn't have to worry about large chunks of it going astray.

** if you're not particularly bothered about its being abused by "AI" etc. That also has the advantage that any cross-references e.g. during discussion on the forum wouldn't point to a URL that people didn't recognise which ordered them to enable Javascript before it would be polite :-)

There's precedent for this sort of thing: you've probably already been directed to the "OOP Structures in Pascal" document at https://github.com/zsoltszakaly/OOPstructuresinpascal

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