untyped pointers - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

untyped pointers

Someone know how can i could test if a untyped pointer is a TObject?

Comments

  • zibadianzibadian Posts: 6,349Member
    : Someone know how can i could test if a untyped pointer is a TObject?
    :
    :
    Here is an untested sample code for that:
    [code]
    try
    TObject(SomePtr).ClassName;
    Label1.Caption := 'SomePtr is an object.';
    except
    Label1.Caption := 'SomePtr is not an object.';
    end;
    [/code]

  • MasterijnMasterijn Posts: 188Member
    : : Someone know how can i could test if a untyped pointer is a TObject?
    : :
    : :
    : Here is an untested sample code for that:
    : [code]
    : try
    : TObject(SomePtr).ClassName;
    : Label1.Caption := 'SomePtr is an object.';
    : except
    : Label1.Caption := 'SomePtr is not an object.';
    : end;
    : [/code]
    :
    :
    A good, but brutal solution ;) Anyway its not a good idea to mix both pointers and objects, to avoid this sort of cruel testing. There's always the possibility that your normal mem can accidently act like an object with regard to the method ClassName! Anyway when hardware exceptions are needed to get code to work, loose the code, and I don't mean the code above. -> You can always code you normal mem stuff as a very simple object with a pointer property.


Sign In or Register to comment.