Solved

Temporary Index on the fly

Posted on 1998-01-29
7
332 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Activex get website that activex running on 3 85
Mydac connection data base issue 3 139
Best Firemonkey component pack 1 86
How to debug For loops? 3 45
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

911 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

20 Experts available now in Live!

Get 1:1 Help Now