Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 02-12-2018, 07:59 PM
FreakaZoid2 FreakaZoid2 is offline
Senior Member
 
Join Date: Jul 2009
Posts: 330
Default treeview pointers to data (VirtualTree)

I am working with a virtualtree and trying to figure out how to make the gettext work with an object instead of just the sample strings. The GetText (last part that I am having issue with) how to get the name part of the object back so I can assign it to the gettext for the cell?

Code:
type
  TMenuClass = class
  private
    F_XMLName : String;
    F_AppID: String;
    F_Name: String;
  published
    property XMLName: String read F_XMLName write F_XMLName;
    property AppID: String read F_AppID write F_AppID;
    property Name: String read F_Name write F_Name;
end;

type
  PMenuData = ^TMenuData;
  TMenuData = record
    FObject : TObject;
end;
.......
function AddVSTObject(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; AObject: TObject): PVirtualNode;
var
  Data: PMenuData;
begin
  Result:=AVST.AddChild(ANode);
  AVST.ValidateNode(Result,False);
  Data:=AVST.GetNodeData(Result);
  Data^.FObject:=AObject;
end;
......
    MenuObject:=TMenuClass.Create;
    if Node.NodeName = 'app' then
    begin
      try
        MenuObject.XMLName:= XMLDoc.FileName;
        MenuObject.AppID:= Node.Attributes['id'];
        MenuObject.Name:= Node.Attributes['name'];
        AddVSTObject(VST,nil,MenuObject);
      except
        MenuObject.Free;
      end;
    end;
......
procedure TfrmMain.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
var
  MenuData : PMenuData;
  MenuObject : TMenuClass;
begin
  MenuData := VST.GetNodeData(Node);
  MenuObject := TMenuClass.Create;
  MenuObject := TMenuClass(MenuData^.FObject);
  CellText := MenuObject.name;
  MenuObject.Free;

end;
  #2  
Old 02-12-2018, 08:12 PM
FreakaZoid2 FreakaZoid2 is offline
Senior Member
 
Join Date: Jul 2009
Posts: 330
Default Never mind figured out that it was running thru code twice

first time empty next time with data....

Code:
var
  Data: PMenuData;
begin
  if not Assigned(Node) then
    Exit;
  Data:=VST.GetNodeData(Node);
  if Data.FObject <> nil then
    CellText := (TMenuClass(Data.FObject).Name);
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:30 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.