Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event handlers in multiple objects

Status
Not open for further replies.

bobbie100

Programmer
Aug 29, 2003
64
GB
I am currently designing a game suite which has at it's core a central set of properties, methods and sub-classes implemented in an abstract class TGameCore. Each game will be a descendant of this core, providing its own special implementation of the abstract methods defined in TGameCore.

Unit Game1 containing:
TGame1 = class(TGameCore)
+ implementation of abstract methods

Unit Game2 containing:
TGame2 = class(TGameCore)
+ different implementation of abstract methods

and MANY more Units

The display on the screen is handled by a separate form with a descendant of TGraphicControl being used as a drawing surface over the client area of the form.

My problem is that I want to link events occurring on the display form and drawing surface (e.g mouse events on the drawing surface and menu/speed button events on the form) to handlers within the TGameCore that is common to each game.

The question is how do I link this significant number of different events to a substantial number of different descendants of TGameCore? I don't know if it makes any difference, but there is only ever one game in existence at the same time. So the none of the events are never linked to two event handlers at the same moment.

I have read a bit about the use of interfaces. However, these only seem to talk about providing access to methods. Are they appropriate for the implementation of event handlers that are accessed via pointers to methods, rather than direct calls to the methods themselves? If so, how is this implemented?

Any advice on this or other more suitable approaches would be very much appreciated.
 
Sorry for wasting your time on this one. Obviously having a bad day yesterday.

Just need to declare statements such as:
GameDisplay.OnClick := GameDisplayClick;
in the constructor of TGameCore and declare property OnClick in the public section of TGameDisplay.

Again many apologies!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top