How about using supports?
or just do the assignment and then check for a nil interface instead of
doing the explicit cast.
eg
into := fMyList[i] as ICommandInterface;
if Assigned( intf) then Intf.Prune;
or
if Supports( fMyList[i], ICommandInterface, Intf) then Intf.Prune;
It's not friday yet ...
Myles.
-----Original Message-----
From: Nahum Wild [mailto:[EMAIL PROTECTED]]
Sent: Thursday, November 02, 2000 9:45 AM
To: Multiple recipients of list delphi
Subject: [DUG]: Today's Mental block
I'm trying to determine if an object implements an interface, and I'm having
a complete mental block about it.
The situation is that I have a TList of objects that ALL implement IUnknown.
Some in the list might implement ICommandCluster and I want to test for this
and do something with them if they do. I'm pretty sure I've done something
in the past that was nice and simple/elegant to determine if an object
implemented a particular interface, but as I said I'm having a complete
mental block about it.
Currently I'm just forcibly casting at runtime the objects to the interface
and trapping the exception generated if it don't work.
for i := fUndoList.Count-1 do begin
try
(fMyList[i] as ICommandInterface).Prune;
except
on E: EIntfCastError do begin
// do nothing
end;
end;
end;
This is pretty yuck and want to do it a better/nicer way. Does anybody know
what I'm taking about and/or can help??
Cheers,
Nahum Wild
Game Designer
Realism Ltd
Pre-Register now for the ESDAO beta test!
http://www.esdao.net
Also the official home of the FatFree Browser
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"