Recent

Author Topic: VirtualTreeview node.parent "illegaler qualifier"  (Read 3750 times)

nogo

  • Newbie
  • Posts: 5
VirtualTreeview node.parent "illegaler qualifier"
« on: August 15, 2017, 02:45:51 pm »
Hello,

just try to follow the example from Lischke's book: "Treeview tutorial"

Quote
Determine the parent
Every node (PVirtualNode) has the property parent. This property points to the parent of
the node. The parent property of a root-node will point to the tree. To differentiate a
root-node from a normal node you can use the following:
Code: Pascal  [Select][+][-]
  1. var
  2. Node: PVirtualNode;
  3. begin
  4. if not Assigned(vst.FocusedNode) then
  5. exit;
  6. Node:=vst.FocusedNode;
  7. while vst.GetNodeLevel(Node)>0 do
  8. Node:=Node.Parent;
  9. end;


Coming from a bigger project, I've broken it down to a small project:
One VirtualStringTree, one button and this code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3. node: PVirtualNode;
  4.  
  5. begin
  6.   node:= VirtualStringTree1.AddChild(nil);
  7.   node:= VirtualStringTree1.AddChild(node);
  8.   node:=node.
  9. end;                          
  10.  


Now the question:

just entering the last "." waiting for the List just failure occurs with "illegal qualifier".
What do I do wrong?


taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: VirtualTreeview node.parent "illegaler qualifier"
« Reply #1 on: August 15, 2017, 03:01:24 pm »
just entering the last "." waiting for the List just failure occurs with "illegal qualifier".
What do I do wrong?
You do not dereference the pointer variable eg.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3. node: PVirtualNode;
  4.  
  5. begin
  6.   node:= VirtualStringTree1.AddChild(nil);
  7.   node:= VirtualStringTree1.AddChild(node);
  8.   node:=node^.
  9. end;                          
  10.  
note the "^" character before the "." character. In delphi mode the compiler will auto dereference typed pointer variables for you the same way it dereferences object variables for you. In fpc mode you have to do it manually.
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

nogo

  • Newbie
  • Posts: 5
Re: VirtualTreeview node.parent "illegaler qualifier"
« Reply #2 on: August 16, 2017, 08:29:01 am »
Many thanks taazz,

now I do understand and can carry on,

regards,

nogo

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: VirtualTreeview node.parent "illegaler qualifier"
« Reply #3 on: March 04, 2018, 08:39:26 am »
Hi

@Taazz thank you

but in wiki.freepascal.org doesn't write "^"??!!


  • Determine Parent
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button13Click(Sender: TObject);
  2. var
  3.   XNode: PVirtualNode;
  4. begin
  5.   if not Assigned(VST.FocusedNode) then
  6.     Exit;
  7.   XNode := VST.FocusedNode;
  8.   while VST.GetNodeLevel(XNode) > 0 do
  9.   begin
  10.     XNode := XNode.Parent;
  11.     VST.Selected[XNode] := True;
  12.   end;
  13.   VST.Refresh;
  14.   VST.SetFocus;
  15. end;
  16.  

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: VirtualTreeview node.parent "illegaler qualifier"
« Reply #4 on: March 04, 2018, 09:52:39 am »
add
Code: Pascal  [Select][+][-]
  1. {$ModeSwitch AutoDeref}
on top of your unit to avoid using ^ .
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

 

TinyPortal © 2005-2018