[Lazarus] OOP basics - 2
José Mejuto
joshyfun at gmail.com
Wed Apr 14 17:52:14 CEST 2010
Hello Lazarus-List,
Wednesday, April 14, 2010, 4:38:49 PM, you wrote:
K> It is simply a trivial example :)
K> It is at the base of an idea to make a "general" unit that can be used
K> between more projects, so I want avoid to make copy/paste everytime
K> the same functions. Often I forgot something... with a "generic" unit
K> that initialize some "standard things" I can do it easily.
For such repetitive things in your form, just use OOP, this means,
instead separate that functions in different units implement such
functions in a TForm descendent and inherit from it in your
specialized forms, something like:
Unit MyBaseForm;
type
TMyBaseForm=class(TForm)
private
protected
procedure SetUsualCaption(); virtual;
procedure AlignToUsualBorders(); virtual;
procedure InsertDefaultPanelWithSomeIcons(); virtual;
public
end;
..............
And just in the form designed unit change the usual:
type
Tform1=class(TForm)
by
TForm1=class(TMyBaseForm);
This way you have the functions and usual procedures in a separated
unit but you can access them from the form being designed.
--
Best regards,
José
More information about the Lazarus
mailing list