Search the web
Sign In
New User? Sign Up
delphigames · Discussion of game programming in the Delphi development environment.
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Steve Beaulieu is out of the office until Jan 5th   Message List  
Reply | Forward Message #7598 of 7611 |
RE: [DelphiGames] Casting an object to an interface

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






Tue Feb 10, 2009 3:17 pm

tom_grubb
Offline Offline
Send Email Send Email

Forward
Message #7598 of 7611 |
Expand Messages Author Sort by Date

I will be out of the office starting 12/18/2008 and will not return until 01/05/2009....
steve.beaulieu@...
Send Email
Dec 24, 2008
3:02 pm

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...
Ian Munro
ianathome12345
Offline Send Email
Feb 10, 2009
11:39 am

Hi Ian Munro, Use a TInterfaceList. That is a TList for interfaces. Regards, Tom ... From: delphigames@yahoogroups.com [mailto:delphigames@yahoogroups.com] On...
Grubb, Thomas G. (GSF...
tom_grubb
Offline Send Email
Feb 10, 2009
3:09 pm

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...
Grubb, Thomas G. (GSF...
tom_grubb
Offline Send Email
Feb 10, 2009
3:17 pm

Hello, I should probably explain my problem in greater detail as using an interface list will not work for me. I need to populate a visible list of data (a...
Ian Munro
ianathome12345
Offline Send Email
Feb 10, 2009
3:26 pm

Hi Ian, Then you need to use _AddRef and _Release. This works great but you need to make sure that you call _Release *before* the listview deletes its items....
Grubb, Thomas G. (GSF...
tom_grubb
Offline Send Email
Feb 10, 2009
7:40 pm

Hello, Thanks for your help in this matter. I've been speaking to the programmer of the DLL and he thinks that he may be able to sort the ref count in his...
Ian Munro
ianathome12345
Offline Send Email
Feb 11, 2009
8:57 am

Hi Ian, You are welcome. I like to monitor the group to keep my programming skills sharp (either learning something or being able to contribute). Good luck, ...
Grubb, Thomas G. (GSF...
tom_grubb
Offline Send Email
Feb 11, 2009
12:07 pm

Can't you define something like type PMyItem = ^TMyItem; TMyItem = record item: IJanusDataSourceItem; end; function PMyItem MyItem(i: IJanusDataSourceItem) var...
Igor Stojkovic
jimyiigor
Offline Send Email
Feb 11, 2009
4:33 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help