[fpc-pascal] Question about interfaces
ml
ml at brainwashers.org
Sat Mar 19 06:03:45 CET 2005
On Sat, 2005-03-19 at 03:55 +0200, Nikolay Nikolov wrote:
> ml wrote:
>
> >3. This one is not some little beauty hack. So, no pressure here. But, I
> >must admit that I'm most interested in this answer. Classes do support
> >multiple interface inheritance, but interfaces don't. That cuts almost
> >all of the interface flexibility. Any good reasons why?
> >
> >
> Probably because of Delphi and COM.
>
??? You mean,... outdated technology that's ceasing to exist even on
Microsoft grounds? COM will not exist anymore, and Delphi will be .net
only :)
More != Less ;)
You can be backward compatible if you support more. And to cut a
powerful feature? I just hope that fpc-devel team is planing to
implement it.
Well, problem can be solved, but its ugly solution. Is there any way
except include file to specify global macros???? Probably not:) I think
I'll probably have to live with some kind of {$I
multiple_interfaces.inc} in every file. Now I wish I can do something
for foreach() and world will be looking much brighter. It should be
doable now that I have multiple interfaces.
Solution:
{$MACRO+}
{$define INamedList := IList, INamed, IUnique}
function SupportsInterface(aInterface: IUnknown; aGUID: array of TGUID):
boolean; // check for complete support of all passed interfaces
function SupportsInterface(aObject: TObject; aGUID: array of TGUID):
boolean; // check for complete support of all passed interfaces
type
TGUIDArray = array of TGUID;
// Tests for detecting interface functionality
//
// and if "is" can't be assigned,... "><" can
operator >< (const source: IUnknown; data: TGUID) dest : boolean;
operator >< (const source: IUnknown; data: TGUIDArray) dest : boolean;
operator >< (const source: TObject; data: TGUID) dest : boolean;
operator >< (const source: TObject; data: TGUIDArray) dest : boolean;
type
TObjectCollection = class(TInterfacedObject, INamedList)
yaddayaddayadda
end;
begin
if (someobjectorinterface >< [INamedList]) then
...
end.
Looks ugly as hell, but it does its job done with a lot of code shortage
and software doesn't grow up in heights (hierarchy) but stays as low as
possible, with much wider variety of combination possible
p.s. One couldn't believe how such small feature (like macro) can make
your day better??? or night:)
p.p.s. fpc-devel team if anyone reads this, thanks for macros and
operators. You just made one man a very happy person
ml
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list