Sign in Join

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

Mailing lists / lazarus / 2015-06

Different packages for different usage

21 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

aradeonas

Hi,

I made package including some units that some of them need LCL but some of them will be need in server tools and they should not use LCL or graphical stuff so I want to make 2 package one for client app and other one for server with some of tools and without any dependency on graphical stuff so for server apps I will add server package. But I have units share with these two package that used TPicture in some parts but they can be removed with compiler condition.

I want to know what is the best way to declare these two package and compiler condition so I will have two package with shared units but for different usage case.

Regards, Ara

http://www.fastmail.com - Faster than the air-speed velocity of an unladen european swallow -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150618/3a9c9b56/attachment-0001.html>

Reply by email

Sven Barth
to aradeonas: I made package including some units that some of them need LCL but some of them will be…
aradeonas wrote 11 lines
Hi, I made package including some units that some of them need LCL but some of them will be need in server tools and they should not use LCL or graphical stuff so I want to make 2 package one for client app and other one for server with some of tools and without any dependency on graphical stuff so for server apps I will add server package. But I have units share with these two package that used TPicture in some parts but they can be removed with compiler condition. I want to know what is the best way to declare these two package and compiler condition so I will have two package with shared units but for different usage case.

In my opinion the best approach would be to put the shared units into their own package and have the code of those units /really/ be shared. This means no compiler defines that influence its behavior. And then the server and the client package depend on that package.

Regards,
Sven

Reply by email

aradeonas
to Sven Barth

Thanks but I cant understand you.
Problem is for example I have a class that will used for server and client but in client it will do some works with TPicture and in server there is no need for these functions and property and without them also class will work but I dont know how separate them so just changing a package do the job.

Regards,
Ara

http://www.fastmail.com - Accessible with your email software or over the web

Reply by email

Sven Barth
to aradeonas
"aradeonas" wrote 7 lines
Thanks but I cant understand you. Problem is for example I have a class that will used for server and client but in client it will do some works with TPicture and in server there is no need for these functions and property and without them also class will work but I dont know how separate them so just changing a package do the job.

In that case you should use inheritance. Have a class which does the common part which resides in a shared package. The client package then has a class that extends that shared class with the TPicture related functionality.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150619/e9bdb5b3/attachment.html>

Reply by email

aradeonas
to Sven Barth

Yes I done something like this but didn't like it so much because I dont want to have different class naming,Im looking for a way that just changing some parameter or condition with package do the job.

Regards, Ara

http://www.fastmail.com - Access all of your messages and folders wherever you are -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150619/5c67aa9f/attachment.html>

Reply by email

Graeme Geldenhuys
to aradeonas: I made package including some units that some of them need LCL but some of them will be…
aradeonas wrote
units share with these two package that used TPicture in some parts but they can be removed with compiler condition.

And it still boggles the mind why TPicture (essentially graphic handling) must pull in the whole LCL or VCL. Free Pascal's FCL-Image doesn't require the VCL or LCL, so why must TPicture.

I had a similar issue with code I had to work on a year or two ago.

Anyway, back to the point at hand... From what I understand Project Options can now set values on packages too. How exactly this is done, I don't know. Maybe the wiki could help. This should mean that if you set a compiler define in your project, that compiler define could be applied to dependency packages too. So your Client app could have the define, and the Server app doesn't. The code in your package then uses simple IFDEF's to block out some parts of the code.

I have so many issues with Lazarus Packages these days - I recommend you scrap them completely and simply use IDE Macros. Build settings, Compiler Defines etc are much much easier to handle then. Each project has there own settings and is applied to all the source code involved.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

aradeonas
to Graeme Geldenhuys

Aha! That what I mean,you explained it better than me ;)

About Compiler Defines,until now I couldn't make them work,I don't know why! can you show me an simple example?
This project going to be big and I want just changing package from client to server change dependencies and allow me to run app in a non graphical OS.

Regards,
Ara

http://www.fastmail.com - Send your email first class

Reply by email

Mattias Gaertner
to aradeonas
Aha! That what I mean,you explained it better than me ;) About Compiler Defines,until now I couldn't make them work,I don't know why! can you show me an simple example?

In Project Options / Compiler Options / Additions and Overrides:

http://wiki.lazarus.freepascal.org/IDE_Window:_Compiler_Options#Add_a_flag_to_project_and_all_packages

In code you can then use:
{$IFDEF SomeFlag}
{$ELSE}
{$ENDIF}
This project going to be big and I want just changing package from client to server change dependencies and allow me to run app in a non graphical OS.

Mattias

Reply by email

Juha Manninen
to Graeme Geldenhuys: And it still boggles the mind why TPicture (essentially graphic handling) must pull in…
Graeme Geldenhuys wrote
From what I understand Project Options can now set values on packages too. How exactly this is done, I don't know.

That is the "Additions and Overrides" you have just discovered. Just put your custom define there and it affects all dependent packages.

"Additions and Overrides" is versatile but also complex. The is confusing partly because of the complexity but I think it could be simplified.
I have added a separate entry for setting LCLWidgetType because many people did not find it and were asking.
Good ideas for the GUI are welcome, for example as mockups.

Juha

Reply by email

aradeonas
to Juha Manninen

Beautiful! Thank you Graeme and Mattias and also Juha.

So summery is when I have 2 package named clientpkg and serverpkg with shared unit but fist one with graphical dependencies so when I make an server app I should declare for example -ThisIsServer and for client nothing and in code use compiler condition so when ThisIsServer declared I exclude graphical code.

Correct and this is the best way?

Also I want to ask how can I find out my app is running in non graphical OS?with compiler condition?

Regards,
Ara

http://www.fastmail.com - The way an email service should be

Reply by email

Graeme Geldenhuys
to aradeonas: Aha! That what I mean,you explained it better than me ;) About Compiler Defines,until now…
aradeonas wrote
About Compiler Defines,until now I couldn't make them work,I don't know why! can you show me an simple example?

Attached is an example which has common code (with IFDEF's), a console Server app (non GUI), and a Client (gui) app.

Notes:
- In both the Client and Server apps there is a IDE Macro in "Project Options / Compiler Options / Additions and Overrides" that defines the location of the common code. Change that to match your location. I normally set this to the root of my project directory.
- In the Client app it defines a "ClientApp" compiler define in "Project Options / Compiler Options / Other". The server app doesn't have this, and that is what allows you to separate the dependencies in the common code.

No Lazarus Packages are used, other than the LCL.lpk for the client app.

Save the attachment and remove the extra extension '.RemoveMe', then unpack as normal. The extra file extension is added to circumvent stupid attachment rules in some email servers.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ -------------- next part -------------- A non-text attachment was scrubbed... Name: exampl.tar.gz.RemoveMe Type: application/octet-stream Size: 2439 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150619/32b218e4/attachment.obj>

Reply by email

Mattias Gaertner
to aradeonas: Beautiful! Thank you Graeme and Mattias and also Juha. So summery is when I have 2…
Show quoted text 7 lines
Beautiful! Thank you Graeme and Mattias and also Juha. So summery is when I have 2 package named clientpkg and serverpkg with shared unit but fist one with graphical dependencies so when I make an server app I should declare for example -ThisIsServer and for client nothing and in code use compiler condition so when ThisIsServer declared I exclude graphical code.

Yes, pass -dThisIsServer to the compiler.

Correct and this is the best way?

Depends. Some people don't like scattering their code with IFDEFs. Sven gave you an alternative with abstract classes.

Also I want to ask how can I find out my app is running in non graphical OS?with compiler condition?

The compiler run *before* the application is running. So, no there is no compiler condition.
Please define what you mean with "is running in non graphical OS".

Mattias

Reply by email

aradeonas
to Mattias Gaertner
The compiler run **before* *the application is running

Agree,silly question!

Please define what you mean with "is running in non graphical OS".

I have a simple vps with red hat os on it with only terminal so if I want to run any app that need LCL it will crash ,so all my server apps should not depend on graphical package and then it will run smoothly.

Regards, Ara

http://www.fastmail.com - A fast, anti-spam email service. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150619/5798d0ba/attachment.html>

Reply by email

Mattias Gaertner
to aradeonas: Thank you very much Graeme. So 'Custom options' work like 'Additions and Overrides' but…
Thank you very much Graeme. So 'Custom options' work like 'Additions and Overrides' but second one is more specific?

"Custom options" is a plain field, simply passed to the compiler. Mostly used for uncommon options that have no GUI element in the IDE.

Additions and Overrides is for complex projects with many targets and flags (e.g. release/debug, Windows/Linux, experiments, many developers).
The later allows to enable/disable flags with simple mouse clicks.

Mattias

Reply by email

aradeonas
to Mattias Gaertner
Show quoted text 7 lines
"Custom options" is a plain field, simply passed to the compiler. Mostly used for uncommon options that have no GUI element in the IDE. Additions and Overrides is for complex projects with many targets and flags (e.g. release/debug, Windows/Linux, experiments, many developers). The later allows to enable/disable flags with simple mouse clicks.

Understood,thank you.

Ara

http://www.fastmail.com - Faster than the air-speed velocity of an unladen european swallow -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150619/91a4fe1d/attachment.html>

Reply by email

Graeme Geldenhuys
to aradeonas: Thank you very much Graeme. So 'Custom options' work like 'Additions and Overrides' but…
aradeonas wrote
So 'Custom options' work like 'Additions and Overrides' but second one is more specific?

I believe Mattias said it all. As far as I understand "Additions and Overrides" pass settings on to packages too. The "Custom Options" allows you to add any compiler settings, and only apply them to the specific project (not passed on to package dependencies).

In the example I attached I didn't use packages, so the difference is probably moot.

TIP:
Created a new project, set your most often used IDE Macros (eg: tiopf:=/data/devel/tiopf/), then tick the "Set compiler options as default" and click OK. Now wherever you create a new project, your most used IDE Macros are already defined. Every little bit helps save time. ;-)

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

aradeonas
to Graeme Geldenhuys
TIP:

Created a new project, set your most often used IDE Macros (eg: tiopf:=/data/devel/tiopf/), then tick the "Set compiler options as default" and click OK. Now wherever you create a new project, your most used IDE Macros are already defined. Every little bit helps save time. ;-)

Thank you Graeme, you helped me as always.

Regards, Ara

http://www.fastmail.com - The way an email service should be -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150619/9d7c7bf6/attachment-0001.html>

Reply by email

Mattias Gaertner
to Graeme Geldenhuys: I believe Mattias said it all. As far as I understand "Additions and Overrides" pass…
Show quoted text 6 lines
On 2015-06-19 12:09, aradeonas wrote: > So 'Custom options' work like 'Additions and Overrides' but second one > is more specific? I believe Mattias said it all. As far as I understand "Additions and Overrides" pass settings on to packages too.

It allows any combination. Only project, only packages, only one packages, all packages except one, etc ...

Show quoted text 12 lines
The "Custom Options" allows you to add any compiler settings, and only apply them to the specific project (not passed on to package dependencies). In the example I attached I didn't use packages, so the difference is probably moot. TIP: Created a new project, set your most often used IDE Macros (eg: tiopf:=/data/devel/tiopf/), then tick the "Set compiler options as default" and click OK. Now wherever you create a new project, your most used IDE Macros are already defined. Every little bit helps save time. ;-)

Note: The "tiopf:=/data/devel/tiopf/" is an absolute path, so when you give your projects to another developer, he has to change this macro in every project and every time you give him a new copy.

As alternative you can use "Addition and Overrides" to add the macro to all your projects. The other developer only needs to do this once as well.

Mattias

Reply by email

Graeme Geldenhuys
to Mattias Gaertner
Mattias Gaertner wrote
Note: The "tiopf:=/data/devel/tiopf/" is an absolute path, so when you give your projects to another developer, he has to change this macro in every project and every time you give him a new copy.

Yes I know it is an absolute path - as defined for my system. They don't however need to modify it every time they get a new copy (eg: from a code repository). They could override it via the "Stored in session only *.lps" section. So they can do a 'svn up' without loosing there customisations.

As alternative you can use "Addition and Overrides" to add the macro to all your projects. The other developer only needs to do this once as well.

Probably even better. Thanks for that info.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email