Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-11

object casting to pointer

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marco Aurelio Ramirez Carrillo

Hi.
I'm working witha TTreeview, and trying to assign a object to a TTreeNode.data property:

<code>
MyTreeNode := myTreeview.add(nil, "MyTreeNode");
// any "TObject" descendant class
MyObject = MyClass.Create();
// all of these, generate a syntax/semantic error:
// no typecasting
MyTreeNode.Data := MyObject;
// typecasting lowercase
MyTreeNode.Data := pointer(MyObject);
// typecasting capital
MyTreeNode.Data := Pointer(MyObject);
// typecasting with address operator
MyTreeNode.Data := pointer(@MyObject);
</code>

But none of them seems to work.
I already search in the wiki. Any idea, what is missing ?

Thanks.

stardev tod maramirezc ta gmail tod com

Reply by email

Leonardo M. Ramé
to Marco Aurelio Ramirez Carrillo
Marco Aurelio Ramirez Carrillo wrote 29 lines
Hi. I'm working witha TTreeview, and trying to assign a object to a TTreeNode.data property: <code> MyTreeNode := myTreeview.add(nil, "MyTreeNode"); // any "TObject" descendant class MyObject = MyClass.Create(); // all of these, generate a syntax/semantic error: // no typecasting MyTreeNode.Data := MyObject; // typecasting lowercase MyTreeNode.Data := pointer(MyObject); // typecasting capital MyTreeNode.Data := Pointer(MyObject); // typecasting with address operator MyTreeNode.Data := pointer(@MyObject); </code> But none of them seems to work. I already search in the wiki. Any idea, what is missing ? Thanks. stardev tod maramirezc ta gmail tod com

I did a quick test using this:

TreeView1.Items[0].Data := @MyObject;

And it compiled without problem.

Reply by email

Mattias Gaertner
to Marco Aurelio Ramirez Carrillo: Hi. I'm working witha TTreeview, and trying to assign a object to a TTreeNode.data…
Show quoted text 14 lines
Hi. I'm working witha TTreeview, and trying to assign a object to a TTreeNode.data property: <code> MyTreeNode := myTreeview.add(nil, "MyTreeNode"); // any "TObject" descendant class MyObject = MyClass.Create(); // all of these, generate a syntax/semantic error: // no typecasting MyTreeNode.Data := MyObject;

This works here.
Please provide a more complete example.

Show quoted text 5 lines
// typecasting lowercase MyTreeNode.Data := pointer(MyObject); // typecasting capital MyTreeNode.Data := Pointer(MyObject); // typecasting with address operator

Pascal types are case insensitive.

MyTreeNode.Data := pointer(@MyObject);

Simply wrong.

Mattias

Reply by email

Michael Van Canneyt
to Marco Aurelio Ramirez Carrillo: Hi. I'm working witha TTreeview, and trying to assign a object to a TTreeNode.data…
Marco Aurelio Ramirez Carrillo wrote 14 lines
Hi. I'm working witha TTreeview, and trying to assign a object to a TTreeNode.data property: <code> MyTreeNode := myTreeview.add(nil, "MyTreeNode"); // any "TObject" descendant class MyObject = MyClass.Create(); // all of these, generate a syntax/semantic error: // no typecasting MyTreeNode.Data := MyObject;

I do this every day ? What is the error you get ?

Michael.

Reply by email