Board index » delphi » type casting (objects)
RG RG
![]() Delphi Developer |
Sun, 14 Aug 2005 13:12:33 GMT
|
RG RG
![]() Delphi Developer |
Sun, 14 Aug 2005 13:12:33 GMT
type casting (objects)
Hm, what do you usually do if you want to type-cast, say, tview pointer as
tdialog one? I mean, tgroup.current returns pointer to active view (be it a window, dialog, whatever), which is declared as pview. How do I execute some method of tdialog, if active window is a dialog, and, therefore, pointer returned by tgroup.current points to an instance of tdialog object? I'm searching for a civilized way to do so:)) Would be very thankful for one who points thist way out. |
Marco van de Voor
![]() Delphi Developer |
Sun, 14 Aug 2005 04:32:30 GMT
Re:type casting (objects)QuoteIn article <b3gf5i$60...@hyppo.gu.net>, RG RG wrote: Quote> I mean, tgroup.current returns pointer to active view (be it a window, Quote> I'm searching for a civilized way to do so:)) Would be very thankful for one you cast the wrong pointer, you probably get a nice RTE 216. But afaik there is no systematic way to check this in BP/TP. (Delphi has IS |
Gdt8
![]() Delphi Developer |
Sun, 14 Aug 2005 07:48:30 GMT
Re:type casting (objects)Can't you derive your own objects in turbo vision ? I you can then one could create an object (TMyDialog ) from a TDialog object and add ones own IS method. Quote
|
Femme Verbee
![]() Delphi Developer |
Sun, 14 Aug 2005 09:14:49 GMT
Re:type casting (objects)"Marco van de Voort" <mar...@toad.stack.nl> schreef in bericht Quote> In article <b3gf5i$60...@hyppo.gu.net>, RG RG wrote: or object at a given location, but to consider it as the type specified by your typecasting. Quote> tdialog(tview) Quote> you cast the wrong pointer, you probably get a nice RTE 216. means of the typeof function. Something like if typeof (tgroup)=typeof(tmyobject) then..... I use this for determining the type in a tcollection filled with -- |
RG R
![]() Delphi Developer |
Mon, 15 Aug 2005 10:16:34 GMT
Re:type casting (objects)There seems to be another way to check object types - pointers to constructor init are all equal for every instance of an object. Replies were very helpful, thank you. Quote"Femme Verbeek" <fv[at]{*word*104}jet[dot]nl> wrote in message Quote
|
Femme Verbee
![]() Delphi Developer |
Mon, 15 Aug 2005 05:41:10 GMT
Re:type casting (objects)"RG RG" <ragnar0ck_FORSPAMME...@ukr.net> schreef in bericht Quote> There seems to be another way to check object types - pointers to if the constructor is an inherited method? The typeof function gives you a pointer to the objects vitual method table. Other preferable method is to start with a mother type of object. Give it a virtual method of the common operation you want to do. All the objects that you work with, decend from the mother type, where every type defines its own unique virtual method for the operation you wanted to do. -- |
RG R
![]() Delphi Developer |
Fri, 19 Aug 2005 12:14:27 GMT
Re:type casting (objects)Quote> Are you sure this will give a unique result for every object type? What Anyhow, mechanism for that and typeof() seems to be identical. Quote"Femme Verbeek" <fv[at]{*word*104}jet[dot]nl> wrote in message Quote
|