Recent

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

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: How to use this appearance in VirtualTreeView
« Reply #15 on: August 17, 2017, 07:52:36 am »
Thank you very much my friend Getmem, it works excellent  :D :D
I owe you a beer  8)

Attached image and my practices.

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: How to use this appearance in VirtualTreeView
« Reply #16 on: August 21, 2017, 07:35:27 pm »
Quote
At the end of searching all its dependencies I get the blank example.

Sorry, fixed that

Quote
You owe me a beer for this one.

@getmem can i add this example to VTV repository?

balazsszekely

  • Guest
Re: How to use this appearance in VirtualTreeView
« Reply #17 on: August 21, 2017, 10:00:38 pm »
@LuizAmérico
Quote
@getmem can i add this example to VTV repository?
Sure. I made it cross platform, the original code contained a lot of windows specific stuff + I did a little cleanup(see attachment).

« Last Edit: August 21, 2017, 10:02:51 pm by GetMem »

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: How to use this appearance in VirtualTreeView
« Reply #18 on: August 22, 2017, 03:07:16 am »
Quote
Sure. I made it cross platform, the original code contained a lot of windows specific stuff + I did a little cleanup(see attachment).

Thanks. I already had made cross platform, but i will use your last version.

I will put a coyright notice linking to this thread

balazsszekely

  • Guest
Re: How to use this appearance in VirtualTreeView
« Reply #19 on: August 22, 2017, 06:18:17 am »
@LuizAmérico
Quote
I will put a coyright notice linking to this thread
That's really not necessary. Feel free to use it anyway you like.

PS: A few days ago @Thaddy created a patch, which enables VST to work on arm-linux. Please take a look at  r.55658. You can add it to VST 4.x.x, 5.x.x if you like.

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: How to use this appearance in VirtualTreeView
« Reply #20 on: August 22, 2017, 10:10:19 pm »
I saw that patch. I will update with a few more improvements

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: How to use this appearance in VirtualTreeView
« Reply #21 on: September 08, 2017, 11:17:23 am »
Hi my friends, I have been practicing with the project and I have managed to integrate several components such as:
- Add items (success) 
- Edit items (success) 
- Filter Items (success)
- Sort columns (success) 
- Save and open data (error)  :(

All codes I use are from the friend "getmem"
please help me, how can I save and open without error

PD: attached images and Project.

the rarest thing is that save and open works while not closing the application, if I close the application no longer opens.
« Last Edit: September 08, 2017, 11:20:38 am by Ericktux »

balazsszekely

  • Guest
Re: How to use this appearance in VirtualTreeView
« Reply #22 on: September 08, 2017, 12:58:23 pm »
@Ericktux

You're mixing an old version with the new one. In the latest version, the nodes are created via CreateNode method, you have to take it into account when you're loading VST from file.

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: How to use this appearance in VirtualTreeView
« Reply #23 on: September 08, 2017, 06:56:52 pm »
Ok friend, I'll keep trying and tell you my progress.

these are the codes that you shared to me a while ago and that I am using them:

Code: Pascal  [Select][+][-]
  1. procedure TfMain.saveBTClick(Sender: TObject);  // for save
  2. var
  3.   FS: TFileStream;
  4.   Node: PVirtualNode;
  5.   Data: PData;
  6. begin
  7.   if VDT.RootNodeCount = 0 then
  8.   begin
  9.     MessageDlg('The list is empty. Nothing to save.', mtInformation, [mbOk], 0);
  10.     Exit;
  11.   end;
  12.  
  13.   if not SD.Execute then
  14.     Exit;
  15.  
  16.   FS := TFileStream.Create(SD.FileName, fmCreate or fmShareDenyWrite);
  17.   try
  18.     FS.WriteWord(VDT.RootNodeCount);
  19.     Node := VDT.GetFirst;
  20.     while Assigned(Node) do
  21.     begin
  22.       Data := VDT.GetNodeData(Node);
  23.       FS.Write(Data^, SizeOf(TData));
  24.       Node := VDT.GetNext(Node);
  25.     end;
  26.   finally
  27.     FS.Free;
  28.   end;
  29. end;
  30.  
  31. procedure TfMain.loadBTClick(Sender: TObject);  // for load
  32. var
  33.   FS: TFileStream;
  34.   Node: PVirtualNode;
  35.   Data: PData;
  36.   Cnt, I: Integer;
  37. begin
  38.   if not OD.Execute then
  39.     Exit;
  40.  
  41.   VDT.Clear;
  42.   VDT.NodeDataSize := SizeOf(TData);
  43.  
  44.   FS := TFileStream.Create(OD.FileName, fmOpenRead or fmShareDenyNone);
  45.   try
  46.     Cnt := FS.ReadWord;
  47.     if Cnt > 0 then
  48.     begin
  49.       I := 1;
  50.       while I <= Cnt do
  51.       begin
  52.         Node := VDT.AddChild(nil);
  53.         Data := VDT.GetNodeData(Node);
  54.         FS.Read(Data^, SizeOf(TData));
  55.         Inc(I);
  56.       end;
  57.     end;
  58.   finally
  59.     FS.Free;
  60.   end;
  61. end;  


as I said yesterday, the rarest thing is that if I do not close the application it opens the file well, but if I close it, I get an error when I open the file.  :(

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to use this appearance in VirtualTreeView
« Reply #24 on: September 09, 2017, 03:47:59 am »
Your shortcut of saving your data does not work on dynamic data types. In your case the problematic data types are the string and TSpeedButton. In the case of the string it might be easily fixed by converting all strings to short string alhtouhg you will get an upper limit of 255 characters per field on the case of TSpeedButton depends on what it is. Is it a speed button that is created at design time or it is dynamically created at runtime? if the later then don't save it at all just read the data from the file and recreate the speed button.

If the above are not acceptable then you have to write a routine that will save each field one by one and load them one by one when you hit the speed button you use the stream's WriteComponent method.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: How to use this appearance in VirtualTreeView
« Reply #25 on: September 14, 2017, 09:11:21 am »
Good friends, thanks for the advice, I have managed to save and open the data as follows:  :)  :)

we create procedure:
Code: Pascal  [Select][+][-]
  1.   public
  2.     ....
  3.     procedure reload_buttons;
  4.   end;
  5.  
  6. ....
  7. procedure TfMain.reload_buttons;
  8. var
  9.    node : PVirtualNode ;
  10.    Data: PData;
  11.    total: integer;
  12. begin
  13.   total := 0;
  14.   node := VDT.GetFirst ;
  15.   while assigned (node) do
  16.       begin
  17.       inc(total,VDT.ChildCount [node] + 1);
  18.       Data := VDT.GetNodeData(Node);
  19.       CreateButton(total, Data);
  20.       node := VDT.GetNext(node) ;
  21.       end;
  22.       //vst.setfocus;
  23.       //vst.Refresh;
  24. end;
  25.  

virtualtreeview event to save

Code: Pascal  [Select][+][-]
  1. procedure TfMain.VDTSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
  2.   Stream: TStream);
  3. var
  4.    data: Pdata;
  5.    len: Integer;
  6. begin
  7. Data := VDT.GetNodeData(Node);
  8. Len := Length(Data^.FName);
  9. Stream.Write(Len, SizeOf(Len));
  10. Stream.Write(PChar(Data^.FName)^, Length(Data^.FName) * SizeOf(Char));
  11.  
  12. Len := Length(Data^.FDescription);
  13. Stream.Write(Len, SizeOf(Len));
  14. Stream.Write(PChar(Data^.FDescription)^, Length(Data^.FDescription) * SizeOf(Char));
  15.  
  16. Stream.Write(Data^.FBunnyCount, SizeOf(Data^.FBunnyCount));
  17. //Stream.Write(Data^.Button, SizeOf(Data^.Button));
  18. Stream.Write(Data^.FImageIndex, SizeOf(Data^.FImageIndex));
  19. End;

virtualtreeview event to load

Code: Pascal  [Select][+][-]
  1. procedure TfMain.VDTLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
  2.   Stream: TStream);
  3.  
  4.   var
  5.   Data: Pdata;
  6.   Len: Integer;
  7. begin
  8.   Data := VDT.GetNodeData(Node);
  9. Stream.Read(Len, SizeOf(Len));
  10. SetLength(Data^.FName, Len);
  11. Stream.Read(PChar(Data^.FName)^, Len * SizeOf(Char));
  12.  
  13. Stream.Read(Len, SizeOf(Len));
  14. SetLength(Data^.FDescription, Len);
  15. Stream.Read(PChar(Data^.FDescription)^, Len * SizeOf(Char));
  16.  
  17. stream.Read(Data^.FBunnyCount, SizeOf(Data^.FBunnyCount));
  18. //stream.Read(Data^.Button, SizeOf(Data^.Button));
  19. Stream.Read(Data^.FImageIndex, SizeOf(Data^.FImageIndex));
  20. end;

use:

Code: Pascal  [Select][+][-]
  1. procedure TfMain.saveBTClick(Sender: TObject);
  2. begin
  3.   VDT.SaveToFile('filename.dat');
  4. end;
  5.  
  6. procedure TfMain.loadBTClick(Sender: TObject);
  7. begin
  8.   VDT.LoadFromFile('filename.dat');
  9.   reload_buttons;  // to draw the buttons
  10. end;

Work fine at the moment  :) :)
Please correct me if I skip something
attached project.
« Last Edit: September 14, 2017, 09:03:11 pm by Ericktux »

Wargan

  • New Member
  • *
  • Posts: 48
    • 'This way' site
Re: How to use this appearance in VirtualTreeView
« Reply #26 on: September 25, 2017, 07:23:10 am »
Friends, I downloaded an example from GetMem (VDT_OwnerDraw.zip) and tested it on 600 dynamically created nodes. The result was sad, since rendering and loading into memory of such a quantity TSpeedButton just killed my comp  :o

How can I make the dynamic creation of a TSpeedButton in the right column?

Algorithm:
You select node in the Virtual Tree and button is creating "on the fly". When you select another node - the old button is released and created in the new one etc.

p.s. sorry, i'm newbie :-[
Lazarus 1.8RC5+ FPC 3.0.4.
Windows 7 x32, RAM 3 Gb.

balazsszekely

  • Guest
Re: How to use this appearance in VirtualTreeView
« Reply #27 on: September 25, 2017, 07:55:19 am »
Hi Wargan,

Quote
Friends, I downloaded an example from GetMem (VDT_OwnerDraw.zip) and tested it on 600 dynamically created nodes. The result was sad, since rendering and loading into memory of such a quantity TSpeedButton just killed my comp  :o
No surprise here! Creating 600 TSpeedButton requires a lot of memory. I just implemented what @Ericktux requested(VST with buttons), without testing it in a real life scenario. However there is a workaround, you can draw a button like Image, change it on mouse over, mouse click, etc... It will look/feel like a real button without consuming too much memory, you have to do a lot of work though.

Quote
How can I make the dynamic creation of a TSpeedButton in the right column?
There is a focus change event, you can create/free the button there.

Wargan

  • New Member
  • *
  • Posts: 48
    • 'This way' site
Re: How to use this appearance in VirtualTreeView
« Reply #28 on: September 26, 2017, 11:18:00 am »
Hi, GetMem.
Perhaps you'll give me the code?
Honestly - I think that I can't dynamically free memory for TSpeedButton.
Lazarus 1.8RC5+ FPC 3.0.4.
Windows 7 x32, RAM 3 Gb.

balazsszekely

  • Guest
Re: How to use this appearance in VirtualTreeView
« Reply #29 on: September 26, 2017, 11:59:26 am »
Quote
Perhaps you'll give me the code?
Honestly - I think that I can't dynamically free memory for TSpeedButton.
But why it is so hard? As I said in my previous post, you can move the creation of the button to OnFocusChanged, like this:
Code: Pascal  [Select][+][-]
  1. procedure TfMain.VDTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
  2.   Column: TColumnIndex);
  3. var
  4.   Data: PData;
  5. begin
  6.  if FOldNode <> nil then
  7.  begin
  8.    Data := VDT.GetNodeData(FOldNode);
  9.    if Data^.Button <> nil then
  10.    begin
  11.      Data^.Button.Free;
  12.      Data^.Button := nil;
  13.    end;
  14.  end;
  15.  
  16.  Data := VDT.GetNodeData(Node);
  17.  Data^.Button := TSpeedButton.Create(VDT);
  18.  with Data^.Button do
  19.  begin
  20.    Caption := 'Get Data';
  21.    Parent := VDT;
  22.    Tag := Data^.ButtonID;
  23.    Visible := True;
  24.    OnClick := @ButtonClick;
  25.    imButton.GetBitmap(0, Glyph);
  26.  end;
  27.  FOldNode := Node;
  28. end;

 

TinyPortal © 2005-2018