Recent

Author Topic: Juggling Multiple Lazarus Projects  (Read 2692 times)

Aruna

  • Full Member
  • ***
  • Posts: 119
Juggling Multiple Lazarus Projects
« on: December 03, 2022, 11:18:53 pm »
I have multiple Lazarus projects. Let's say we have 4 separate projects.
For example:

Proj1.lpi
Proj2.lpi
Proj3.lpi
Proj4.lpi

I have 3 buttons in the main form of Proj1 that when clicked I want:

Button1 clicked should  invoke Proj2.lpi .
Button2 clicked should invoke Proj3.lpi .
Button3 clicked should invoke Proj4.lpi .

Can this be done?

Thank you.

Aruna

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Juggling Multiple Lazarus Projects
« Reply #1 on: December 03, 2022, 11:31:43 pm »
Yes, its possible. But its also possible to ride a push bike across the Simpson Desert, I would not want to either !

Seriously, its reasonable to include units from other projects if you are very careful about what you do, including a project would be quite awkard.

I prefer to make a copy of an existing unit from an "other" project - make a note at the top where it came from and try not to change it too much. using ifdefs works -
Code: Pascal  [Select][+][-]
  1. {$ifdef PROJ1}
  2. ....
And the unix diff or sdiff -bs commands will easily show you the differences between two versions of the same unit.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Juggling Multiple Lazarus Projects
« Reply #2 on: December 03, 2022, 11:47:31 pm »
(Sorry, short answer / but I don't know what exactly you ask)

Invoke as in create a TProcess?

The forum has tips on how to run an external exe/process. Any of your Projects (once compiled) is an exe, and you can launch that exe (if your Proj1 knows were those exe are)

If you meant reusing the code, and compile all in on => create packages for the shared code.


On a side note, if you develop in several projects like this (potentially changing the open project often), install the ProjectGroups package into the IDE.

Aruna

  • Full Member
  • ***
  • Posts: 119
Re: Juggling Multiple Lazarus Projects
« Reply #3 on: December 03, 2022, 11:51:10 pm »
Yes, its possible. But its also possible to ride a push bike across the Simpson Desert, I would not want to either !

Seriously, its reasonable to include units from other projects if you are very careful about what you do, including a project would be quite awkard.

I prefer to make a copy of an existing unit from an "other" project - make a note at the top where it came from and try not to change it too much. using ifdefs works -
Code: Pascal  [Select][+][-]
  1. {$ifdef PROJ1}
  2. ....
And the unix diff or sdiff -bs commands will easily show you the differences between two versions of the same unit.

Davo
Sorry  I should have given more 'context' to the question. The "Testall" that you so painstakingly restructured and organized when I last checked gives me 85 folders containing fully working 'examples'. I was thinking of reading the filenames into a Tlistbox and having the end user choose the example he/she may be interested in. Instead of the TListbox I asked for buttons to make this simpler if that makes sense. So what would be the best way to write a wrapper around the 85 separate examples?

Ps: What would be wrong with riding a push bike? I am in the great white north so sadly do not have anything remotely like Simpson desert down under but I am told the current weather up in Edmonton two days back was -29 degrees celsius so riding a push bike will keep you warm? You could also keel over from frost bite if your not properly attired for the weather  :-\
« Last Edit: December 03, 2022, 11:58:18 pm by Aruna »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Juggling Multiple Lazarus Projects
« Reply #4 on: December 04, 2022, 12:01:50 am »
I don't follow that other thread, but first of all: Why not use the existing list inside the IDE?
Menu: Tools > Example Projects
?



But back to your question, still not clear what launch means....
If someone clicks you button, then your code knows the project as c:\lazarus\examples\foo\SomeBar.lpi

That file isn't executable.
Do you want to:
1) Open it in an IDE?
2) Compile it, and run the created exe?

In either case you need to look at TProcess (TUtf8Process) or alternatives (IIRC .... there is some routine to "launch" - as in start the associated exe, if the OS supports that....)

1) you launch lazarus.exe as new process, and give the lpi as argument.
It depends on how the user did configure their IDE. It either opens the project in a running IDE, or it opens a new IDE.

2) you first launch lazbuild to build the project.
I don't know if you can specify the name for the final exe, or if you need other means to find that exe.
Then you run the exe.

Aruna

  • Full Member
  • ***
  • Posts: 119
Re: Juggling Multiple Lazarus Projects
« Reply #5 on: December 04, 2022, 12:07:24 am »
(Sorry, short answer / but I don't know what exactly you ask)
Please allow me to shed some light on the matter. We have a brand new examples directory put together by @dbannon which currently has 85 separate folders containing separate projects. I want to have a simple way to allow a end user to browse then select the example they want and run/execute it.

Invoke as in create a TProcess?
I prefer not to at this time Martin_fr usually TProcess will mean extra ram being used and if things go south I get smoked. Definitely will try what you suggested at a later  date just for my learning but right now uh-uh nope.

The forum has tips on how to run an external exe/process. Any of your Projects (once compiled) is an exe, and you can launch that exe (if your Proj1 knows were those exe are)
This is the other thing I am running Linux Debian and my executables are deb's  :-X

If you meant reusing the code, and compile all in on => create packages for the shared code.


On a side note, if you develop in several projects like this (potentially changing the open project often), install the ProjectGroups package into the IDE.
Thank you @Martin_fr I will definitely explore ProjectGroups.

Aruna

  • Full Member
  • ***
  • Posts: 119
Re: Juggling Multiple Lazarus Projects
« Reply #6 on: December 04, 2022, 12:40:14 am »
I don't follow that other thread, but first of all: Why not use the existing list inside the IDE?
Menu: Tools > Example Projects ?
Use it by all mean that is a fantastic piece of work. That being said take another look at it carefully. It does give you a list of available examples but you are unable to select immediately using the list. Try pressing Enter and see. 

You can double-click and it grabs the displayed example and opens it in the ide but again we have to run it by pressing F9 to see what it looks like.  More keystrokes again.

Or once you select the example you have to copy it to the work area then open it. All this is fine and I am really happy but just for my own sake I would like to be able to scroll up or down in that list and press Enter and I want a running instance of the example. Simple right? Scroll through the List press enter and boom running instance. ( or maybe not..) I am yet too new and insufficiently experienced to see if what I want to do is not feasible or is a waste of time. Still, I want to give it a go...


But back to your question, still not clear what launch means....
If someone clicks you button, then your code knows the project as c:\lazarus\examples\foo\SomeBar.lpi

That file isn't executable.
Do you want to:
1) Open it in an IDE?
2) Compile it, and run the created exe?

2)I want to compile it, and run please.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Juggling Multiple Lazarus Projects
« Reply #7 on: December 04, 2022, 03:01:18 am »
I don't follow that other thread, but first of all: Why not use the existing list inside the IDE?
Menu: Tools > Example Projects ?
Use it by all mean that is a fantastic piece of work. That being said take another look at it carefully. It does give you a list of available examples but you are unable to select immediately using the list. Try pressing Enter and see. 
Well, for me Enter works (though that is on Windows / not tested on Linux).
Of course, "Enter works" once I selected the listview. By default it is on the filter edit. It would be a nice extension, if e.g. the up/down keys would affect the selection in the list, even while the filter has focus.... And then consequently enter could be made to work.... But that is another story.

Yes well, if you just quickly want to run each example that is a different usecase.


Quote
2)I want to compile it, and run please.
Well since compilation, needs to know about packages used by each example the only way you have is to run (TProcess or similar)
   lazbuild demo.lpi
and then run the exe.

So when you click, you will have the time that compilation takes... Unless you have a batch job, and precompile them all.

However you need to find where the final exe was put by lazbuild, otherwise you want be able to run it.
Not sure how to do that best. Maybe read the lpi, and see if an output for the exe is defined?


dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Juggling Multiple Lazarus Projects
« Reply #8 on: December 04, 2022, 08:19:44 am »

I suspect key to what I think you want is in the function that is told to open a project after its chosen in the Example Window -

Code: [Select]
ide/main.pp:813:    function DoOpenProjectFile(AFileName: string;
You should add a parameter to that that tells it that after it has opened the project, it should compile and run it.


Alternatively, you could have a stand alone app that displays the list of examples (easily copied from existing exampleswindow code) and it would compile (using lazbuild) and run the resulting app (using, sorry, TProcess).

> .....which currently has 85 separate folders containing separate projects.

Please don't forget all the "other" example projects, there are many more in the Lazarus SRC tree associated with the relevant parts of Lazarus code. There are a touch over 200 from memory.

I cannot think of a practical way to do it otherwise. And, honestly, I don't see a need. In most cases, the value to the end user of the Examples is the chance to look at the code. yep, they might compile and run to ensure its the example they think it is but browsing across the code is the benefit.

> This is the other thing I am running Linux Debian and my executable are deb's

If you have executable debs, I'd be quite worried. But seriously, it does not matter about the executable format, Lazarus is cross platform. In all (supported) cases, Lazbuild makes an appropriate binary as determined from the project file. By default, Lazbuild uses the "default" mode. So, you would need to check all 200 metadata files and maybe add a mention of the correct project mode to use ensuring cross platform.

> Ps: What would be wrong with riding a push bike?
Nothing, but don't expect to see me riding one across the Simpson. https://www.traveller.com.au/dune-busters-crossing-the-simpson-desert-go0wjx and it will be over 45 degrees tomorrow.

> current weather up in Edmonton two days back was -29 degrees celsius so riding a push bike will keep you warm
No, if its -29 outside, they should be waiting for the rescue team to arrive and take them away from such a terrible place.

 :D

Davo




Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Juggling Multiple Lazarus Projects
« Reply #9 on: December 04, 2022, 09:19:29 am »
I suspect key to what I think you want is in the function that is told to open a project after its chosen in the Example Window -
Code: [Select]
ide/main.pp:813:    function DoOpenProjectFile(AFileName: string;You should add a parameter to that that tells it that after it has opened the project, it should compile and run it.
No need for a new parameter. The IDE interface already has functions DoRunProject and DoRunProjectWithoutDebug.
There can be an option for ExampleWindow to run a project right after opening it.

Quote
In most cases, the value to the end user of the Examples is the chance to look at the code. yep, they might compile and run to ensure its the example they think it is but browsing across the code is the benefit.
Yes, the request sounds unusual. Usually people want to look at an example project's forms and/or code for a while before running it. Also, pressing F9 is a rather small task.
Still, if somebody wants such an option, it makes no harm to others.

I opened the Example Projects window after a long pause.
The list is empty. :(
The option "Directory where Examples go" is : /home/juha/.lazarus/examples_work_dir/
which is correct.
That directory is empty but the projects under Lazarus source examples/ directory should be shown.
I have the latest Git main branch on a Manjaro Linux and start Lazarus as "./lazarus &" from the source dir which is ~/SW/lazarus.
I remember having the same problem in the early tests a long time ago. I don't remember how it was solved. Maybe I had to change the code somehow.

[Edit] Oops, actually it works with a clean Lazarus configuration, like "./lazarus --pcp=~/.lazarus_test &".
The default config is old and must be corrupt somehow.
I must delete it and tweak the settings again. I will lose file and project history and some settings but it is OK.

[Edit2] No, the example list becomes empty right after opening any project, eg. lazarus.lpi or one of the examples.
To reproduce on a Linux system :
1. Start Lazarus with a clean configuration, either by --pcp= parameter or by deleting the default config directory (~/.lazarus).
2. Open the Tools -> Example Projects window. The list is filled.
3. Close the Example Projects window. Open ide/lazarus.lpi.
4. Open the Example Projects window again. The list is empty.

An alternative step 3.: Open one of the example projects from the window. It opens OK.
Then continue with step 4.

This is annoying. Project settings should not affect the Example Projects window anyhow.
How is it possible that nobody has noticed this?
« Last Edit: December 04, 2022, 10:45:19 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Juggling Multiple Lazarus Projects
« Reply #10 on: December 04, 2022, 10:52:21 am »
No need for a new parameter. The IDE interface already has functions DoRunProject and DoRunProjectWithoutDebug.
There can be an option for ExampleWindow to run a project right after opening it.
Ah, I did not look through the code, just grepped for the call its using now.

I opened the Example Projects window after a long pause. The list is empty. :(
.......
The default config is old and must be corrupt somehow.
I must delete it and tweak the settings again. I will lose file and project history and some settings but it is OK.
Hmm, thats surprising, it generates its list of examples at each startup, does not cache that content in PCP. 

We do keep projects the user has opened there and there is a single setting, where to keep that stuff, in the Lazarus Settings. Nothing I can think of thats likely to upset indexing the projects. But we do scan through PCP looking for potential Examples that are there, eg, OPM. If there was an invalid metadata file, it should report it to console and continue on.

If you have saved that PCP, can you see if there are any metadata files in there please ?  *.ex-meta

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Juggling Multiple Lazarus Projects
« Reply #11 on: December 04, 2022, 12:09:25 pm »
I guess when I would want to do such project, I would invent my own little scripts that be loaded at runtime into my app, txt/xml/json/whatever....

So I would have a prepared ListView (one visible column for a mini project description and invisible columns for filepath and parameter switches)
That data comes from the "script" file.

When clicking on of the entries, a bigger description of project appear on a memo/richtext/whatever type of control to display text.
That data comes from the "script" file.

Optional have some TImage display snapshot of GUI showing the used control.
That data comes from the "script" file.

Offering a "Run" and a "Show" button, run would compile and run the actual .lpi/.lpr file and show would open project in IDE.
That data comes from the "script" file.

An example for a script could be looking like this (.ini file exemplary since its usage is enorm simple for everyone)
Code: Pascal  [Select][+][-]
  1. [project]
  2. MainFile=project1.lpi                <- what is project main file to use
  3. Parameter=                             <- special compiler parameter needed to compile project
  4. Description=TButton handling   <- small description about what this project cover
  5. LongDescription=project1.txt    <- long text file for the description
  6. BuildPath=                              <- a folder that be created for binary
  7. SnapShots=image1.png           <- a comma seperated list of path+image filename, for basepath no path is needed to add
  8.  
Having such kind of file in each directory for all projects helps you to create an automated way of doing if you understand my meaning.

So you just need to crawl thru all folders, find the script file and store data in your app to be used at runtime.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Juggling Multiple Lazarus Projects
« Reply #12 on: December 04, 2022, 12:36:42 pm »
We really need to get you using -main KodeZwerg !

I guess when I would want to do such project, I would invent my own little scripts that be loaded at runtime into my app, txt/xml/json/whatever....
I called them example metadata files, <projectname>.ex-meta, json !

So I would have a prepared ListView (one visible column for a mini project description and invisible columns for filepath and parameter switches)
Image attached !

Optional have some TImage display snapshot of GUI showing the used control.
We forgo the images now because of the size issues but its possibly an online system might develope in the future.

Offering a "Run" and a "Show" button, run would compile and run the actual .lpi/.lpr file and show would open project in IDE.
We "copy to Work Area" (because in some *nix installs, the main copy of the Examples is in read-only space). The IDE then opens automatically and displays the project. The user can, if they choose, press the Run button. Its pressing that Run button Aruna wants to avoid.

An example for a script could be looking like this (.ini file exemplary since its usage is enorm simple for everyone) .....
Pretty close, we also have Keywords and Categories to make searching easy. See attached image.

 :D

Davo

EDIT: But again, we are off topic, this is about juggling multiple Lazarus installs ...
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Aruna

  • Full Member
  • ***
  • Posts: 119
Re: Juggling Multiple Lazarus Projects
« Reply #13 on: December 04, 2022, 01:57:59 pm »
Well, for me Enter works (though that is on Windows / not tested on Linux).
This is easily fixed with ListBox1KeyUp or ListBox1KeyDown and checking for #13.

Of course, "Enter works" once I selected the listview. By default it is on the filter edit. It would be a nice extension, if e.g. the up/down keys would affect the selection in the list, even while the filter has focus.... And then consequently enter could be made to work.... But that is another story.
If I remember right the TListBox has a built-in search functionality? I was actually wondering why David used a separate search text box? The way it is right now when searching the results are displayed only after you have typed in what your are searching for and then pressed the enter key. Until you press the enter key no possible matches/results are shown/updated. If we use the built-in functionality that comes with the TListbox when searching the results are updated instantly. Anyway, this is not a big issue I am just sharing what I found when I was testing. I am sure there must have been a very good reason he did things the way they are now. Then again this behaviour could be happening just on my Linux system?

Yes well, if you just quickly want to run each example that is a different usecase.
Yes there is a reason why I want to do this. I will get to that in my reply to what Juha has said in this thread. Have patience and have faith.

Well since compilation, needs to know about packages used by each example the only way you have is to run (TProcess or similar)
lazbuild demo.lpi and then run the exe.

So when you click, you will have the time that compilation takes... Unless you have a batch job, and precompile them all.

However you need to find where the final exe was put by lazbuild, otherwise you want be able to run it.
Not sure how to do that best. Maybe read the lpi, and see if an output for the exe is defined?
True and fair enough...

Aruna

  • Full Member
  • ***
  • Posts: 119
Re: Juggling Multiple Lazarus Projects
« Reply #14 on: December 04, 2022, 02:22:49 pm »
Alternatively, you could have a stand alone app that displays the list of examples (easily copied from existing exampleswindow code) and it would compile (using lazbuild) and run the resulting app (using, sorry, TProcess).
This is what I was also thinking. Aargh.. TProcess  eh? Oh well if there is no other way so be it  :-\

> .....which currently has 85 separate folders containing separate projects.

Please don't forget all the "other" example projects, there are many more in the Lazarus SRC tree associated with the relevant parts of Lazarus code. There are a touch over 200 from memory.
Oh dear I totally missed the other examples. Thank you for reminding me.

I cannot think of a practical way to do it otherwise. And, honestly, I don't see a need. In most cases, the value to the end user of the Examples is the chance to look at the code. yep, they might compile and run to ensure its the example they think it is but browsing across the code is the benefit.
Agreed 100% but there is a corner case which to me is rather important because 'I' had to go through that pain and grief and if I am able to do something that will make life easier for someone else and ensure they do not have to go through the same pain and grief, why not? Again this is just my own thoughts and opinion I am not asking/requesting changes or new implementations in the code. Things are fine the way they are.


Ps: What would be wrong with riding a push bike?
Nothing, but don't expect to see me riding one across the Simpson. https://www.traveller.com.au/dune-busters-crossing-the-simpson-desert-go0wjx and it will be over 45 degrees tomorrow.
Sweet Jesus, 45 degrees celsius?

> current weather up in Edmonton two days back was -29 degrees celsius so riding a push bike will keep you warm
Nothing, but don't expect to see me riding one across the Simpson. https://www.traveller.com.au/dune-busters-crossing-the-No, if its -29 outside, they should be waiting for the rescue team to arrive and take them away from such a terrible place.
You get used to it after a while. I have a friend he works at the Air base at Cambridge Bay way up north in Nunavut try Googling current weather Cambridge Bay, Nunavut. Actually let me just give you a screenshot and my apologies to everyone this is quite unrelated to coding or anything Pascal related but may make you appreciate the warmer weather you all may have  :)

 :D
« Last Edit: December 04, 2022, 02:24:30 pm by Aruna »

 

TinyPortal © 2005-2018