* * *

Author Topic: How to use this appearance in VirtualTreeView  (Read 2798 times)

Ericktux

  • Full Member
  • ***
  • Posts: 142
How to use this appearance in VirtualTreeView
« on: August 07, 2017, 09:16:10 am »
Hello friends, how can I use the appearance in VirtualTreeView of the image attached.  :(
Attached image and project, regards.

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 456
Re: How to use this appearance in VirtualTreeView
« Reply #1 on: August 07, 2017, 06:04:19 pm »
You need to do owner draw. Here is an example: https://github.com/blikblum/luipack/tree/master/vtvextras/vtvutils/demos/jsontreeview-ownerdraw

You can find more in internet (most Delphi code should work)

Ericktux

  • Full Member
  • ***
  • Posts: 142
Re: How to use this appearance in VirtualTreeView
« Reply #2 on: August 08, 2017, 12:00:17 am »
Thanks friend, but ask me to install multiple LPK files.  %)
At the end of searching all its dependencies I get the blank example.  :(

Ericktux

  • Full Member
  • ***
  • Posts: 142
Re: How to use this appearance in VirtualTreeView
« Reply #3 on: August 10, 2017, 07:06:35 pm »
hi my friends, I have managed to have multiline, but as I can put the buttons to the sides like the previous image, help please.  :( :(
Attached image and draft.

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, VirtualTrees, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   StdCtrls, Buttons;
  10.  
  11. type
  12.   PData = ^TData;
  13.   TData = record
  14.     FName: String;
  15.     FOcupation: String;
  16.     FYear: String;
  17.     FMarried: String;
  18.     FImageIndex: Integer;
  19.   end;
  20.  
  21.   { TForm1 }
  22.  
  23.   TForm1 = class(TForm)
  24.     BitBtn1: TBitBtn;
  25.     ImageList1: TImageList;
  26.     VST: TVirtualStringTree;
  27.     procedure BitBtn1Click(Sender: TObject);
  28.     procedure button1Click(Sender: TObject);
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  31.       Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
  32.       var ImageIndex: Integer);
  33.     procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  34.       Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
  35.   private
  36.    function GetSelectedNodeData2(var AData: PData): Boolean;
  37.   public
  38.  
  39.   end;
  40.  
  41. var
  42.   Form1: TForm1;
  43.  
  44. implementation
  45.  
  46. {$R *.lfm}
  47.  
  48.  
  49. function TForm1.GetSelectedNodeData2(var AData: PData): Boolean;  // code of getmem...
  50. var
  51.   Node: PVirtualNode;
  52. begin
  53.   Node := VST.GetFirstSelected;
  54.   if Node <> nil then
  55.   begin
  56.     AData := VST.GetNodeData(Node);
  57.     Result := True;
  58.   end
  59.   else
  60.   Begin
  61.     //MessageDlg('Please select a node first!', mtInformation, [mbOk], 0);
  62.     Result := False;
  63.   end;
  64. end;
  65.  
  66. procedure TForm1.button1Click(Sender: TObject);
  67. begin
  68.  
  69. end;
  70.  
  71. procedure TForm1.BitBtn1Click(Sender: TObject);
  72. var
  73.   Data: PData;
  74.   Node: PVirtualNode;
  75. begin
  76.   if not GetSelectedNodeData2(Data) then
  77.   Exit;
  78.   begin
  79.     //ShowMessage(Data^.FName+', '+Data^.FOcupation+', '+Data^.FYear+', '+Data^.FMarried);
  80.  
  81.     ShowMessage(Data^.FName);
  82.     {ShowMessage(Data^.FOcupation);
  83.     ShowMessage(Data^.FYear);
  84.     ShowMessage(Data^.FMarried);}
  85.   end;
  86. end;
  87.  
  88. procedure TForm1.VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  89.   Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
  90.   var ImageIndex: Integer);
  91. var
  92.   Data: PData;
  93. begin
  94.   if Column = 0 then
  95.   begin
  96.     Data := VST.GetNodeData(Node);
  97.     ImageIndex := Data^.FImageIndex;
  98.   end;
  99. end;
  100.  
  101. procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  102.   Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
  103. var
  104.   Data: PData;
  105. begin
  106.   Data := VST.GetNodeData(Node);
  107.   case Column of
  108.     0: CellText := '';
  109.     1: CellText := Data^.FName;
  110.     2: CellText := Data^.FOcupation;
  111.     3: CellText := Data^.FYear;
  112.     4: CellText := Data^.FMarried;
  113.   end;
  114. end;
  115.  
  116. procedure TForm1.FormCreate(Sender: TObject);
  117. var
  118.   Data: PData;
  119.   Node: PVirtualNode;
  120. begin
  121.   VST.Clear;
  122.   VST.NodeDataSize := SizeOf(TData);
  123.  
  124.   Node := VST.AddChild(nil);
  125.   Data := VST.GetNodeData(Node);
  126.   VST.MultiLine[node] := true;
  127.   Data^.FName := 'erick, '#13'student, '+'18, '+'no';
  128.   {Data^.FName := 'erick';
  129.   Data^.FOcupation := 'student';
  130.   Data^.FYear := '18';
  131.   Data^.FMarried := 'no';}
  132.   Data^.FImageIndex := 0;
  133.  
  134.   Node := VST.AddChild(nil);
  135.   Data := VST.GetNodeData(Node);
  136.   VST.MultiLine[node] := true;
  137.   Data^.FName := 'magui, '#13'enfermera, '+'25, '+'si';
  138.   {Data^.FName := 'magui';
  139.   Data^.FOcupation := 'enfermera';
  140.   Data^.FYear := '25';
  141.   Data^.FMarried := 'si';
  142.   Data^.FImageIndex := 1;}
  143.  
  144.   Node := VST.AddChild(nil);
  145.   Data := VST.GetNodeData(Node);
  146.   VST.MultiLine[node] := true;
  147.   Data^.FName := 'leo, '#13'ingenier, '+'30, '+'si';
  148.   {Data^.FName := 'leo';
  149.   Data^.FOcupation := 'ingenier';
  150.   Data^.FYear := '30';
  151.   Data^.FMarried := 'si';}
  152.   Data^.FImageIndex := 2;
  153.  
  154.   {vst.InvalidateNode(Node);
  155.   vst.Refresh;}
  156. end;
  157. end.




GetMem

  • Hero Member
  • *****
  • Posts: 2327
Re: How to use this appearance in VirtualTreeView
« Reply #4 on: August 10, 2017, 08:14:36 pm »
What is "Get Data" a button?

Ericktux

  • Full Member
  • ***
  • Posts: 142
Re: How to use this appearance in VirtualTreeView
« Reply #5 on: August 11, 2017, 05:07:50 am »
hi my friend getmem, Exactly it is a button, with this I want to obtain the data of the row in which this button is found.

GetMem

  • Hero Member
  • *****
  • Posts: 2327
Re: How to use this appearance in VirtualTreeView
« Reply #6 on: August 11, 2017, 07:11:31 am »
@Ericktux
It can be done, but at the moment I'm busy with other things. Maybe next week I can make a demo if time permits.

Ericktux

  • Full Member
  • ***
  • Posts: 142
Re: How to use this appearance in VirtualTreeView
« Reply #7 on: August 11, 2017, 07:36:14 am »
Thanks friend for your help  :), while I wait for your demo I will continue to look for more solutions.

Ericktux

  • Full Member
  • ***
  • Posts: 142
Re: How to use this appearance in VirtualTreeView
« Reply #8 on: August 15, 2017, 07:37:09 am »
Good friends  :), I have managed to have a small progress, manage to put buttons to each row, but I still have to put action to the click of the button.

Attached code, project and images of my progress.

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   windows, Classes, SysUtils, VirtualTrees, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   StdCtrls, Buttons, ComCtrls;
  10.  
  11. type
  12.   PData = ^TData;
  13.   TData = record
  14.     FName: String;
  15.     FOcupation: String;
  16.     FYear: String;
  17.     FMarried: String;
  18.     FImageIndex: Integer;
  19.   end;
  20.  
  21.   { TForm1 }
  22.  
  23.   TForm1 = class(TForm)
  24.     BitBtn1: TBitBtn;
  25.     ImageList1: TImageList;
  26.     ImageList2: TImageList;
  27.     VST: TVirtualStringTree;
  28.     procedure BitBtn1Click(Sender: TObject);
  29.     procedure button1Click(Sender: TObject);
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure VSTAfterCellPaint(Sender: TBaseVirtualTree;
  32.       TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  33.       const CellRect: TRect);
  34.     procedure VSTClick(Sender: TObject);
  35.     procedure VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  36.       Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
  37.       var ImageIndex: Integer);
  38.     procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  39.       Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
  40.     procedure VSTNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  41.       Column: TColumnIndex; const NewText: String);
  42.     procedure VSTPaintText(Sender: TBaseVirtualTree;
  43.       const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  44.       TextType: TVSTTextType);
  45.   private
  46.    function GetSelectedNodeData2(var AData: PData): Boolean;
  47.   public
  48.  
  49.   end;
  50.  
  51. var
  52.   Form1: TForm1;
  53.  
  54. implementation
  55.  
  56. {$R *.lfm}
  57.  
  58.  
  59. function TForm1.GetSelectedNodeData2(var AData: PData): Boolean;  // code of getmem...
  60. var
  61.   Node: PVirtualNode;
  62. begin
  63.   Node := VST.GetFirstSelected;
  64.   if Node <> nil then
  65.   begin
  66.     AData := VST.GetNodeData(Node);
  67.     Result := True;
  68.   end
  69.   else
  70.   Begin
  71.     //MessageDlg('Please select a node first!', mtInformation, [mbOk], 0);
  72.     Result := False;
  73.   end;
  74. end;
  75.  
  76. procedure TForm1.button1Click(Sender: TObject);
  77. begin
  78.  
  79. end;
  80.  
  81. procedure TForm1.BitBtn1Click(Sender: TObject);
  82. var
  83.   Data: PData;
  84.   Node: PVirtualNode;
  85. begin
  86.   if not GetSelectedNodeData2(Data) then
  87.   Exit;
  88.   begin
  89.     //ShowMessage(Data^.FName+', '+Data^.FOcupation+', '+Data^.FYear+', '+Data^.FMarried);
  90.  
  91.     ShowMessage(Data^.FName);
  92.     {ShowMessage(Data^.FOcupation);
  93.     ShowMessage(Data^.FYear);
  94.     ShowMessage(Data^.FMarried);}
  95.   end;
  96. end;
  97.  
  98. procedure TForm1.VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  99.   Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
  100.   var ImageIndex: Integer);
  101. var
  102.   Data: PData;
  103. begin
  104.   if Column = 0 then
  105.   begin
  106.     Data := VST.GetNodeData(Node);
  107.     ImageIndex := Data^.FImageIndex;
  108.   end;
  109. end;
  110.  
  111. procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  112.   Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
  113. var
  114.   Data: PData;
  115. begin
  116.   Data := VST.GetNodeData(Node);
  117.   case Column of
  118.     0: CellText := '';
  119.     1: CellText := Data^.FName;
  120.     2: CellText := Data^.FOcupation;
  121.     3: CellText := Data^.FYear;
  122.     4: CellText := Data^.FMarried;
  123.   end;
  124. end;
  125.  
  126. procedure TForm1.VSTNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  127.   Column: TColumnIndex; const NewText: String);
  128. begin
  129.  
  130. end;
  131.  
  132. procedure TForm1.VSTPaintText(Sender: TBaseVirtualTree;
  133.   const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  134.   TextType: TVSTTextType);
  135. begin
  136.  
  137. end;
  138.  
  139. procedure TForm1.FormCreate(Sender: TObject);
  140. const
  141. pbColumnIndex = 1;
  142. pbMax = 100;
  143. var
  144. pb : TBitBtn;
  145. pbRect : TRect;
  146.  
  147.   Data: PData;
  148.   Node: PVirtualNode;
  149. begin
  150. //BitBtn1.Parent := vst;
  151.  
  152.   VST.Clear;
  153.   VST.NodeDataSize := SizeOf(TData);
  154.   Node := VST.AddChild(nil);
  155.   Data := VST.GetNodeData(Node);
  156.   VST.MultiLine[node] := true;
  157.   Data^.FName := 'erick, '#13'student, '+'18, '+'no';
  158.   {Data^.FName := 'erick';
  159.   Data^.FOcupation := 'student';
  160.   Data^.FYear := '18';
  161.   Data^.FMarried := 'no';}
  162.   Data^.FImageIndex := 0;
  163.         begin
  164.         pb := TBitBtn.Create(nil);
  165.         pb.Parent := vst;
  166.         pbRect := vst.GetDisplayRect(Node, 2{ColumnID if you Have}, false);
  167.         pb.Left := pbRect.Left;
  168.         pb.Top := pbRect.Top+2;
  169.         pb.Width := pbRect.Width;
  170.         ImageList2.GetBitmap(0, pb.Glyph);
  171.         pb.Caption:='Get Data';
  172.         End;
  173.  
  174.   Node := VST.AddChild(nil);
  175.   Data := VST.GetNodeData(Node);
  176.   VST.MultiLine[node] := true;
  177.   Data^.FName := 'magui, '#13'enfermera, '+'25, '+'si';
  178.   {Data^.FName := 'magui';
  179.   Data^.FOcupation := 'enfermera';
  180.   Data^.FYear := '25';
  181.   Data^.FMarried := 'si';
  182.   Data^.FImageIndex := 1;}
  183.         begin
  184.         pb := TBitBtn.Create(nil);
  185.         pb.Parent := vst;
  186.         pbRect := vst.GetDisplayRect(Node, 2{ColumnID if you Have}, false);
  187.         pb.Left := pbRect.Left;
  188.         pb.Top := pbRect.Top+2;
  189.         pb.Width := pbRect.Width;
  190.         ImageList2.GetBitmap(0, pb.Glyph);
  191.         pb.Caption:='Get Data';
  192.         End;
  193.  
  194.   Node := VST.AddChild(nil);
  195.   Data := VST.GetNodeData(Node);
  196.   VST.MultiLine[node] := true;
  197.   Data^.FName := 'leo, '#13'ingenier, '+'30, '+'si';
  198.   {Data^.FName := 'leo';
  199.   Data^.FOcupation := 'ingenier';
  200.   Data^.FYear := '30';
  201.   Data^.FMarried := 'si';}
  202.   Data^.FImageIndex := 2;
  203.         begin
  204.         pb := TBitBtn.Create(nil);
  205.         pb.Parent := vst;
  206.         pbRect := vst.GetDisplayRect(Node, 2{ColumnID if you Have}, false);
  207.         pb.Left := pbRect.Left;
  208.         pb.Top := pbRect.Top+2;
  209.         pb.Width := pbRect.Width;
  210.         ImageList2.GetBitmap(0, pb.Glyph);
  211.         pb.Caption:='Get Data';
  212.         End;
  213.  
  214. end;
  215.  
  216. procedure TForm1.VSTAfterCellPaint(Sender: TBaseVirtualTree;
  217.   TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  218.   const CellRect: TRect);
  219. begin
  220. end;
  221.  
  222. procedure TForm1.VSTClick(Sender: TObject);
  223. begin
  224.   ShowMessage('hi');
  225. end;
  226. end.

GetMem

  • Hero Member
  • *****
  • Posts: 2327
Re: How to use this appearance in VirtualTreeView
« Reply #9 on: August 15, 2017, 09:13:32 pm »
Here you go:
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   windows, Classes, SysUtils, VirtualTrees, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   StdCtrls, Buttons, ComCtrls;
  10.  
  11. type
  12.   PData = ^TData;
  13.   TData = record
  14.     FName: String;
  15.     FOcupation: String;
  16.     FYear: String;
  17.     FMarried: String;
  18.     FImageIndex: Integer;
  19.     Button: TSpeedButton;
  20.     ButtonID: Integer;
  21.   end;
  22.  
  23.   { TForm1 }
  24.  
  25.   TForm1 = class(TForm)
  26.     BitBtn1: TBitBtn;
  27.     ImageList1: TImageList;
  28.     ImageList2: TImageList;
  29.     VST: TVirtualStringTree;
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure VSTAfterCellPaint(Sender: TBaseVirtualTree;
  32.       {%H-}TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  33.       const {%H-}CellRect: TRect);
  34.     procedure VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  35.       {%H-}Kind: TVTImageKind; Column: TColumnIndex; var {%H-}Ghosted: Boolean;
  36.       var ImageIndex: Integer);
  37.     procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  38.       Column: TColumnIndex; {%H-}TextType: TVSTTextType; var CellText: String);
  39.   private
  40.    procedure CreateButton(AUniqueID: Integer; AData: PData);
  41.    procedure ButtonClick(Sender: TObject);
  42.   public
  43.  
  44.   end;
  45.  
  46. var
  47.   Form1: TForm1;
  48.  
  49. implementation
  50.  
  51. {$R *.lfm}
  52.  
  53. procedure TForm1.VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  54.   Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
  55.   var ImageIndex: Integer);
  56. var
  57.   Data: PData;
  58. begin
  59.   if Column = 0 then
  60.   begin
  61.     Data := VST.GetNodeData(Node);
  62.     ImageIndex := Data^.FImageIndex;
  63.   end;
  64. end;
  65.  
  66. procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  67.   Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
  68. var
  69.   Data: PData;
  70. begin
  71.   Data := VST.GetNodeData(Node);
  72.   case Column of
  73.     0: CellText := '';
  74.     1: CellText := Data^.FName;
  75.     2: CellText := Data^.FOcupation;
  76.     3: CellText := Data^.FYear;
  77.     4: CellText := Data^.FMarried;
  78.   end;
  79. end;
  80.  
  81. procedure TForm1.CreateButton(AUniqueID: Integer; AData: PData);
  82. begin
  83.   AData^.Button := TSpeedButton.Create(VST);
  84.   AData^.Button.Caption := 'Get Data';
  85.   AData^.Button.Parent := VST;
  86.   AData^.Button.Visible := False;
  87.   AData^.Button.Tag := AUniqueID;
  88.   AData^.Button.OnClick := @ButtonClick;
  89.   AData^.ButtonID := AUniqueID;
  90. end;
  91.  
  92. procedure TForm1.FormCreate(Sender: TObject);
  93. var
  94.   Data: PData;
  95.   Node: PVirtualNode;
  96.   UniqueID: Integer;
  97. begin
  98.   UniqueID := 0;
  99.   VST.Clear;
  100.   VST.NodeDataSize := SizeOf(TData);
  101.  
  102.   Node := VST.AddChild(nil);
  103.   Data := VST.GetNodeData(Node);
  104.   VST.MultiLine[node] := true;
  105.   Data^.FName := 'erick, '#13'student, '+'18, '+'no';
  106.   Data^.FImageIndex := 0;
  107.   Inc(UniqueID);
  108.   CreateButton(UniqueID, Data);
  109.  
  110.   Node := VST.AddChild(nil);
  111.   Data := VST.GetNodeData(Node);
  112.   VST.MultiLine[node] := true;
  113.   Data^.FName := 'magui, '#13'enfermera, '+'25, '+'si';
  114.   Data^.FImageIndex := 1;
  115.   Inc(UniqueID);
  116.   CreateButton(UniqueID, Data);
  117.  
  118.   Node := VST.AddChild(nil);
  119.   Data := VST.GetNodeData(Node);
  120.   VST.MultiLine[node] := true;
  121.   Data^.FImageIndex := 2;
  122.   Data^.FName := 'leo, '#13'ingenier, '+'30, '+'si';
  123.   Inc(UniqueID);
  124.   CreateButton(UniqueID, Data);
  125. end;
  126.  
  127. procedure TForm1.ButtonClick(Sender: TObject);
  128. var
  129.   Node: PVirtualNode;
  130.   Data: PData;
  131.   ButtonID: Integer;
  132. begin
  133.   ButtonID := (Sender as TSpeedButton).Tag;
  134.   Node := VST.GetFirst;
  135.   while Assigned(Node) do
  136.   begin
  137.     Data := VST.GetNodeData(Node);
  138.     if Data^.ButtonID = ButtonID then
  139.     begin
  140.       ShowMessage('Get data for: ' + Data^.FName);
  141.       Break;
  142.     end;
  143.     Node := VST.GetNext(Node);
  144.   end;
  145. end;
  146.  
  147. procedure TForm1.VSTAfterCellPaint(Sender: TBaseVirtualTree;
  148.   TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  149.   const CellRect: TRect);
  150. var
  151.   Data: PData;
  152.   R: TRect;
  153. begin
  154.   if Column = 2 then
  155.   begin
  156.     Data := VST.GetNodeData(Node);
  157.     if Assigned(Data^.Button) then
  158.     begin
  159.       R := VST.GetDisplayRect(Node, Column, False);
  160.       Data^.Button.Width  := R.Right - R.Left - 1;
  161.       Data^.Button.Left   := R.Left + 1;
  162.       Data^.Button.Top    := R.Top + 1;
  163.       Data^.Button.Height := R.Bottom - R.Top - 1;
  164.     end;
  165.     Data^.Button.Visible := VST.IsVisible[Node];
  166.   end
  167. end;
  168.  
  169. end.
  170.  

PS: For image columns is very similar: OnAfterPaint you just draw the images and that's all there is to it.

GetMem

  • Hero Member
  • *****
  • Posts: 2327
Re: How to use this appearance in VirtualTreeView
« Reply #10 on: August 15, 2017, 09:21:16 pm »
I almost forgot...you need to add this:
Code: Pascal  [Select]
  1. procedure TForm1.VSTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
  2. var
  3.   Data: PData;
  4. begin
  5.   Data := FVST.GetNodeData(Node);
  6.   if Assigned(Data^.Button) then
  7.     Data^.Button.Visible := False;
  8.   Finalize(Data^);
  9. end;

Ericktux

  • Full Member
  • ***
  • Posts: 142
Re: How to use this appearance in VirtualTreeView
« Reply #11 on: August 16, 2017, 06:48:02 am »
thankyou my friend, work fine  :D :D

Ericktux

  • Full Member
  • ***
  • Posts: 142
Re: How to use this appearance in VirtualTreeView
« Reply #12 on: August 16, 2017, 08:42:37 am »
Good friend Getmem, a question, because when I have several rows and then I go up and under the buttons are disordered.  :(

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   windows, Classes, SysUtils, VirtualTrees, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   StdCtrls, Buttons, ComCtrls;
  10.  
  11. type
  12.   PData = ^TData;
  13.   TData = record
  14.     FName: String;
  15.     FOcupation: String;
  16.     FYear: String;
  17.     FMarried: String;
  18.     FImageIndex: Integer;
  19.     Button: TSpeedButton;
  20.     ButtonID: Integer;
  21.   end;
  22.  
  23.   { TForm1 }
  24.  
  25.   TForm1 = class(TForm)
  26.     BitBtn1: TBitBtn;
  27.     ImageList1: TImageList;
  28.     ImageList2: TImageList;
  29.     VST: TVirtualStringTree;
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure VSTAfterCellPaint(Sender: TBaseVirtualTree;
  32.       {%H-}TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  33.       const {%H-}CellRect: TRect);
  34.     procedure VSTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
  35.     procedure VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  36.       {%H-}Kind: TVTImageKind; Column: TColumnIndex; var {%H-}Ghosted: Boolean;
  37.       var ImageIndex: Integer);
  38.     procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  39.       Column: TColumnIndex; {%H-}TextType: TVSTTextType; var CellText: String);
  40.   private
  41.    procedure CreateButton(AUniqueID: Integer; AData: PData);
  42.    procedure ButtonClick(Sender: TObject);
  43.   public
  44.  
  45.   end;
  46.  
  47. var
  48.   Form1: TForm1;
  49.  
  50. implementation
  51.  
  52. {$R *.lfm}
  53.  
  54. procedure TForm1.VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  55.   Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
  56.   var ImageIndex: Integer);
  57. var
  58.   Data: PData;
  59. begin
  60.   if Column = 0 then
  61.   begin
  62.     Data := VST.GetNodeData(Node);
  63.     ImageIndex := Data^.FImageIndex;
  64.   end;
  65. end;
  66.  
  67. procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  68.   Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
  69. var
  70.   Data: PData;
  71. begin
  72.   Data := VST.GetNodeData(Node);
  73.   case Column of
  74.     0: CellText := '';
  75.     1: CellText := Data^.FName;
  76.     2: CellText := Data^.FOcupation;
  77.     3: CellText := Data^.FYear;
  78.     4: CellText := Data^.FMarried;
  79.   end;
  80. end;
  81.  
  82. procedure TForm1.CreateButton(AUniqueID: Integer; AData: PData);
  83. begin
  84.   AData^.Button := TSpeedButton.Create(VST);
  85.   AData^.Button.Caption := 'Get Data';
  86.   AData^.Button.Parent := VST;
  87.   AData^.Button.Visible := False;
  88.   AData^.Button.Tag := AUniqueID;
  89.   AData^.Button.OnClick := @ButtonClick;
  90.   AData^.ButtonID := AUniqueID;
  91. end;
  92.  
  93. procedure TForm1.FormCreate(Sender: TObject);
  94. var
  95.   Data: PData;
  96.   Node: PVirtualNode;
  97.   UniqueID: Integer;
  98. begin
  99.   UniqueID := 0;
  100.   VST.Clear;
  101.   VST.NodeDataSize := SizeOf(TData);
  102.  
  103.   Node := VST.AddChild(nil);
  104.   Data := VST.GetNodeData(Node);
  105.   VST.MultiLine[node] := true;
  106.   Data^.FName := 'erick, '#13'student, '+'18, '+'no';
  107.   Data^.FImageIndex := 0;
  108.   Inc(UniqueID);
  109.   CreateButton(UniqueID, Data);
  110.  
  111.   Node := VST.AddChild(nil);
  112.   Data := VST.GetNodeData(Node);
  113.   VST.MultiLine[node] := true;
  114.   Data^.FName := 'magui, '#13'enfermera, '+'25, '+'si';
  115.   Data^.FImageIndex := 1;
  116.   Inc(UniqueID);
  117.   CreateButton(UniqueID, Data);
  118.  
  119.   Node := VST.AddChild(nil);
  120.   Data := VST.GetNodeData(Node);
  121.   VST.MultiLine[node] := true;
  122.   Data^.FImageIndex := 2;
  123.   Data^.FName := 'leo, '#13'ingenier, '+'30, '+'si';
  124.   Inc(UniqueID);
  125.   CreateButton(UniqueID, Data);
  126.  
  127.  
  128.  
  129.  
  130.   Node := VST.AddChild(nil);
  131.   Data := VST.GetNodeData(Node);
  132.   VST.MultiLine[node] := true;
  133.   Data^.FName := 'erick, '#13'student, '+'18, '+'no';
  134.   Data^.FImageIndex := 0;
  135.   Inc(UniqueID);
  136.   CreateButton(UniqueID, Data);
  137.  
  138.   Node := VST.AddChild(nil);
  139.   Data := VST.GetNodeData(Node);
  140.   VST.MultiLine[node] := true;
  141.   Data^.FName := 'magui, '#13'enfermera, '+'25, '+'si';
  142.   Data^.FImageIndex := 1;
  143.   Inc(UniqueID);
  144.   CreateButton(UniqueID, Data);
  145.  
  146.   Node := VST.AddChild(nil);
  147.   Data := VST.GetNodeData(Node);
  148.   VST.MultiLine[node] := true;
  149.   Data^.FImageIndex := 2;
  150.   Data^.FName := 'leo, '#13'ingenier, '+'30, '+'si';
  151.   Inc(UniqueID);
  152.   CreateButton(UniqueID, Data);
  153.  
  154.   Node := VST.AddChild(nil);
  155.   Data := VST.GetNodeData(Node);
  156.   VST.MultiLine[node] := true;
  157.   Data^.FName := 'erick, '#13'student, '+'18, '+'no';
  158.   Data^.FImageIndex := 0;
  159.   Inc(UniqueID);
  160.   CreateButton(UniqueID, Data);
  161.  
  162.   Node := VST.AddChild(nil);
  163.   Data := VST.GetNodeData(Node);
  164.   VST.MultiLine[node] := true;
  165.   Data^.FName := 'magui, '#13'enfermera, '+'25, '+'si';
  166.   Data^.FImageIndex := 1;
  167.   Inc(UniqueID);
  168.   CreateButton(UniqueID, Data);
  169.  
  170.   Node := VST.AddChild(nil);
  171.   Data := VST.GetNodeData(Node);
  172.   VST.MultiLine[node] := true;
  173.   Data^.FImageIndex := 2;
  174.   Data^.FName := 'leo, '#13'ingenier, '+'30, '+'si';
  175.   Inc(UniqueID);
  176.   CreateButton(UniqueID, Data);
  177.  
  178.   Node := VST.AddChild(nil);
  179.   Data := VST.GetNodeData(Node);
  180.   VST.MultiLine[node] := true;
  181.   Data^.FName := 'erick, '#13'student, '+'18, '+'no';
  182.   Data^.FImageIndex := 0;
  183.   Inc(UniqueID);
  184.   CreateButton(UniqueID, Data);
  185.  
  186.   Node := VST.AddChild(nil);
  187.   Data := VST.GetNodeData(Node);
  188.   VST.MultiLine[node] := true;
  189.   Data^.FName := 'magui, '#13'enfermera, '+'25, '+'si';
  190.   Data^.FImageIndex := 1;
  191.   Inc(UniqueID);
  192.   CreateButton(UniqueID, Data);
  193.  
  194.   Node := VST.AddChild(nil);
  195.   Data := VST.GetNodeData(Node);
  196.   VST.MultiLine[node] := true;
  197.   Data^.FImageIndex := 2;
  198.   Data^.FName := 'leo, '#13'ingenier, '+'30, '+'si';
  199.   Inc(UniqueID);
  200.   CreateButton(UniqueID, Data);
  201.  
  202.   Node := VST.AddChild(nil);
  203.   Data := VST.GetNodeData(Node);
  204.   VST.MultiLine[node] := true;
  205.   Data^.FName := 'erick, '#13'student, '+'18, '+'no';
  206.   Data^.FImageIndex := 0;
  207.   Inc(UniqueID);
  208.   CreateButton(UniqueID, Data);
  209.  
  210.   Node := VST.AddChild(nil);
  211.   Data := VST.GetNodeData(Node);
  212.   VST.MultiLine[node] := true;
  213.   Data^.FName := 'magui, '#13'enfermera, '+'25, '+'si';
  214.   Data^.FImageIndex := 1;
  215.   Inc(UniqueID);
  216.   CreateButton(UniqueID, Data);
  217.  
  218.   Node := VST.AddChild(nil);
  219.   Data := VST.GetNodeData(Node);
  220.   VST.MultiLine[node] := true;
  221.   Data^.FImageIndex := 2;
  222.   Data^.FName := 'leo, '#13'ingenier, '+'30, '+'si';
  223.   Inc(UniqueID);
  224.   CreateButton(UniqueID, Data);
  225. end;
  226.  
  227. procedure TForm1.ButtonClick(Sender: TObject);
  228. var
  229.   Node: PVirtualNode;
  230.   Data: PData;
  231.   ButtonID: Integer;
  232. begin
  233.   ButtonID := (Sender as TSpeedButton).Tag;
  234.   Node := VST.GetFirst;
  235.   while Assigned(Node) do
  236.   begin
  237.     Data := VST.GetNodeData(Node);
  238.     if Data^.ButtonID = ButtonID then
  239.     begin
  240.       ShowMessage('Get data for: ' + Data^.FName);
  241.       Break;
  242.     end;
  243.     Node := VST.GetNext(Node);
  244.   end;
  245. end;
  246.  
  247.  
  248. procedure TForm1.VSTAfterCellPaint(Sender: TBaseVirtualTree;
  249.   TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  250.   const CellRect: TRect);
  251. var
  252.   Data: PData;
  253.   R: TRect;
  254. begin
  255.   if Column = 2 then
  256.   begin
  257.     Data := VST.GetNodeData(Node);
  258.     if Assigned(Data^.Button) then
  259.     begin
  260.       R := VST.GetDisplayRect(Node, Column, False);
  261.       Data^.Button.Width  := R.Right - R.Left - 1;
  262.       Data^.Button.Left   := R.Left + 1;
  263.       Data^.Button.Top    := R.Top + 1;
  264.       Data^.Button.Height := R.Bottom - R.Top - 1;
  265.     end;
  266.     Data^.Button.Visible := VST.IsVisible[Node];
  267.   end
  268. end;
  269.  
  270. procedure TForm1.VSTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
  271. var
  272.   Data: PData;
  273. begin
  274.   Data := VST.GetNodeData(Node);
  275.   if Assigned(Data^.Button) then
  276.     Data^.Button.Visible := False;
  277.   Finalize(Data^);
  278. end;
  279. end.
  280.  

How can I solve it my friend.  :(

Attached image and project

GetMem

  • Hero Member
  • *****
  • Posts: 2327
Re: How to use this appearance in VirtualTreeView
« Reply #13 on: August 16, 2017, 10:14:20 pm »
@Ericktux
You owe me a beer for this one.
« Last Edit: August 16, 2017, 10:18:02 pm by GetMem »

Ericktux

  • Full Member
  • ***
  • Posts: 142
Re: How to use this appearance in VirtualTreeView
« Reply #14 on: August 17, 2017, 06:22:16 am »
Wooww is beautiful  :o :o :o
Of course my friend  8)


I'm going to try it  :)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus