[Lazarus] Is it meaningful or possible to change the visibility or the properties and events in a form or datamodule, ie make the private or protected?

Michael Van Canneyt michael at freepascal.org
Mon Apr 9 13:28:04 CEST 2012



On Mon, 9 Apr 2012, Frank Church wrote:

> On 23 March 2012 14:15,  <michael.vancanneyt at wisa.be> wrote:
>>
>>
>> On Fri, 23 Mar 2012, Michael Fuchs wrote:
>>
>>> Am 23.03.2012 14:55, schrieb Frank Church:
>>>>
>>>> [...]  I'd prefer to look only at the public section and say, Oh,
>>>> this is what it does for the program's other modules. Whatever isn't
>>>> there is not relevant to the rest of the application.
>>>>
>>>> I understand that it comes from a Delphi legacy as RAD tool dating
>>>> from a time when the principles underlying object orientation had not
>>>> properly sunk in. [...]
>>>
>>>
>>> You can already do this by changing the way you are programming. Just
>>> write a class which only publish the needed methods and properties to the
>>> outside.
>>> Don't let the Application create and control your forms, move this to your
>>> class. So, your class hides the forms, datampdules and other stuff.
>>
>>
>> That's what I do too.
>>
>> unit appforms;
>>
>> type
>>  TBaseMyForm = Class(TForm)
>>    // Define public interface
>>  end;
>>  TBaseMyFormClass = Class of TBaseMyForm;
>>
>> Var
>>  MyFormClass : TBaseMyFormClass = Nil
>>
>> And then somewhere:
>>
>>
>>
>> Type
>>  TForm = TBaseMyForm;
>>
>>  TMyForm = Class(TForm);
>>   // Regular lazarus definition of form
>>  end;
>>
>> initialization
>>  MyFormClass = TMyForm; end;
>>
>> And then, whenever I need an instance of TBaseMyForm:
>>
>> F:=MyFormClass.Create(Self);
>>
>> You could even substitute the complete TMyForm form with another one,
>> depending on
>> configuration options.
>>
>> Michael.
>>
>>
>> --
>> _______________________________________________
>> Lazarus mailing list
>> Lazarus at lists.lazarus.freepascal.org
>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
> Hi Michael, could you help me clarify how the units are linked.
>
>> From reading your code I get the impression that I create TMyForm
> separately then copy all of its code into appforms.pas.

No ?

> It is not a
> matter of adding the unit or TMyForm in appforms? Or is the other way
> round in which the unit of myform.pas has appforms included in its
> units?

It is the other way round.

>
> The first option also implies that I must include the .lfm file of
> myform in appforms.
>
> So in a nutshell does it mean I create TMyForm in the usual manner,
> using the IDE then copy all its contents into appform, then add  TForm
> = TBaseMyForm to the top of its type definition?

Yes, this is what you should do.

>
> I know I've got to brush up on my Object Pascal concepts, but some
> help here would be really welcome

Hope the above helps. If not, ask away.

Michael.


More information about the Lazarus mailing list