Solved

Temporary Index on the fly

Posted on 1998-01-29
7
330 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
  • 3
  • 3
7 Comments
 
LVL 3

Accepted Solution

by:
d4jaj1 earned 150 total points
Comment Utility
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
Comment Utility
    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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Whytboy
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now