Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-03

Adding units to a project

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Antonio Sanguigni

Hi all,

I know I'm lost in a glass of water but I cannot be able to use some units. I'm building a new lazarus project and I would like to re-use other units in my file system. So I added them to this new project with Project inspector - Add - Add Files - Add file to packages and this operation add the units on .lpr files of project and that's fine. Now, I need to use this added unit also in other unit's use clause of the project but Lazarus complains that it cannot find it when I try to build it.

Adding requirements of .lpk files is fine and works smooth.

My question is: Do I need to create a package to use that units or I'm missing something ?

Thanks
Antonio

Antonio Sanguigni alias slapshot ---------------------------------------------------------------------- GioveLUG (Linux User Group) - http://www.giovelug.org Edupup (Educational distro) - http://www.pieroni.biz/edupup

Reply by email

Graeme Geldenhuys
to Antonio Sanguigni
Antonio Sanguigni wrote
My question is: Do I need to create a package to use that units or I'm missing something ?

This is the recommended method if you share units between projects. It just works much easier.

If you normally add a unit which lives in a different directory than other units, Lazarus normally prompts you to add that new path to the unit search path. Did you get any such prompt?

Anyway, creating a package with shared units between projects is a much better idea. I use it all the time.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

David W Noon
to Antonio Sanguigni: I know I'm lost in a glass of water but I cannot be able to use some units. I'm building…
Antonio Sanguigni wrote 13 lines
I know I'm lost in a glass of water but I cannot be able to use some units. I'm building a new lazarus project and I would like to re-use other units in my file system. So I added them to this new project with Project inspector - Add - Add Files - Add file to packages and this operation add the units on .lpr files of project and that's fine. Now, I need to use this added unit also in other unit's use clause of the project but Lazarus complains that it cannot find it when I try to build it. Adding requirements of .lpk files is fine and works smooth. My question is: Do I need to create a package to use that units or I'm missing something ?

The way I approach reusing common code is to have my common units in local directories:

~/units -- for code that is not yet considered stable /usr/local/units -- for code that is considered stable

The first of these is added with a -Fu option in my ~/.fpc.cfg file, and the second is added with a -Fu option in my /etc/fpc.cfg file. These directories can also be added to your Lazarus compilation options.

Whenever I need to incorporate a unit I simply add its name to the "uses" clause of the unit that needs to invoke code from the shared unit. Lazarus seems to find the code when tracing, so it all just seems to work.

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================

Reply by email

Antonio Sanguigni
to Graeme Geldenhuys: This is the recommended method if you share units between projects. It just works much…

2009/3/4 Graeme Geldenhuys :

If you normally add a unit which lives in a different directory than other units, Lazarus normally prompts you to add that new path to the unit search path. Did you get any such prompt?

I did not have this prompt ! Weird :O.

Anyway, creating a package with shared units between projects is a much better idea. I use it all the time.

Yes, Lazarus packages are really powerful tool

Antonio

Antonio Sanguigni alias slapshot ---------------------------------------------------------------------- GioveLUG (Linux User Group) - http://www.giovelug.org Edupup (Educational distro) - http://www.pieroni.biz/edupup

Reply by email

Antonio Sanguigni
to David W Noon: The way I approach reusing common code is to have my common units in local directories:…

2009/3/4 David W Noon :

Show quoted text 14 lines
The way I approach reusing common code is to have my common units in local directories: ? ~/units ? ? ? ? ? -- for code that is not yet considered stable ? /usr/local/units ?-- for code that is considered stable The first of these is added with a -Fu option in my ~/.fpc.cfg file, and the second is added with a -Fu option in my /etc/fpc.cfg file. These directories can also be added to your Lazarus compilation options. Whenever I need to incorporate a unit I simply add its name to the "uses" clause of the unit that needs to invoke code from the shared unit. Lazarus seems to find the code when tracing, so it all just seems to work.

Cool, I will try also this method, too.

Antonio

Antonio Sanguigni alias slapshot ---------------------------------------------------------------------- GioveLUG (Linux User Group) - http://www.giovelug.org Edupup (Educational distro) - http://www.pieroni.biz/edupup

Reply by email

Antonio Sanguigni
to Graeme Geldenhuys: This is the recommended method if you share units between projects. It just works much…
Show quoted text 15 lines
> My question is: Do I need to create a package to use that units or I'm > missing something ? This is the recommended method if you share units between projects. It just works much easier. If you normally add a unit which lives in a different directory than other units, Lazarus normally prompts you to add that new path to the unit search path. Did you get any such prompt? Anyway, creating a package with shared units between projects is a much better idea. I use it all the time.

Graeme, I'm trying to follow your suggest but I'm getting some troubles that I will explain in a few.
Well, I have 5-6 units that are my BOM and with my test projects it seems to work well. Now I started a new Lazarus project to build a presentation layer for this BOM I'm using. I created as you said a new package and added it to my new project inspector as requirements and it seems to find that units.

But now I have another issue I cannot understand, I mean that units of my BOM cannot find tiOPF units, even if I added tiOPF package into this new project. Of course, test project with tiOPF package added worked fine.

I hope I was clear.

Thanks
Antonio

Antonio Sanguigni alias slapshot ---------------------------------------------------------------------- GioveLUG (Linux User Group) - http://www.giovelug.org Edupup (Educational distro) - http://www.pieroni.biz/edupup -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090311/b2a674d4/attachment.html

Reply by email

Graeme Geldenhuys
to Antonio Sanguigni

2009/3/11 Antonio Sanguigni :

But now I have another issue I cannot understand, I mean that units of my BOM cannot find tiOPF units, even if I added tiOPF package into this new project. Of course, test project with tiOPF package added worked fine.

I have no idea. Such cases work for me. Alternatively you can use the following source code directory layout. I use this layout in our current company project and it works perfectly as well.

<project>
docs <= global project documentation bin <= binary files get created here src <= contains common units like BOM sub_project1 <= contains .lpr file and project1 specific units sub_project2 <= contains .lpr file and project2 specific units sub_project3 <= contains .lpr file and project3 specific units resources <= any files like *.bmp, *.png etc. used in projects

Projects 'project1', 'project2' and 'project3' use the '../' Other Unit Path (-Fu) entry to find the common units in 'src' directory. Each project also has the 'tiopf' Required Package added to find any tiOPF specific units. Each project also generates it's executable in the 'bin' directory use the compiler option: -FE../../bin

I hope this alternative method help you if the packages option doesn't.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Vincent Snijders
to Antonio Sanguigni: Graeme, I'm trying to follow your suggest but I'm getting some troubles that I will…
Antonio Sanguigni wrote 27 lines
> My question is: Do I need to create a package to use that units or I'm > missing something ? This is the recommended method if you share units between projects. It just works much easier. If you normally add a unit which lives in a different directory than other units, Lazarus normally prompts you to add that new path to the unit search path. Did you get any such prompt? Anyway, creating a package with shared units between projects is a much better idea. I use it all the time. Graeme, I'm trying to follow your suggest but I'm getting some troubles that I will explain in a few. Well, I have 5-6 units that are my BOM and with my test projects it seems to work well. Now I started a new Lazarus project to build a presentation layer for this BOM I'm using. I created as you said a new package and added it to my new project inspector as requirements and it seems to find that units. But now I have another issue I cannot understand, I mean that units of my BOM cannot find tiOPF units, even if I added tiOPF package into this new project. Of course, test project with tiOPF package added worked fine.

The package with the BOM (Business object model?) should have a requirement to the tiOPF package too, not just the main program.

Vincent

Reply by email

Antonio Sanguigni
to Vincent Snijders
Show quoted text 19 lines
> Graeme, I'm trying to follow your suggest but I'm getting some troubles > that I will explain in a few. > Well, I have 5-6 units that are my BOM and with my test projects it > seems to work well. Now I started a new Lazarus project to build a > presentation layer for this BOM I'm using. I created as you said a new > package and added it to my new project inspector as requirements and it > seems to find that units. > > But now I have another issue I cannot understand, I mean that units of > my BOM cannot find tiOPF units, even if I added tiOPF package into this > new project. Of course, test project with tiOPF package added worked fine. > The package with the BOM (Business object model?) should have a requirement to the tiOPF package too, not just the main program.

Thanks both Graeme and Vincent. This one was my fault, Vincent. Now, I'm better understanding lazarus package and I must confess they are awesome, really powerful :).

I think I will stress you a bit from now ;)

Antonio

Antonio Sanguigni alias slapshot ---------------------------------------------------------------------- GioveLUG (Linux User Group) - http://www.giovelug.org Edupup (Educational distro) - http://www.pieroni.biz/edupup -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090312/ffb87e44/attachment.html

Reply by email

Graeme Geldenhuys
to Vincent Snijders: The package with the BOM (Business object model?) should have a requirement to the tiOPF…
Vincent Snijders wrote
The package with the BOM (Business object model?) should have a requirement to the tiOPF package too, not just the main program.

Ah yes, I forgot about that. :-(

Correct me if I am wrong, but doesn't that also mean that if the BOM is inside a package and has a requirement to tiOPF package, then your main program should only need to include the BOM package. The tiOPF package doesn't need to be added explicitly to the main program. Projects inherit dependencies from packages.

eg:
You only need to add the LCL dependency to a project and not LCL + FPC, because LCL package already includes the FCL package as a requirement.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Antonio Sanguigni
to Graeme Geldenhuys
Show quoted text 7 lines
Correct me if I am wrong, but doesn't that also mean that if the BOM is inside a package and has a requirement to tiOPF package, then your main program should only need to include the BOM package. The tiOPF package doesn't need to be added explicitly to the main program. Projects inherit dependencies from packages.

Yes Graeme, you are rigth. Into the porject inspector I erased tiOPF as required packages and it is compiling well, too.

Antonio

Antonio Sanguigni alias slapshot ---------------------------------------------------------------------- GioveLUG (Linux User Group) - http://www.giovelug.org Edupup (Educational distro) - http://www.pieroni.biz/edupup -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090312/8dedc232/attachment.html

Reply by email