PARADOX的INDEX问题(100分)

Y

YuTian

Unregistered / Unconfirmed
GUEST, unregistred user!
一个PARADOX表,没有定义KEY,只有一个SECOND INDEX名为INDEX1。
在程序中,FORM1用于修改数据,FORM1中的TABLE的INDEXNAME为空,
FORM2用于打印预览,其中的TABLE的INDEXNAME为INDEX1。现在FORM1
中修改数据后用CREATE建立FORM2,出现INDEX OUT OF DATE。
我该怎么办?
 
您的问题十分典型, 当使用多个 Form 时同时访问一个数据文件
时应该避免在每个Form 上都放上一个 Ttable 控件, 正确的方法
是应该让它们共享一个 Ttable Delphi 中提供的解决方案是使
用 DataModule, 把不可见控件、数据都放在 DataModule 中, 在
使用这些数据的 Form 中只需要在 uses 中引用它们就可以了这
样就能够保证几个 Form 中的数据同步。

对于你的问题也可以将 Table 放在 Form1 中并设置 IndexName
为 INDEX1, 在 Form2 的 implementation 段的 uses 下引用
Form1(假设为 unit1, TForm1),在需要数据操作时前面加上
"Form1." 的前缀, 例如:

Label1.caption := Form1.Table1.FieldByName('AnyName').AsString;
 
非常感谢您的回答,可是我的问题重点并不在于不同的FORM对TABLE的共享。
而在于如果数据表不设置KEY并把SENCOND INDEX设成MAINTAINED的话,
修改数据后使用SECOND INDEX就会出现INDEX OUT OF DATE。
我之所以不设置KEY而且FORM1中的TABLE不设置INDEXNAME是因为不希望在
DBGRID中刚添加的记录由于KEY或INDEX的影响不知跑到哪里去了。
我还试过如果数据表没有KEY的话即使INDEXNAME设置为INDEX1,添加记录时
也会产生INDEX READONLY的EXCEPTION。
 
HI:对于PARADOX而言,你最好设置KEY,至于你说的添加后找不到,可以在程序中使用FINDKEY,LOCATE来定位.如果是我来做,我不会在DBGRID中添加记录的,这样做程序未免有些太粗糙了.
希望对您有所帮助!
 
下面是Paradox的the secondary index的Maintained option的说明,
也是你问题的答案.


Maintained

Specifies whether to maintain the secondary index automatically.

Maintained indexes are updated by Database Desktop every time the table changes.
This speeds up certain operations like queries.
Maintained indexes are available for keyed tables only.
Non-maintained indexes are updated only when the index is used; for example, when you link tables or run a query.
The operation that uses the secondary index takes slightly longer using a non-maintained index, because Database Desktop must first update the index to recognize values that you have added, deleted, or changed, and then sort the table according to the new index. Also, if a non-maintained index becomes out of date, you cannot use it to change the viewing order of records.

Non-maintained indexes are most useful on tables that are read-only.
 
不知你是否看通了我的回答.

数据表不设置KEY并把SENCOND INDEX设成MAINTAINED是不行的.
 
你的问题出在建库上,跟其他问题无关,
前几天我也遇到这个问题,
PARADOX表,必须先设KEY,然后才能建SECOND INDEX!
这是王八屁股---规定!
 
顶部