Recent

Author Topic: Treeview issue  (Read 1139 times)

Rafael.Castro

  • Newbie
  • Posts: 5
Treeview issue
« on: November 17, 2021, 09:38:24 pm »
I'm sorry I don't know how the order of things works but I would like to comment that the treeview component does not work 100%.

I send file

Code:

TreeView.LoadFromFile( 'tree.txt') ;

Thanks and apologies

CHR$(20)
« Last Edit: November 17, 2021, 09:50:18 pm by Rafael.Castro »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Treeview issue
« Reply #1 on: November 17, 2021, 10:10:26 pm »
No, the treeview works correctly, your data file is faulty.

Load the data file into the IDE (you must select file filter "All files" to see the text file), switch the editor to display special characters ("Tools" > " Options" > "Editor" > "General" > "Miscellaneous" > check "Show special characters" in the "Editor options" box). Now you see the tab characters as double arrows ">>" and spaces as a centered dot. Scroll towards the end of the file. The offending line is #39890. The text is "Animals.localized" but there is a space between the last tab and the "Animals". When you remove this space and repeat this with the lines for "Business", "Food", "Household", "People" and "Special" the file will load without error.

Why is this space harmful? The treeview reads the lines into a stringlist, and then extracts the node level and the node text by means of the TTreeStrings method GetBufStart:
Code: Pascal  [Select][+][-]
  1. function TTreeStrings.GetBufStart(Buffer: PChar; var Level: Integer): PChar;
  2. begin
  3.   Level := 0;
  4.   while Buffer^ in [' ', #9] do
  5.   begin
  6.     Inc(Buffer);
  7.     Inc(Level);
  8.   end;
  9.   Result := Buffer;
  10. end;  
You see the "while" condition? This means that the node level is determined by the number of spaces (' ') and tabs  (#9) before the non-white text. Having an additional space here has the consequence that this node has no parent, and this must crash the reading process.

How did you create this file? Please check your code.
« Last Edit: November 17, 2021, 10:34:34 pm by wp »

Rafael.Castro

  • Newbie
  • Posts: 5
Re: Treeview issue
« Reply #2 on: November 18, 2021, 01:27:07 am »
Good morning WP

Thank you for your help

But...  ;D

The code I use to scan the drives is the classic TSearchRec.
Everything that TsearchRec sees I save in a text file and when I generate the treeview it is based on what TsearchRec has created.
Today I received this error from a Mac user. I noticed that the character 20 was in front of the name, which I don't understand, but it crashes treeview.
That is, the results I get from TSearchRec are crashing Treeview.

The databases are already created with the chr$20. What do you recommend ?
Thanks

.. Index Your Files

Translated with www.DeepL.com/Translator (free version)

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Treeview issue
« Reply #3 on: November 18, 2021, 06:45:48 pm »
The code I use to scan the drives is the classic TSearchRec.
Everything that TsearchRec sees I save in a text file and when I generate the treeview it is based on what TsearchRec has created.
Today I received this error from a Mac user. I noticed that the character 20 was in front of the name, which I don't understand, but it crashes treeview.
That is, the results I get from TSearchRec are crashing Treeview.

The databases are already created with the chr$20. What do you recommend ?
I am almost absolutely sure that the spaces are added somewhere by your code. Therefore, I can only say: study your code. Or post the code how you populate the TreeView with the SearchRec values, otherwise nobody can help.

If you want to ask further questions on this please put them into a new thread and refer to this one. This thread is about the v2.2 release candidate, and your problems do not have to do anything with the new version.

Rafael.Castro

  • Newbie
  • Posts: 5
Re: Treeview issue
« Reply #4 on: November 19, 2021, 09:59:19 pm »
Hello wp

Apologies for posting this post in the wrong place.
I have found that the same error occurs with the latest version of Delphi.

Everything makes me think that I'm on the wrong track.

But...

On Mac it is allowed to start files with blank spaces.
Linux and Windows do not.

'     hello word' is OK for Mac
'space space space space  hello word' is OK for Mac

Create Folder '           hola' is ok
Create Folder 'space space space etc hola' is ok

So, I see that Treeview fails at the Global level.

The solution I know is to remove all spaces from the beginning of the file on Mac.

Thanks for your help and forgive my recklessness.

Translated with www.DeepL.com/Translator (free version)
« Last Edit: November 19, 2021, 10:40:59 pm by Rafael.Castro »

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Treeview issue
« Reply #5 on: November 19, 2021, 10:37:09 pm »
If Memory serves I believe the Space in the Tree view when loading from file is uses to indicate a child node.

I could be wrong here but that seems to ring a bell.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018