Unit Temptbl

This is a TempTable example for Delphi 2.0. Free for anyone to use, modify and do whatever else you wish. This version has been tested with Delphi 2.0 and seems to work fine. This does NOT work with 16-bit Delphi! The 16-bit version is in a file called inmemory.zip. TempTables are supposedly also in-memory tables and provide all of the functionality of regular tables. Since the introduction of DbiMakePermanent you no longer have to modify the VCL to make this work. :) (DbiMakePermanent was incorporated in the previous release, but I didn't realize it fixed the VCL problem back then. Sorry if this made you do extra work!) Just like all things free this unit comes with no guarantees. I cannot be responsible for any damage this code may cause. Thanks to Steve Garland <72700.2407@compuserve.com> for his help. He created his own variation of an in-memory table component and I used it to get started. If you have comments - please contact me by e-mail at . Happy hacking! Gregory Trubetskoy P.S. Here is what I had to do to overcome certain problems with Delphi's implementation of BDE. For a BDE novice like me, it wasn't nearly as simple as it would seem from reading this! First, when you call DbiCreateTempTable it creates a table with a different name. BDE uses whatever file name you give it as the beginning and appends it with a number, e.g. XXX.DB will become XXXn.DB where n is some number that gets incremented every time you call DbiCreateTempTable. So the first thing I did was to retrieve the new name of the table by using DbiGetProp and assign it to TableName. (See TTempTable.CreateTable) Another problem was with the indexes. When you create a primary index, you must switch to it with DbiSwitchToIndex to make it active. DbiSwitchToIndex will also return you a new cursor handle to use for the new index. Delphi makes sure that any value you assign to IndexValue is not the same as the old value, or it will do nothing. (See TTable.SetIndex in DBTABLES.PAS) Therefore, when you create a primary index where none existed before and IndexName is '', Delphi VCL does NOT call DbiSwitchToIndex to activate the new index, even if you do IndexName := ''. For some reason it works for regular tables (I guess Borland programmers know what they are doing, or I missed something), but for TempTables, I would get a GPF shortly after using the old cursor. So I had to call TDataSet.SwitchToIndex manually (See TTempTable.AddIndex). Last problem I had was with either Delphi VLC or BDE itself confused with what the file name for the table was. I would get 'Table does not exist' or 'Operation not applicable' errors when adding indexes. I didn't study the problem in detail, but found it can easily be solved by DbiMakePermanent function (See TTempTable.Create). Description of MakePermanent sais that it doesn't save the table until convenient or the cursor is closed, so no benefit of TTempTable being fast because it's in RAM should be lost. I simply delete the table in the destructor to reverse the effect of DbiMakePermanent. Set the Permanent property to True, to prevent the table from being deleted. Speaking of performance benefits - my test showed that writing and indexing 5000 small records takes 5.77 seconds with TTable and 5.40 seconds with TTempTable - so I'm not sure where the performance benefit is. I do think TempTable is highly useful, mainly because it's a neat way to manage temporary tables without having to do all the boring stuff, like creating temporary filenames, if not for the supposed performance improvement. Happy Hacking again, and make sure to drop me a thank you note if you're using this! My e-mail is (without brackets, of course)

Classes

TTempTable -

Functions

Types

Constants

Variables


Functions


Types


Constants


Variables