Recent

Author Topic: Convert vb6 TreeNodes to Pascal TreeNodes  (Read 1871 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Convert vb6 TreeNodes to Pascal TreeNodes
« on: October 23, 2020, 08:32:17 am »
Hey Guys,

hope u all having a good Day. So lately i was Converting old vb6 Code to Pascal Code, until i came to this code Section:

Code: Pascal  [Select][+][-]
  1.  
  2. For Each nd In AClass.TreeViewZ(Index).Nodes
  3.         If nd.Bold = True Then
  4.             yn = False
  5.             Set nodX = nd.Child
  6.             For i = 1 To nd.Children
  7.                 If nodX.Checked = True Then
  8.                     yn = True
  9.                 End If
  10.                 Set nodX = nodX.Next
  11.             Next i
  12.             If yn = True Then
  13.                 nd.Checked = True
  14.             Else
  15.                 nd.Checked = False
  16.             End If
  17.         End If
  18.     Next

i Dont know how this Code works in free Pascal. I went through some Tutorials but nothing helped.

Please Help   :-\
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Convert vb6 TreeNodes to Pascal TreeNodes
« Reply #1 on: October 23, 2020, 11:06:18 am »
The code iterates through all "bold" nodes of the treeview and checks those nodes which have checked child nodes. Since you do not show the entire procedure I cannot tell whether these checks are restricted only to the node and its direct children, or whether the entire tree is affected.

AFAIK the LCL treeview does not support checkboxes. But using an imagelist with checked and unchecked icons you can easily imitate the effect. You'll have to write some code which selects the checked or unchecked image. Please look at the attached demo which contains routines to check the top-level parent if any of its children is checked. It is a nice exercise in recursive programming.
« Last Edit: October 23, 2020, 11:09:25 am by wp »

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Convert vb6 TreeNodes to Pascal TreeNodes
« Reply #2 on: October 27, 2020, 09:25:01 am »
Thank u wp, this was very helpful :) Any Idea how to make those Captions of the Checkboxes Bold ?
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Convert vb6 TreeNodes to Pascal TreeNodes
« Reply #3 on: October 27, 2020, 09:59:28 am »
You can add a handler for the OnCustomDrawItem event which sets the Canvas.Font to bold when required. The following code draws the checked top-level node in bold:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
  2.   Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
  3. begin
  4.   if NodeChecked(Node) and (Node.Parent = nil) then
  5.     Sender.Canvas.Font.Style := [fsBold]
  6.   else
  7.     Sender.Canvas.Font.Style := [];
  8.   DefaultDraw := true;
  9. end;

Tested to work on Windows. Not sure about the other widgetsets -- I know about a bold-issue with the similar TListView.
« Last Edit: October 27, 2020, 10:01:14 am by wp »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Convert vb6 TreeNodes to Pascal TreeNodes
« Reply #4 on: October 27, 2020, 10:05:29 am »
Tested to work on Windows. Not sure about the other widgetsets -- I know about a bold-issue with the similar TListView.
It will work because LCL's TTreeView is a custom drawn component.
TListView is not. It maps to native controls which is challenging with such a complex component.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Convert vb6 TreeNodes to Pascal TreeNodes
« Reply #5 on: October 27, 2020, 11:25:28 am »
Thank u Guys
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

 

TinyPortal © 2005-2018