BTW, the problem you were having below is that when you shoved the
interface into the Tlist, the reference count was not incremented. So,
at some point, the object behind the interface got freed... And bang
when you tried to get it back. You could have hacked around this by
call __AddRef and all the other reference counting code but it would be
a hack and messy. Much cleaner to use the TinterfaceList (which also
has its own interface, IInterfaceList).
Regards,
Tom
-----Original Message-----
From: delphigames@yahoogroups.com [mailto:delphigames@yahoogroups.com]
On Behalf Of Grubb, Thomas G. (GSFC-583.0)
Sent: Tuesday, February 10, 2009 10:08 AM
To: delphigames@yahoogroups.com
Subject: RE: [DelphiGames] Casting an object to an interface
Hi Ian Munro,
Use a TInterfaceList. That is a TList for interfaces.
Regards,
Tom
-----Original Message-----
From: delphigames@yahoogroups.com [mailto:delphigames@yahoogroups.com]
On Behalf Of Ian Munro
Sent: Tuesday, February 10, 2009 6:39 AM
To: delphigames@yahoogroups.com
Subject: [DelphiGames] Casting an object to an interface
Hello,
I need to store references to interfaces in a list so that when the user
selects a list item I can easily access the interface that relates to
that item. I've been casting the interface as a pointer and adding it as
the list items object. Now when I try to retrieve it I try to cast it
back and the compiler moans that you cant cast a TObject to an
interface. I tried casting it to a pointer first and then to the
interface type which the compiler likes (see code below). The problem I
have then is that when the code runs, when the following line runs it
throws an exception. My question is, Is there a better way to do what I
need to do and what is causing the problem with this code. I must say
that I'm not 100% when it comes to interfaces.
Item := IJanusDataSourceItem (pointer (ListItemObject)) ;
This email is intended solely for the person to whom it is addressed and
may contain confidential or legally privileged information. If you are
not the intended recipient, be advised that you have received this email
in error and that any use, dissemination, forwarding, printing or
copying of this email is strictly prohibited. Please notify the author
by replying to this email and destroying all copies of the email and
attachments. Access to this email by anyone else is unauthorised.
Email may be susceptible to data corruption, interception, unauthorised
amendment, viruses and delays or the consequences thereof. Any views or
opinions presented are solely those of the author and do not necessarily
represent those of Grosvenor Technology Ltd.
Grosvenor Technology Ltd. (incorp. Newmark Technology Ltd.) is a company
registered in England with company number 2412554.
The Grosvenor Technology Ltd. Registered Office address is Millars
Three, Southmill Road, Bishop's Stortford, Herts, CM23
[Non-text portions of this message have been removed]
------------------------------------
// *** Yahoo! Groups Info ***
begin
Yahoo! Group := DelphiGames;
HomePage := http://turbo.gamedev.net
Unsubscribe := delphigames-unsubscribe@yahoogroups.com
end.Yahoo! Groups Links
------------------------------------
// *** Yahoo! Groups Info ***
begin
Yahoo! Group := DelphiGames;
HomePage := http://turbo.gamedev.net
Unsubscribe := delphigames-unsubscribe@yahoogroups.com
end.Yahoo! Groups Links