I want to add a TList with TTreeViewItem and a special class object (TRoom) with another. In delphi 2007 there was a βDataβ field of type Pointer, which was replaced by TValue, in which I do not know how to use it. I searched the Internet, stating that it could not handle custom types yet.
Can anyone come up with a way to achieve this other than making a hack class?
For example, the following form code should work correctly: -
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
FMX.TreeView, FMX.Layouts, FMX.Edit;
type
TRoom = class
ID : WORD;
Name : String;
end;
TForm1 = class(TForm)
TreeView1: TTreeView;
TreeViewItem1: TTreeViewItem;
Button1: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
var
List : TList;
begin
// Get The List From TreeViewItem1
// pani Solution - List := TList ( TreeViewItem1.TagObject );
Edit1.Text := TRoom ( List.First ).Name;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Room : TRoom;
List : TList;
begin
List := TList.Create;
Room := TRoom.Create;
Room.ID := 5;
Room.Name := IntToStr ( 5 );
List.Add ( Room );
// Add The List To TreeViewItem1
// pani Solution - TreeViewItem1.TagObject := List;
end;
end.
source
share