[Lazarus] Challenge of converting a Delphi project

Martin Schreiber fpmse at bluewin.ch
Thu May 6 10:03:42 CEST 2010


On Thursday 06 May 2010 02:45:35 Hans-Peter Diettrich wrote:

> In any case the
> encapsulation of class fields and methods is broken; this encapsulation
> was designed for an interface between the component library and
> application code, not for code transformation, GUI designers or other
> "low level" stuff.
>
I have this problem every day in development of MSEgui framework. Often there 
is need to access low level stuff in classes which are defined in other 
units.
I don't want to define the low level stuff public because it should not be 
used in application code.
I don't want to use a single unit for the whole framework because there are 
about 200'000 lines, I don't like include files, for the compiler it would be 
a single unit anyway.
And please don't suggest I should refactor the code in order to have no low 
level interactions between framework classes in different units. ;-)
It is simply not possible, especially in a framework which evolves over a long 
time and where it is too dangerous and expensive to change the architecture 
often for additions which where not foreseen at the beginning.

Because of this I supposed several times the introduction of the simple 
construct of "friend units" where protected class members are visible.
Nobody liked it :-( so MSEgui is full of code like:

"
uses
 classes,mseclasses,msegui;
type
 twidget1 = class(twidget);
 tcustomframe1 = class(tcustomframe);

[...]

 twidget1(thewidget).dosomething();
 tcustomframe1(frame).dosomeother();
"

With "friend units" it could be done for example like:
"
uses
 classes,mseclasses;
friends           //or any other more appropriate identifier
 msegui;

[...]

 thewidget.dosomething();
 frame.dosomeother();
"

Public framework class elements are intended to be used by application code, 
protected elements in "friend units" can be used too but need a deeper 
knowledge of the context and are normally accessible by the framework only, 
private elements are for encapsulation purpose.

Martin




More information about the Lazarus mailing list