Recent

Author Topic: TMainMenu not showing  (Read 1875 times)

shock

  • Newbie
  • Posts: 2
TMainMenu not showing
« on: October 22, 2024, 12:07:03 am »
Hi.  Please be patient because I am new to Lazarus, but not to Delphi.  I have over a few years been converting a number of (command line) programs to FreePascal.  That has gone smoothly.  One of those programs uses VCL (now LCL) to run a couple of tests which plot graphics on a form.  The form uses a TMainMenu with a menu item for each test.  My problem is that the main menu is not shown.  I have searched for a day and am unable to work out what I have done wrong.  I can add other controls, such as a TButton, and they appear on the form.

I run Linux Mint 21.3 x86_64, Cinnamon 6.0.4, Lazarus 3.6, FPC 3.2.2, x86_64_linux-gtk2.  FPC and Lazarus were downloaded and installed again yesterday, to make sure I had the latest versions.

Note that I do *not* use the Lazarus or FreePascal IDEs.  I attach a severely trimmed program which shows, at least on my computer, the problem: the button is shown but not the main menu.  If I go the normal way of using the Lazarus IDE the main menu is shown, but I need all this to happen automatically using the command line and custom make files.

Any help will be appreciated.

Thank you.

jamie

  • Hero Member
  • *****
  • Posts: 7763
Re: TMainMenu not showing
« Reply #1 on: October 22, 2024, 12:45:03 am »
I didn't look at your app because I am on Windows.

But, did you put the TApplication in as the main GUI from end and did you use the CreateForm to greate the forms?
The only true wisdom is knowing you know nothing

Aruna

  • Hero Member
  • *****
  • Posts: 807
Re: TMainMenu not showing
« Reply #2 on: October 22, 2024, 01:30:12 am »
<snip> but I need all this to happen automatically using the command line and custom make files.
Any help will be appreciated.

Hello, what is your command line @shock? Does it even vaguely resemble this:
Code: Pascal  [Select][+][-]
  1. fpc -MObjFPC -Scghi -O1 -vewnhi -l -dLCL -dLCLGtk2 -Fu/home/aruna/lazarus3/lazarus/lcl/units/x86_64-linux/gtk2 -Fu/home/aruna/lazarus3/lazarus/packager/units/x86_64-linux WSLCL.pas

I tried to build your zip I managed to get some progress but now trying to resolve this error:
Code: Text  [Select][+][-]
  1. Free Pascal Compiler version 3.2.2 [2021/07/09] for x86_64
  2. Copyright (c) 1993-2021 by Florian Klaempfl and others
  3. Target OS: Linux for x86-64
  4. Compiling WSLCL.pas
  5. Fatal: Can't find unit LMessages used by Gtk2Int
  6. Fatal: Compilation aborted
  7. Error: /usr/bin/ppcx64 returned an error exitcode

So I am curious what command and flags you used when compiling, this is the reason I asked.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4715
  • I like bugs.
Re: TMainMenu not showing
« Reply #3 on: October 22, 2024, 02:08:34 am »
Indeed you did not mention how you compiled it.
You must create a Lazarus project with LCL dependency. Then you can build it with the command line LazBuild.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Aruna

  • Hero Member
  • *****
  • Posts: 807
Re: TMainMenu not showing
« Reply #4 on: October 22, 2024, 03:21:17 am »
Indeed you did not mention how you compiled it.
You must create a Lazarus project with LCL dependency. Then you can build it with the command line LazBuild.

Hello Juha, so if I use LazBuild I do not have to worry about any dependencies? LazBuild will pull in everything that is needed?

I also just noticed in the OP's code he is assigning at first :
Code: Pascal  [Select][+][-]
  1.  test_Menu_Item_1.OnClick := Run_Test_1;

And later on to:
Code: Pascal  [Select][+][-]
  1. test_Menu_Item_1.OnClick := Run_Test_2;
Which to me does not make sense??

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TMainMenu not showing
« Reply #5 on: October 22, 2024, 05:31:27 am »
My problem is that the main menu is not shown.
Add the following lines after you created the individual item(s):

Code: Pascal  [Select][+][-]
  1.   test_main_Menu.Items.Add(test_Menu_Item_1);
  2.   test_main_Menu.Items.Add(test_Menu_Item_2);
  3.  
Today is tomorrow's yesterday.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TMainMenu not showing
« Reply #6 on: October 22, 2024, 05:42:57 am »
Indeed you did not mention how you compiled it.
TS provided a fpc.cfg which kinda removes the requirement to mention it.

small snippet:
Code: [Select]
-Fu/usr/share/lazarus/3.6.0/lcl/units/$fpctarget
-Fu/usr/share/lazarus/3.6.0/lcl/units/$fpctarget/*
-Fu/usr/share/lazarus/3.6.0/lcl/units/$fpctarget/gtk2
-Fu/usr/share/lazarus/3.6.0/components/lazutils/lib/$fpctarget

Quote
You must create a Lazarus project with LCL dependency. Then you can build it with the command line LazBuild.
Whenever I read the word must then I think to myself, really ? and how can we do without ?  :)

Turns out, pretty easy as long as you know what you are doing (and yes, I also get stuck with FPC attempting to compile packages with the command-line compiler because that can be a rats nest with all its dependencies = use lazbuild).
Today is tomorrow's yesterday.

Aruna

  • Hero Member
  • *****
  • Posts: 807
Re: TMainMenu not showing
« Reply #7 on: October 22, 2024, 04:10:02 pm »
Turns out, pretty easy as long as you know what you are doing (and yes, I also get stuck with FPC attempting to compile packages with the command-line compiler because that can be a rats nest with all its dependencies = use lazbuild).
Hi TRon I have never used LazBuild before this is my first time and it chokes with:
Code: Text  [Select][+][-]
  1. aruna@debian:~/lazarus/forum-demos/shock/test$ lazbuild --verbose WSLCL.pas
  2. Error: (lazbuild) don't know how to build: /home/aruna/lazarus/forum-demos/shock/test/WSLCL.pas

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TMainMenu not showing
« Reply #8 on: October 22, 2024, 04:20:48 pm »
Hi TRon I have never used LazBuild before this is my first time and it chokes with:
Lazbuild requires a lazarus project information file (.lpi) or Lazarus PacKage (.lpk) file to be able to build a Lazarus program/package.

TS wrote a (pure) pascal program without providing a .lpi file. In such a program it is possible to create LCL classes at runtime but doing so manually. For instance, for TS it is not possible in his current situation to make use of f.e. the .lfm file (Lazarus ForM).(though in practice you can stream the lfm manually if you want to do so).

See also lazbuild wiki and file extensions wiki
« Last Edit: October 22, 2024, 04:45:04 pm by TRon »
Today is tomorrow's yesterday.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4715
  • I like bugs.
Re: TMainMenu not showing
« Reply #9 on: October 22, 2024, 04:47:43 pm »
Hello Juha, so if I use LazBuild I do not have to worry about any dependencies? LazBuild will pull in everything that is needed?
As explained by TRon, you need a Lazarus project.
A dependency for LCL package there is enough. LazBuild takes care of the rest.

TS provided a fpc.cfg which kinda removes the requirement to mention it.
I tried this:
Code: [Select]
$ fpc test_WSLCL.pas
Free Pascal Compiler version 3.2.2 [2024/05/01] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling test_WSLCL.pas
Compiling WSLCL.pas
WSLCL.pas(8,17) Fatal: Can't find unit Interfaces used by WSLCL
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
I confess I very seldom run fpc directly. I use Lazarus IDE and LazBuild as a middleman.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TMainMenu not showing
« Reply #10 on: October 22, 2024, 05:31:15 pm »
I tried this:
...

That is why TS provided his fpc.cfg.

If FPC is not configured to locate the LCL then it can't find it unless the paths are manually provided, e.g. relevant part:
Code: [Select]
-Fu/usr/share/lazarus/3.6.0/lcl/units/$fpctarget
-Fu/usr/share/lazarus/3.6.0/lcl/units/$fpctarget/*
-Fu/usr/share/lazarus/3.6.0/lcl/units/$fpctarget/gtk2
-Fu/usr/share/lazarus/3.6.0/components/lazutils/lib/$fpctarget
can be provided on the commandline:
Code: Bash  [Select][+][-]
  1. fpc -B -Fu/usr/share/lazarus/3.6.0/lcl/units/$fpctarget -Fu/usr/share/lazarus/3.6.0/lcl/units/$fpctarget/gtk2 -Fu/usr/share/lazarus/3.6.0/components/lazutils/lib/$fpctarget test_WSLCL.pas
Although when provided on the command-line and most probably depending on the used shell/terminal the dollar sign should be escaped properly.

Personally I use an additional fpc.cfg file (that has these LCL paths declared) that is included in the main fpc.cfg file when a specific define is present to indicate that I want to use FPC to compile something that depends on the LCL so that I can do something like:
Code: Bash  [Select][+][-]
  1. fpc -B -d"THIS_PROGRAM_REQUIRES_LCL" test_WSLCL.pas
Today is tomorrow's yesterday.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4715
  • I like bugs.
Re: TMainMenu not showing
« Reply #11 on: October 23, 2024, 01:39:32 am »
That is why TS provided his fpc.cfg.
I forgot to mention that fpc.cfg is there in the current directory after I extracted the test.zip.
But yes, I must adjust the paths to match my system. I will test more later.
« Last Edit: October 23, 2024, 02:13:13 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TMainMenu not showing
« Reply #12 on: October 23, 2024, 04:00:13 am »
@JuhaManninen:
Indeed the paths must be adjusted to match the individual user's setup (could be done in a more configurable/maintainable manner if wanted).

When that is 'fixed' then make sure to use something like:
Code: Bash  [Select][+][-]
  1. fpc -n @fpc.cfg -B test_WSLCL.pas
in order to override any default (system wide) fpc.cfg file.

Note that I am not sure if it is required to provide the full path to the fpc.cfg file (e.g. something that I do myself).

There could be more potential issues with the fpc.cfg as provided by TS (I did not have such a detailed look at it as I used my own fpc.cfg in order to compile TS' project)
Today is tomorrow's yesterday.

 

TinyPortal © 2005-2018