Jump to content

TUniTreewView


Marlon Nardi

Recommended Posts

Why Marlon ?

What is the purpose ?

 

If you want to store a textField for each node, look at the new demo 0.99. Farshad used a very nice technic for that :

Just create a TStringList and store on it this syntaxe :

 

L:=TStringList.Create

L.add('myNode1=myText1')

L.add('myNode2=myText2')

...

Then L.Values['myNode2'] gives you myText2

 

Could this be your Field additional ?

For more details see AllFeaturesDemo project on the mainForm.onCreate

(FileName : TStrings)

 

Regards.

Link to comment
Share on other sites

Maybe something like that?

Declare a pointer to a record which contains all the fields you need.
 

type
PMyRecord = ^TMyRecord;
TMyRecord = record
MyStringField: String;
MyIntegerField: Integer;
MyDateTimeField: TDateTime;
MyTGUIDField: TGUID;
//...
end;

Assign an instance of this pointer to each node of your tree.
 

var MyRecordPointer:PMyRecord;
MyNode:TUniTreeNode;
begin
//In a loop...
MyNode:=MyUniTreeView.Items.Add(nil, 'myNodeCaption');
New(MyRecordPointer);
MyRecordPointer^.MyStringField:='uniGui';
MyRecordPointer^.MyIntegerField:=99;
MyRecordPointer^.MyDateTimeField:=now;
MyRecordPointer^.MyTGUIDField:=TGUID.Empty;
MyNode.Data:=MyRecordPointer;
//Loop...
end;

Get the values of the record linked to a node whenever you want.
 

ShowMessage(PMyRecord(MyUniTreeView.Selected.Data)^.MyStringField);
DecodeDate(PMyRecord(MyUniTreeView.Items[0].Data)^.MyDateTimeField, MyYear, MyMonth, MyDay);
//...
  • Upvote 1
Link to comment
Share on other sites

+1
You can do it also with objects to avoid pointer's records.
TUniTreeNode.Data accept any object :

Type TmyData=Class
Private
fMyString:string;
fMyinteger:integer;
...
published
   Property  MyString : string read fMyString write fMyString;
   Property: integer read fMyinteger write fmyinteger;
end;

Then declare an instance of your object :
Var Obj: TmyData;
Begin
Obj:=TmyData.Create;
Try
Obj.Mystring:='Hello i am Node 1';
Obj.Myinteger:=1001;

// then use Data methode to get it :
--------------------------------------
MyUniTreeView.Selected.Data := Obj;
--------------------------------------
Finally
Obj.free;
End;
 

_________________________________

After you can retreive your fields like : 

 UniEdit1.Text := TmyData(MyUniTreeView.Selected.Data).fMyString;

 UniEdit2.Text := intToStr( TmyData(MyUniTreeView.Selected.Data).fMyInteger );

 

Thx to FreeMan35

 

Regards.

  • Upvote 3
Link to comment
Share on other sites

  • 1 year later...

I'm still testing on trail version, so I can not check source code of unigui. If I'm not wrong, TUniTreeView and TUniTreeNode class inherited from delphi. If this true, why not published some importent properties? example: "OnDeletion" event. This event so usefull for purge memory for added data.

Var Obj: TmyData;
Begin
Obj:= TmyData.Create;
MyUniTreeView.Selected.Data:= Obj;// blocked ram.

and add 20 nodes. this mean created 20 time obj record. after then user delete some nodes. in unigui, have to write some code lines and make many control for memoryleak. But on delphi's treeview, just one line:

....OnDeletion(Sender: TObject; Node: TTreeNode);
TmyData(Node.Data).Free; // simple scenario

Best regards

  • Upvote 1
Link to comment
Share on other sites

If needed is just store data, (string, integer etc.) I'm not recomended class type. record or packed record is better then class.

My example is:

type  
  P_Data= ^T_Data;
  T_Data = record
    Lst: TList;
    Hint: string;
    whr : string;
  end;
..
var
    N: TUniTreeNode;
    P: P_Data;
begin
      N:= TRW_.Items.AddChild(nil, 'Test node');
      P:= New(P_Data);
      P.Lst:= TList.Create;
      N.Data:= P;
     
     P.Lst.Add(TUniCheckBox.Create(FRM_xxxx);

This my usage. before remove data, in  Lst's (TList) dimision has to be free, then free node data (record) via dispose(P); this can be so easy, if ondeletion event be added.

Link to comment
Share on other sites

  • 1 month later...

About feature request,

I'd like have the possibility to Bookmark the most interesting/useful forum topics in my profile

so I have my personal Wiki to look at when I need remember how problems can be solved.

 

It's a forum feature I have seen very useful on other products (RemObjects).

 

Thanks

Link to comment
Share on other sites

×
×
  • Create New...