How do I search a large database contained in a Delphi TTreeView?

I have a large databse contained in a Delphi 7 TTreeView.  The database contains equipment with parameters situated on different floors in different buildings on different sites.  The structure of the databse is as follows:
Heading - Level 0
   Site - Level 1
      Building - Level 2
         Floor In Building - Level 3
             Equipment on Floor - Level 4
                  Parameters of Equipment - Level 5

The bulk of the data is on the Equipment Parameter  level  5, where some of the equipment may contain up to 150 lines of parameter information.  The total database is now over 140000 lines in the TTReeView.

I need to search for specific equipment in specific buildings.  When the databse was small my program worked quite well as searching entails the program reading through all the lines when searching for a piecei of equipment.  With the larger size of the database however this in now very slow.

Is there a way to construct some indexing or other methods where the program will be able to search from the index for a building, floor and equipment without having to read through every line on especailly level 5, taking into account that the program is dynamic where equipment on level 4 is constantly added or removed?
Who is Participating?
HenryM2Connect With a Mentor Author Commented:
Thanks to all that participated with offers of advice.  Unfortunately the proposed solutions would require major changes to my program.  I therefore wrote my own simple indexing system.  It simply consists of an dynamic array of type String and of type LongWord.  An index is built in this array where the String names of each item on level 4 is added to the array and at the same time the AbsoluteIndex of the string item on level 4 is added to the LongWord Array, both against the same index reference.

When a search is required, it is just necessary to run through the String dynamic index and when a mach is found, the associated LongWord dynamic index contains the AbsoluteIndex for the Equipment Record ||Number EquipRecordNo  of the searched item and
"TreeView9.Selected := TreeView9.Items.Item[EquipRecordNo];" subsequintly selects the appropreate lin in the TreeView.

Naturally the Index is maintained when items are added and deleted from the TTreeView.
the TTreeView is a mean to display the data ... but how is you data stored when the application is not running ... what king of data storage are you using ? If you are using a SQL capable database what you are asking is quite easy to do.

Please give more information.
HenryM2Author Commented:
On closing of the program the data is converted to an XML file stored on disc. On open the XML file is again converted into the TTrreView where the data is manipulated.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Are you searching through the XML document or the actual tree once loaded?
load the data in a TClientDataSet and use it`s Filter functionality, i think that`s the painless way at this point
Eddie ShipmanAll-around developerCommented:
You can search the XML using XPATH very easily. If you post say two full nodes of the XML I'll show you how to do that as well as return the results to you.
Geert GOracle dbaCommented:
maybe you need to upgrade to an express database (like oracle express or mssql express) or use an embedded database like accuracer

your app will load a lot faster and it will not need to save anything at closure.

and you can search directly in the database with sql queries.
HenryM2Author Commented:
Thanks all so far.  Sounds like there is quite a few possibilities listed.  I am unfortunately out of office till Friday when I will look at these possibilites, please don't loose interest in my problem.

I would just like to mention that the persons using the database is used to expanding nodes in the TTreeView to get certain bits of info.  I also have right click menu funtions which allows the users to copy and paste nodes from one section of the database to other sections.  So once loaded all resides in the TTReeView and manipulated there by either the users or functions being run, manipulating selected parts of the data.

The way you solved your problem sounds intriguing. Would you be willing to post your code so we can see how you did it?

HenryM2Author Commented:
The solution has now been operational for a while and works quite well.  At the moment the code is scattered over a few Procedures amongs 6800 lines of code and the Procedure and variable names are appication specific.  Posting it in this state will be messy.  I did this as I was pressed for time to produce the working appication.  I plan to package the solution into a generic set of Procedures as soon as I get time, also so that I can easily reuse the solution myself.  I will then gladly post the solution.  If you are in a hurry for the solution I will make a plan to do it otherwise if for interest sake, I will appreciat if you could give me a few days.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.