[Lazarus] Strange dependency of units
Alberto Narduzzi
albertonarduzzi at yahoo.com
Mon Apr 2 21:52:19 CEST 2012
> Do I need to study the whole LCL in detail to write programs with Lazarus? It seems so.
no, you don't need indeed to study it all, but a little understanding
may help.
> 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.
the main issue is that you used code for the GUI (LCL) in a console
application. Then the IDE and the compiler couldn't have helped you better.
It is a good practice not to mix "specific" code; you may understand
that a function max(a: integer; b: integer) is a little different from
another like max(a: TSpinEdit; b: TSpinEdit)...
(I don't even know if the class names are correct; just in case, please
forgive me).
If you had done this (using IFDEFs I mean) correctly since the
beginning, you would probably never have faced the issue...
> > 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).
Again, as many have said already, it's time you become more familiar
with abstract classes.
This has nothing to do with C (good or bad) inheritance (in terms of
language design, not OO programming). Abstract classes behave like this.
Full stop. Either you implement them, or don't use them at all.
The fact that INTERFACES is needed is just to help you with an easy
"uses INTERFACES" instead of forcing you to write the whole
implementation for it.
And don't come back "nobody told me, neither the IDE or the compiler
did", because this leads to the INITIAL, MANDATORY, USE OF IFDES for
your code.
Cheers, A.
More information about the Lazarus
mailing list