Forum > General

[SOLVED] Howto use a DEFINE present in an installed package

(1/5) > >>

tintinux:
Hi

I have installed the package ZeosLib in the EDI.
In my projects, I need to know and test the version installed, to make them more independent of the package version and avoid compatibility breaks.

In a source of the ZeosLib package (Zeos.inc) there is
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$DEFINE ZEOS80UP}which could help me if I could write in my projects

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$IF ZEOS80UP}// Code for 8.0{$ELSE}// Code for older version{$ENDIF}
Before, I have to add in my source

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$I  zeosfolder/Zeos.inc}

But, the exact root path of the package sources (zeosfolder) can change on every installation.
Is there not a way to know where are the source of the installed package, or a way to find them without adding a hard coded path in the options ?

Thanks for your suggestions.

[Of course, this is a general issue, not a ZeosLib issue]

MarkMLl:
I don't think you can. you can check for a {$define ... } in the same unit using {$ifdef ... } (where the define might actually be in a .inc file), but the best you can do across units is using {$if declared( ... ) } at compilation time, or a version-returning function at runtime.

MarkMLl

TRon:
You can set a specific include dir to search in in the project options.

Another suggestion might be to add the define to the compiler options in case it is sure that the version matches.

tintinux:

--- Quote from: TRon on November 25, 2024, 05:13:26 pm ---You can set a specific include dir to search in in the project options.

Another suggestion might be to add the define to the compiler options in case it is sure that the version matches.

--- End quote ---
No, this is what I would like to avoid : specific include directory or specific compiler option.
I wondered whether if the compiler could find the directory where the package sources have been downloaded, or the version of the package.
Thanks

MarkMLl:
The compiler doesn't /find/ anything, it needs to be told about paths either on the command line or in fpc.cfg.

In principle you can put a path in either a uses clause or in an include directive. However experience shows that this is risky: there is a problem that's never been made adequately reproducible either in FPC or possibly the Lazarus IDE whereby it doesn't notice that a unit has changed and refuses to recompile it.

I've also seen situations where if you pull in a single include file it insists on recompiling a whole lot of stuff that shouldn't be. That might be specific to some versions of the Lazarus IDE, or might be related to the above problem.

As far as I am aware, you can't specify the value of a define on the command line: it has to be there or not there.

So it boils down to the fact that either you have to use something like


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---(* This is an experimental replacement for the RTL's Now() based on the POSIX  clock.*)function posixNow(): TDateTime; var     ts: timespec;        days: extended; begin  result := UnixEpoch; (* This test appears to be unreliable for functions provided directly by the *)(* kernel or a standard system library.                                      *) {$if defined(clock_gettime) }  if clock_gettime(CLOCK_REALTIME, @ts) = 0 then begin    days := ts.tv_sec / SecsPerDay;    days += ts.tv_nsec / SecsPerDay / 10E9; (* Since even the extended type doesn't really have enough digits to express *)(* times relative to the unix epoch in nanoseconds, assume we have to be     *)(* very careful with the evaluation order.                                   *)     result := days + UnixDateDelta  end{$endif                     }end { posixNow } ; 
or you have to use an external tool to build a compiler/project configuration, plus possibly a .inc file containing macros of the various things you need.

MarkMLl

Navigation

[0] Message Index

[#] Next page

Go to full version