Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-11

How do you create some kind of type definition based on adding a set if identical functions to different objects with different ancestors?

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Frank Church

I don't know whether interfaces are what I am looking for here.

I am creating an object called TStateInfoSource which needs to display its state using different objects, mainly a TForm, a TFrame, some future TComponent based visual object and a web interface as yet undecided.

eg, both the TForm, the TFrame and web object are to implement a function called DisplayState in their own way.

Is there some way to create some kind of type definition called a TImplementsDisplayState so that TStateInfoSource can call the DisplayState function of TImplementsDisplayState object it is associated with at runtime?

In effect the TImplementsDisplayState facility is added or associated with existing objects, rather then having TForm, TFrame etc as its sub properties or components. In this way the display code is implemented directly by the form or frame, rather than having the TImplementsDisplayState object manipulate the form or frame's elements directly.

In effect is it possible to put a group of unrelated objects into the same type definition by adding to them a set of identically defined functions?

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101117/0632ab29/attachment-0001.html>

Reply by email

Frank Church
to Frank Church
Frank Church wrote 30 lines
I don't know whether interfaces are what I am looking for here. I am creating an object called TStateInfoSource which needs to display its state using different objects, mainly a TForm, a TFrame, some future TComponent based visual object and a web interface as yet undecided. eg, both the TForm, the TFrame and web object are to implement a function called DisplayState in their own way. Is there some way to create some kind of type definition called a TImplementsDisplayState so that TStateInfoSource can call the DisplayState function of TImplementsDisplayState object it is associated with at runtime? In effect the TImplementsDisplayState facility is added or associated with existing objects, rather then having TForm, TFrame etc as its sub properties or components. In this way the display code is implemented directly by the form or frame, rather than having the TImplementsDisplayState object manipulate the form or frame's elements directly. In effect is it possible to put a group of unrelated objects into the same type definition by adding to them a set of identically defined functions? -- Frank Church ======================= http://devblog.brahmancreations.com

I think interfaces are what I need here. I'm going to do some more reading.

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101119/a93887b1/attachment.html>

Reply by email

Max Vlasov
to Frank Church

2010/11/19 Frank Church

Show quoted text 39 lines
On 17 November 2010 10:39, Frank Church wrote: > > I don't know whether interfaces are what I am looking for here. > > I am creating an object called TStateInfoSource which needs to display its > state using different objects, mainly a TForm, a TFrame, some future > TComponent based visual object and a web interface as yet undecided. > > eg, both the TForm, the TFrame and web object are to implement a function > called DisplayState in their own way. > > Is there some way to create some kind of type definition called a > TImplementsDisplayState so that TStateInfoSource can call the DisplayState > function of TImplementsDisplayState object it is associated with at > runtime? > > In effect the TImplementsDisplayState facility is added or associated with > existing objects, rather then having TForm, TFrame etc as its sub properties > or components. In this way the display code is implemented directly by the > form or frame, rather than having the TImplementsDisplayState object > manipulate the form or frame's elements directly. > > In effect is it possible to put a group of unrelated objects into the same > type definition by adding to them a set of identically defined functions? > > -- > Frank Church > > ======================= > http://devblog.brahmancreations.com > I think interfaces are what I need here. I'm going to do some more reading.

Frank, reading your initial question, I think the interfaces are good for the task, but if it's just about calling a single method or two, I'd choose just passing/register method pointers. it's something about interfaces that I don't like much. When I'm a user of DirectX, it's ok, it's just a convenient way to access the API and it looks like you just use objects. But when I implement them in my own project as a way of interation between objects, it smells multiple inheritance, this thing I'd avoid with any programming language.

Max Vlasov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101120/fcdd9d3a/attachment.html>

Reply by email