troubleshooting Question

store a record in TTreeNode data property

Avatar of Oli999
Oli999 asked on
Delphi
3 Comments1 Solution668 ViewsLast Modified:
Hello.

Am writing an application that contains a large TTreeView and wish to store some data against every node in the tree of complex data type.

Have figured out how to do this with a simple data types like integer and string but can't get it working with a record.

I can see why the sample of code below crashes, but can't figure out how to get it working. Please can anyone help?

type
  PTestType = ^TTestType;
  TTestType = record
    str1,str2 : string;
  end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  PTestType(TreeView1.Items.Item[0].data).str1:='hello1';     //crashes here with "access vioaltion"
  PTestType(TreeView1.Items.Item[0].Data).str2:='hello2';
  showmessage(PTestType(TreeView1.Items.Item[1].Data).str1);
  showmessage(PTestType(TreeView1.Items.Item[1].Data).str2);
end;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros