### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Test the object type of TTreeNode.Data  (Read 291 times)

#### Marion

• Jr. Member
• Posts: 90
##### Test the object type of TTreeNode.Data
« on: May 05, 2021, 10:23:07 pm »
How do I determine the object type in a TTreeNode.Data?

I have tried and failed with:

Code: Pascal  [Select][+][-]
1. TypeOf(Node.Data^) = TypeOf(TProject)
2.
3. Node.Data = TypeOf(TProject)

Thank you,
Marion
(A recovering Windows programmer.)

#### jamie

• Hero Member
• Posts: 4587
##### Re: Test the object type of TTreeNode.Data
« Reply #1 on: May 05, 2021, 10:50:34 pm »
First you need to check it for assignment...

if Assigned(Node.Data) then

if TObject(Node.Data) is TheNameOFTheClass Then....
The only true wisdom is knowing you know nothing

#### Marion

• Jr. Member
• Posts: 90
##### Re: Test the object type of TTreeNode.Data
« Reply #2 on: May 06, 2021, 12:03:29 am »
First you need to check it for assignment...

if Assigned(Node.Data) then

if TObject(Node.Data) is TheNameOFTheClass Then....

Thank you so much!
Thank you,
Marion
(A recovering Windows programmer.)

#### Remy Lebeau

• Hero Member
• Posts: 932
##### Re: Test the object type of TTreeNode.Data
« Reply #3 on: May 06, 2021, 12:24:36 am »
First you need to check it for assignment...

if Assigned(Node.Data) then

You don't need that.  All that will do is tell you whether Data is nil or not.  Calling the 'is' operator on a nil pointer will return False (and likewise, calling the 'as' operator on a nil pointer will return a nil pointer).  So the Assigned() check is redundant.
« Last Edit: May 06, 2021, 12:27:22 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)