Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OOP Design in Delphi using VCL

29 views
Skip to first unread message

Pier

unread,
Jan 21, 2008, 5:35:35 AM1/21/08
to
I am writing an internet application in Delphi 7 and have ended up with a
lot of code in the main form's unit file. I make use of many of the events
of controls on the main form. I want to make the application more modular so
I thought of deriving classes in separate units for some of the controls on
the main form and overriding methods instead of using events. Is this a good
approach or is there a better way of making the application more modular?

Pier


HAROUCHE, David

unread,
Jan 21, 2008, 7:53:44 AM1/21/08
to
You might explore the TDataModule model !

Another approach is to use TActionList...

DH...

"Pier" <pi...@ramm.co.za> a écrit dans le message de news:
4794759e$1...@newsgroups.borland.com...

Marc Rohloff [TeamB]

unread,
Jan 21, 2008, 10:23:33 AM1/21/08
to

I would only override a control if I wanted to change its
functionality and reuse it. I would break the form up into individual
frames, each handling a group of controls. You can add events and
methods to the frame which your main form can call.

--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com

Peter Morris [CapableObjects]

unread,
Jan 21, 2008, 10:32:29 AM1/21/08
to
The development approach for the dev tool on Apple is to create a class to
do all the logic, and then have the various Button.Click events execute
methods on an instance of that class.

Qi

unread,
Feb 1, 2008, 9:49:47 AM2/1/08
to
Qi wrote:
>
> Some suggestions,
>
> 1, Put all controls which on the main form to a separate frame, then put
> that frame on the main form. This gives you the chance to add another
> group of controls without modifying current ones' layout.
>
> 2, Use TActionList instead of events.
>
> 3, By using TActionList, instead of write OnExecute handler for each
> actions, write a handler in TActionList.OnExecute then dispatch the
> event as an ID (use actions' tag property to store the IDs). This is so
> called "command model" in refactoring.
> I heavily use this method in my projects. One public project is the
> LeakInspector in Denomo (Google Denomo for it if you want to see the code).
> This method will significantly reduce the even handlers count. But it's
> not a must so you may skip this point if you don't know how to implement
> it.
>
> 4, Don't do any business/data logic in the even handlers (hey, the
> handlers belong to UI logic). You need some business/data logic, then
> connect them with the UI through some simple interfaces or APIs.
> Your business/data logic module should have the most code instead of the
> UI module.


Sorry for the terrible format (long lines).
I was cheated by ThunderBird that it wrapped the lines virutally
instead of inserting a new line break.

Qi

unread,
Feb 1, 2008, 9:48:16 AM2/1/08
to

Some suggestions,

Pier

unread,
Feb 7, 2008, 8:13:26 AM2/7/08
to
Marc

I created a number of frames, but I find that some event handlers in the
frames do not get called. I have to add events to the frames via the main
form. I want the event handlers in the frame units to be called, since I
have now put the event handlers that were in the main form in their own
frames.

Pier

"Marc Rohloff [TeamB]" <ma...@nospam.marcrohloff.com> wrote in message
news:ij7ivno5...@dlg.marcrohloff.com...

Graeme Geldenhuys

unread,
Jul 14, 2008, 5:07:47 AM7/14/08
to

A very nice (and quick) way of minimizing code in Forms is to use the
MGM (Module-GUI-Mediator) design pattern. MGM fits nicely between MVC
(Module-View-Controller) and MVP (Model-View-Presenter), but I think
it's the easiest one to implement and fits very nice with today's modern
GUI frameworks without having to create custom components or register
new components in the component palette. I have used MGM successfully
with 3 GUI toolkits - VCL/CLX, LCL and fpGUI.

I have implemented MGM using RTTI and created generic mediators. This is
a more complex implementation, but a much more simplified implementation
with a couple lines of code is also possible.

For more details on MGM. See the the following:
http://www.atug.com/andypatterns/mgm.htm

My my MGM implementation using RTTI is the tiOPF project on SourceForge.
https://tiopf.svn.sourceforge.net/svnroot/tiopf/tiOPF2/Trunk/GUI
Units of interrest:
tiGenericEditMediators, tiGenericListMediators,
tiGenericTreeviewMediator and tiCompositeMediators

Regards,
- Graeme -


_______________________________________________________
fpGUI - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

0 new messages