Solved

Temporary Index on the fly

Posted on 1998-01-29
7
338 Views
Last Modified: 2010-05-18
How would I go about creating a temporary Index in a procedure that can be used in a TTable, but then can be discarded (somehow) either automatically or manually when the Table is closed or freed?

Thanks,
Roger
0
Comment
Question by:Whytboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 3

Accepted Solution

by:
d4jaj1 earned 150 total points
ID: 1357849
Don't know of any way to create a temporay index, the best thing to do is create the index, then delete it when the table/form is closed.  To add the index, use;

if IndexName = Fieldname then ixCaseSensitive is reqd (the default)
if IndexName <> Fieldname then ixCaseInsensitive is reqd

Thus you need:

table.AddIndex('cusname', 'name', [ixCaseInsensitive]);
 or
table.AddIndex('name', 'name', []);

To delete the Index, use; Table1.DeleteIndex('NewIndex');

Any questions, please add a comment.

Good Luck!
Jay
0
 

Author Comment

by:Whytboy
ID: 1357850
    Will this add the index to the table?  I ask, because basically, I have to keep everything READ-ONLY.  The table I am viewing and wanting to Re-Index is not of my own design and so I can't adjust the database in ANY way.  They have their indexes in the database, to which I can not add, modify, or delete!

Roger
0
 
LVL 3

Expert Comment

by:d4jaj1
ID: 1357851
In that case, you have a problem.  There isn't a 'virual' index.  This will actually add an index to the table.

What do you need teh index for, sorting, filtering?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Whytboy
ID: 1357852
Its for sorting mainly... on a non-primary key or indexed value.  I did try using a SQL with the fieldname as the ORDER BY parameter... but, it didnt work either.
0
 
LVL 3

Expert Comment

by:d4jaj1
ID: 1357853
Unfortunately, the Order By clause uses an Index to sort the DB.  Every other means of sorting a table, SetRange, IndexName, etc. require an index - afterall, that what they are there for.  Unless the owners of the DB allow you to add an index - at least only for a short time, you won't be able to sort this table.

There is a way you can provide your users a sorted view of this same data, although it will be slow.  It would require you to create a new table, just like the existing table, copy its data, then sort (apply the index) to the newly created table.  Add a button you your existing form that opens a new form and creates the table ---

  try
   with table1 do
    begin
     fielddefs.update;
     indexdefs.update;
   end;
   tempdb := ttable.create(nil);
    with tempdb do begin
     DataBaseName := table1.databasename;
     tableName := 'temporary.db';
     TableType := table1.tabletype;
     fielddefs.assign(table1.fielddefs);
     indexdefs.assign(contacts.indexdefs);
     with IndexDefs do
      begin
       Clear;
       Add('NewIndex', 'NewIndex', []);
     end;
     createtable;
     open;
    end;
  except
    raise;
  end;

Set the index and show the form here.




0
 

Author Comment

by:Whytboy
ID: 1357854
Yeah... Thats about what I came down to.. now the problem is "sync"ing the tables..but, thats a different question
0
 

Expert Comment

by:erikenglund
ID: 1357855
You could create a new field in the table only for sorting and then when the user want to sort you could copy all fieldvalues to that "SortField"... Slow again ofcourse
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question