0

I have a package which uses a certain library. In one of my projects I want to choose whether the package uses this library or not.

My first attempt was using a DEFINE at project level and then {$IFDEF } in the package, but apparently this only works (is defined) for the project itself, not for the package used. -> is this correct?

I could split up the package objects - one which uses the library and one which doesn't - but that isn't very practical if there are different combinations of libraries to choose from. -> would you have a better suggestion?

EDIT: I want the package to be "multi-platform', except for some functions which are VCL/win dependent

frank
  • 1
  • 3
  • The package decides which library it uses. Once it is compiled you cannot change it. Seems you are looking for something like a Plugin System. – Uwe Raabe Jun 04 '18 at 13:25
  • You'll likely need separate packages. Conditionals control what code is included at *compile* time, but once it's compiled, it's there for good. – Jerry Dodge Jun 04 '18 at 13:36
  • @JerryDodge I want to control it at "project-compile" time. there is not such a thing I suppose? – frank Jun 04 '18 at 13:43
  • As the package is not altered during project compile - no. – Uwe Raabe Jun 04 '18 at 13:44
  • @UweRaabe Plugin System, you mean like loading a DLL? I am hoping for something light... – frank Jun 04 '18 at 13:51
  • See here: https://stackoverflow.com/questions/38556892/how-to-make-a-single-component-support-both-vcl-and-fmx – Jerry Dodge Jun 04 '18 at 14:00
  • @JerryDodge I quite liked your original comment of creating a new package and sharing the files as it enabled me to keep the ifdef's. I'll see what is more appropriate: splitting the package or deriving as in your linked answer. it's amazing how things get entangled if it's not considered from the start... anyway, I'll accept your comments, thank you! – frank Jun 04 '18 at 15:02

1 Answers1

0

The compiled packages are never platform independent, they are always compiled for one specific platform.

But with compiler defines you can specify which code gets compiled, when you are compiling the package for a specific platform.

So when you’ve create the correct IFDEF statments, then compile the package for each platform (to different folders) and deploy the correct version for each platform you are deploying the main executable (for which you’ve also compiled different executables).

R. Hoek
  • 916
  • 8
  • 27
  • the problem is I can't control the DEFINE's from the projects – frank Jun 04 '18 at 15:00
  • But there's no need to do that, because defines are evaluated while the package is being compiled. But the most important think to remember, is you need to compile the package for each platform and therefor need to add the different target platforms to the package too. – R. Hoek Jun 04 '18 at 15:06
  • I want it to be evaluated when the project is compiled, but apparently the define-system doesn't reach that far... – frank Jun 04 '18 at 15:13
  • You're right, when you compile the 'project', the package is not 'recompiled' based on the platform you've selected for the main 'project'. But when you add the package above the project (in the projectgroup), you can compile them in the correct order by right clicking the project group and select 'Build all'. (NOTE: make sure you've selected the correct platform for the packages and the project first). – R. Hoek Jun 04 '18 at 15:18
  • yes, but there doesn't seem to be a way to 'disable' certain functions based on the current project. – frank Jun 04 '18 at 15:28
  • OK, so you mean you are looking for a way to make the available code not only available based on the platform (win32, win64, iOs, etc), but also dependent on the project which uses the package? – R. Hoek Jun 04 '18 at 15:30
  • yes, as I'm not interested in certain (platform-dependant) functions, but I do want it to compile ;-) – frank Jun 04 '18 at 15:39
  • Sorry, but this is not possible the easy way (using build from within the IDE). But you can add some project specific (function specific) defines and use the commandline compiler (dcc32) to build the packages and specificy the corresponding functional define to add. – R. Hoek Jun 04 '18 at 16:16
  • When you use defines to specify the functionality (units) you what compiled into the package, please also read this: https://stackoverflow.com/questions/8415549/how-to-make-package-dependencies-requirements-dependent-on-conditional-symbols?rq=1 – R. Hoek Jun 07 '18 at 07:24