F
flyman2
Unregistered / Unconfirmed
GUEST, unregistred user!
我在一程序中的分支窗体中设置如下语句datamodule1.booktable.indexfieldnames:='bookname';
另一字段bookno是文件的第一个字段且其后加*号。执行程序到datamodule1.booktable.findnearest([edit1.text]);
处便显示no index for fields 'bookname'的错误信息,后来在大富翁论坛提出此问题有大侠说是
我没有建立索引的原因,后来我在booktable代表的book.db文件中设置了bookname索引即在bookname的key处
双击出现*号(将indexfieldnames改为indexname,bookname加*和不加*又都试过,datamodule1.booktable.open;
改为active:=true;),可程序运行仍然提示同样的错误信息,不知哪位大侠知道到底是何原因,该如何解决?进入form的源码如下:
unit Unit104;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, StdCtrls, ComCtrls, Mask, DBCtrls, ExtCtrls;
type
TForm4 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Button1: TButton;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
Edit2: TEdit;
Button2: TButton;
Panel1: TPanel;
Label3: TLabel;
Label4: TLabel;
DBEdit1: TDBEdit;
Edit3: TEdit;
Button3: TButton;
Button4: TButton;
Button5: TButton;
DBRadioGroup1: TDBRadioGroup;
DBCheckBox1: TDBCheckBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure TabSheet1Show(Sender: TObject);
procedure TabSheet2Show(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
uses Unit101;
{$R *.DFM}
procedure TForm4.Button1Click(Sender: TObject);
begin
datamodule1.booktable.active:=true;
datamodule1.booktable.findnearest([edit1.text]);
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
datamodule1.booktable.open;
datamodule1.booktable.findnearest([edit2.text]);
end;
procedure TForm4.Button3Click(Sender: TObject);
var srecord:integer;
sstudno:integer;
sbookno:integer;
sordstno:integer;
begin
if dbcheckbox1.checked=true then
begin
showmessage('');
dbradiogroup1.enabled:=false;
button4.enabled:=false;
end
else
begin
sstudno:=strtoint(edit3.text);
datamodule1.studenttable.indexfieldnames:='studentno';
datamodule1.studenttable.open;
if not datamodule1.studenttable.findkey([sstudno]) then
begin
showmessage('');
edit3.enabled:=false;
button4.enabled:=false;
end
else if datamodule1.studenttable.fieldbyname('permitted').asboolean=false then
begin
showmessage('');
form4.close;
end
else
begin
case dbradiogroup1.ItemIndex of
0:
begin
with datamodule1.recordtable do
begin
open;
last;
srecord:=datamodule1.recordtable.fieldbyname('recordno').asinteger+1;
sstudno:=strtoint(edit3.text);
sbookno:=strtoint(dbedit1.text);
insert;
setfields([srecord,sstudno,sbookno,null,null,null,false,false]);
post;
end;
with datamodule1.booktable do
begin
sbookno:=strtoint(dbedit1.text);
indexfieldnames:='BookNo';
close;
readonly:=false;
open;
findkey([sbookno]);
edit;
setfields([null,null,null,null,null,true,false]);
datamodule1.booktable.post;
showmessage('');
end;
end;
1:
begin
with datamodule1.booktable do
begin
sbookno:=strtoint(dbedit1.text);
datamodule1.booktable.close;
indexfieldnames:='BookNo';
readonly:=false;
open;
findkey([sbookno]);
edit;
setfields([null,null,null,null,null,true,true]);
post;
end;
with datamodule1.recordtable do
begin
sordstno:=strtoint(edit3.text);
indexfieldnames:='BookNo';
open;
findkey([dbedit1.text]);
edit;
setfields([null,null,null,sordstno,null,null,null,true]);
post;
end;
showmessage('');
end;
end;
end;
end;
end;
procedure TForm4.Button4Click(Sender: TObject);
begin
edit3.clear;
edit3.enabled:=true;
button5.enabled:=true;
dbradiogroup1.enabled:=true;
end;
procedure TForm4.TabSheet1Show(Sender: TObject);
begin
datamodule1.BookTable.indexfieldnames:='BookName';
end;
procedure TForm4.TabSheet2Show(Sender: TObject);
begin
datamodule1.BookTable.indexfieldnames:='Author';
end;
end.
另一字段bookno是文件的第一个字段且其后加*号。执行程序到datamodule1.booktable.findnearest([edit1.text]);
处便显示no index for fields 'bookname'的错误信息,后来在大富翁论坛提出此问题有大侠说是
我没有建立索引的原因,后来我在booktable代表的book.db文件中设置了bookname索引即在bookname的key处
双击出现*号(将indexfieldnames改为indexname,bookname加*和不加*又都试过,datamodule1.booktable.open;
改为active:=true;),可程序运行仍然提示同样的错误信息,不知哪位大侠知道到底是何原因,该如何解决?进入form的源码如下:
unit Unit104;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, StdCtrls, ComCtrls, Mask, DBCtrls, ExtCtrls;
type
TForm4 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Button1: TButton;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
Edit2: TEdit;
Button2: TButton;
Panel1: TPanel;
Label3: TLabel;
Label4: TLabel;
DBEdit1: TDBEdit;
Edit3: TEdit;
Button3: TButton;
Button4: TButton;
Button5: TButton;
DBRadioGroup1: TDBRadioGroup;
DBCheckBox1: TDBCheckBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure TabSheet1Show(Sender: TObject);
procedure TabSheet2Show(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
uses Unit101;
{$R *.DFM}
procedure TForm4.Button1Click(Sender: TObject);
begin
datamodule1.booktable.active:=true;
datamodule1.booktable.findnearest([edit1.text]);
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
datamodule1.booktable.open;
datamodule1.booktable.findnearest([edit2.text]);
end;
procedure TForm4.Button3Click(Sender: TObject);
var srecord:integer;
sstudno:integer;
sbookno:integer;
sordstno:integer;
begin
if dbcheckbox1.checked=true then
begin
showmessage('');
dbradiogroup1.enabled:=false;
button4.enabled:=false;
end
else
begin
sstudno:=strtoint(edit3.text);
datamodule1.studenttable.indexfieldnames:='studentno';
datamodule1.studenttable.open;
if not datamodule1.studenttable.findkey([sstudno]) then
begin
showmessage('');
edit3.enabled:=false;
button4.enabled:=false;
end
else if datamodule1.studenttable.fieldbyname('permitted').asboolean=false then
begin
showmessage('');
form4.close;
end
else
begin
case dbradiogroup1.ItemIndex of
0:
begin
with datamodule1.recordtable do
begin
open;
last;
srecord:=datamodule1.recordtable.fieldbyname('recordno').asinteger+1;
sstudno:=strtoint(edit3.text);
sbookno:=strtoint(dbedit1.text);
insert;
setfields([srecord,sstudno,sbookno,null,null,null,false,false]);
post;
end;
with datamodule1.booktable do
begin
sbookno:=strtoint(dbedit1.text);
indexfieldnames:='BookNo';
close;
readonly:=false;
open;
findkey([sbookno]);
edit;
setfields([null,null,null,null,null,true,false]);
datamodule1.booktable.post;
showmessage('');
end;
end;
1:
begin
with datamodule1.booktable do
begin
sbookno:=strtoint(dbedit1.text);
datamodule1.booktable.close;
indexfieldnames:='BookNo';
readonly:=false;
open;
findkey([sbookno]);
edit;
setfields([null,null,null,null,null,true,true]);
post;
end;
with datamodule1.recordtable do
begin
sordstno:=strtoint(edit3.text);
indexfieldnames:='BookNo';
open;
findkey([dbedit1.text]);
edit;
setfields([null,null,null,sordstno,null,null,null,true]);
post;
end;
showmessage('');
end;
end;
end;
end;
end;
procedure TForm4.Button4Click(Sender: TObject);
begin
edit3.clear;
edit3.enabled:=true;
button5.enabled:=true;
dbradiogroup1.enabled:=true;
end;
procedure TForm4.TabSheet1Show(Sender: TObject);
begin
datamodule1.BookTable.indexfieldnames:='BookName';
end;
procedure TForm4.TabSheet2Show(Sender: TObject);
begin
datamodule1.BookTable.indexfieldnames:='Author';
end;
end.