[Lazarus] Strange dependency of units

Jürgen Hestermann juergen.hestermann at gmx.de
Mon Apr 2 17:51:10 CEST 2012


Martin schrieb:
 > Actually the basic concept of a unit is use it all or nothing.

This is not the concept of units but it seems to be a restriction of 
interfaces (as I now read a bit more about them). Units were introduced 
as libraries of functions and other declarations and that's the way I am 
using them. When I use SysUtils I also don't use all functions this unit 
implements. With smartlinking it should not even affect file size much. 
The unit concept was one of the main reasons for the success of the 
Borland compilers to overcome the splitting (and inconsistency) of 
interface (header files) and implementation (object files). Units are a 
merge of both and with the uses clause in them the compiler should be 
able to resolve all dependencies easily.


 >  So by using Grids, you should expect all the platform/GUI dependent 
stuff to end up in your application.

I am not even aware of all the platform/GUI dependent stuff. I just 
wanted to use TStringGrid types. Do I need to study the whole LCL in 
detail to write programs with Lazarus? It seems so.


 > And there are cases where smart-linking does not work. And you 
encountered one. Some of the methods, of some classes in Grids can not 
be smart linked (IIRC virtual/overridden class methods, maybe all 
virtual/overridden).

Smartlinking is not the issue here (because that only affects the size 
of the file) but it seems that the concept of virtual methods broke the 
mechanism of units.


 > For this cases the "NoGui" widgetset exists. It provides (or should 
provide) empty methods for this.

But how should I know that this is necessary? I used a simple unit in a 
console application. And the error messages gave no hint what is wrong.


 > In theory that could be changed (like a lot of thinks *could* be 
done). In practise this may never happen (if only due to time 
available...). A re-design that big could have a lot of other side 
effects (which probably could all be remedied). But the cost might just 
be to high. (Yet I guess, if someone wants to step forward....)

Ok, I know this now. The solution in my case will be that I create 2 
general purpose units: One for all programs and one for graphical 
programs only.


 > Originally a default implementation (a class wit abstract methods) 
did exist, so using grids, without interfaces would compile.
 > - If the code was not called: good
 > - If by some chance it was called (even totally unexpected): crash

Can the compiler no longer determine whether code will be executed or 
not? Then this is no longer Pascal. It sounds as if we are talking about 
C. All the pitfalls that existed in C now even creap into Pascal (at 
least it looks like this for me).





More information about the Lazarus mailing list