Link to home
Start Free TrialLog in
Avatar of Oli999
Oli999

asked on

store a record in TTreeNode data property

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;
ASKER CERTIFIED SOLUTION
Avatar of Ayd192
Ayd192

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Oli999
Oli999

ASKER

TreeView1.Items.Item[0].data = new(PTestType);

Thanks very much Aydin, this was what I needed. Much appreciated.

You're welcome. Good luck.