On Thu, 2005-03-24 at 14:37 +0000, memsom wrote: > Sorry to be late in the conversation... > > >> Here is a simple example how it should be used > >> > >> type > >> IReportable = interface > >> function Report: string; > >> // let's say that this should write report and > >> // return status description as string > >> end; > >> > >> ILogged = interface > >> procedure Log(aStr: string); > >> end; > > > Surely, using Delphi's way of things: > > type TMyReport = class(TInterfacedObject, IReportable, ILogged) > ... //an implementation of each interface > end; > > > >> procedure MyXYZPart.DoReport(aRep: IReportable); > >> begin > >> if (aRep <> nil) then begin > >> if (aRep is ILogged) then > >> (aRep as ILogged).Log(aRep.Report) > >> else > >> aRep.Report > >> end; > > > Again : > > > procedure MyXYZPart.DoReport(aRep: IReportable); > var > tmp: ILogged; > begin > if (aRep <> nil) then begin > if (aRep.QueryInterface(ILogged, tmp) = S_OK) then > tmp.Log(aRep.Report) //or you could just do the as cast.. > else > aRep.Report > end; >
1. and what I would like is just a lot cleaner and readable code of this. 2. Before you tell how to do something at least test and look your solution 2.1. Because queryinterface doesn't work in fpc as it should you always get first vmt and if you do a queryinterface you don't work with correct interface, you just get exception when you work with this new interface. Anyway patch for this will be finished until weekend. 2.2. It's ugly and not really readable, you always land with additional declarations like tmp > > > > I see what you want, but if you would do > > > > procedure MyXYZPart.DoReport(aRep: TInterfacedObject); > > > > begin > > if (aRep <> nil) and arep is IReportable then begin > > if (aRep is ILogged) then > > (aRep as ILogged).Log(aRep.Report) > > else > > aRep.Report > > end; > > Converting interfaces to instances to object instances is a bad idea... it > screws with reference counting, for a start...> This still does not > explain why you would need to do > Follow the vmt problems. That is needed for defining blind properties. It has to be redirected to original vmt of class. For now you have to specify properties as type IA = interface function GetSome: integer; procedure SetSome(aValue: integer); property Some: integer read GetSome write SetSome; end; this is needed because interface has no clue of original vmt. while blind properties definition would be type IA = interface property Some: integer read object write object; end; and the implementation of property is left to class, not conditioned with function and procedure > > AClassInstance := AnInterface; > > I think the above is a really bad idea. Especially when the implementing > class is private... e.g. > > interface > > type > IPublic = interface > procedure whatever; > end; > > TFactory = class > function newPublic: IPublic; > end; > > implementation > > type > TPrivate = class(TInterfacedObject, IPublic) > ... > end; > > function TFactory.newPublic: IPublic; > begin > > Result := TPrivate.Create; // or implement some kind of class > // pooling etc .. > end; > How could you define private class outside where it is not visible. Best shot for you it would be highest visible type of this class. So sorry, I don't understand this part. This is something which is completely normal behavior and is connected to software plan only. No rocket since here. > > How would you be able to get at the class? Only as TObject or > TInterfacedObject. Bad idea. I don't know where the idea here is and thus I don't know why it would be bad. ml > > Matt > > > > > _______________________________________________ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal