源程序:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ADODB,ExtCtrls, ComCtrls, StdCtrls, DB;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
ListView1: TListView;
ADOQuery1: TADOQuery;
StaticText1: TStaticText;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
Content : string;
begin
try
ListView1.Items.Clear;
with form1.ADOQuery1 do
begin
Content := Edit1.Text;
SQL.Clear;
SQL.Add( 'select * from table where aa like :aa');
Parameters.ParamByName('aa').value := Content;
end;
adoquery1.OPEN;
while not Eof do
begin
with ListView1.Items.Add do
begin
Caption:= FieldByName('11').AsString;
SubItems.Add(FieldByName('22').AsString);
SubItems.Add(FieldByName('33').AsString);
SubItems.Add(FieldByName('44').AsString);
subitems.Add(fieldbyname('55').asstring);
SubItems.Add(FieldByName('66').AsString);
end;
Next;
end;
StaticText1.Caption:= '共'+IntToStr(RecordCount)+'条记录';
Close;
end;
except
MessageDlg('查询失败',mtError,[mbok],0);
end;
end;
end.
这是报错的消息提示:
[Error] Unit1.pas(51): Undeclared identifier: 'FieldByName'
[Error] Unit1.pas(51): Missing operator or semicolon
[Error] Unit1.pas(52): ')' expected but identifier 'AsString' found
[Error] Unit1.pas(59): EXCEPT or FINALLY expected
[Error] Unit1.pas(60): Undeclared identifier: 'RecordCount'
[Error] Unit1.pas(63): Declaration expected but 'EXCEPT' found
[Error] Unit1.pas(65): '.' expected but ';' found
[Warning] Unit1.pas(66): Text after final 'END.' - ignored by compiler
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ADODB,ExtCtrls, ComCtrls, StdCtrls, DB;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
ListView1: TListView;
ADOQuery1: TADOQuery;
StaticText1: TStaticText;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
Content : string;
begin
try
ListView1.Items.Clear;
with form1.ADOQuery1 do
begin
Content := Edit1.Text;
SQL.Clear;
SQL.Add( 'select * from table where aa like :aa');
Parameters.ParamByName('aa').value := Content;
end;
adoquery1.OPEN;
while not Eof do
begin
with ListView1.Items.Add do
begin
Caption:= FieldByName('11').AsString;
SubItems.Add(FieldByName('22').AsString);
SubItems.Add(FieldByName('33').AsString);
SubItems.Add(FieldByName('44').AsString);
subitems.Add(fieldbyname('55').asstring);
SubItems.Add(FieldByName('66').AsString);
end;
Next;
end;
StaticText1.Caption:= '共'+IntToStr(RecordCount)+'条记录';
Close;
end;
except
MessageDlg('查询失败',mtError,[mbok],0);
end;
end;
end.
这是报错的消息提示:
[Error] Unit1.pas(51): Undeclared identifier: 'FieldByName'
[Error] Unit1.pas(51): Missing operator or semicolon
[Error] Unit1.pas(52): ')' expected but identifier 'AsString' found
[Error] Unit1.pas(59): EXCEPT or FINALLY expected
[Error] Unit1.pas(60): Undeclared identifier: 'RecordCount'
[Error] Unit1.pas(63): Declaration expected but 'EXCEPT' found
[Error] Unit1.pas(65): '.' expected but ';' found
[Warning] Unit1.pas(66): Text after final 'END.' - ignored by compiler
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
procedure TForm1.Button1Click(Sender: TObject);
var
Content : string;
begin
try
ListView1.Items.Clear;
with form1.ADOQuery1 do // <<开始A
begin
Content := Edit1.Text;
SQL.Clear;
SQL.Add( 'select * from table where aa like :aa'); // like 后面的 ''
Parameters.ParamByName('aa').value := Content;
end; // <<结束A 明显是这里多了END
adoquery1.OPEN;
while not Eof do // not who's eof
begin
with ListView1.Items.Add do
begin
Caption:= FieldByName('11').AsString; // << 不在A里, FieldByName前就要加adoquery1.
SubItems.Add(FieldByName('22').AsString);
SubItems.Add(FieldByName('33').AsString);
SubItems.Add(FieldByName('44').AsString);
subitems.Add(fieldbyname('55').asstring);
SubItems.Add(FieldByName('66').AsString);
end;
Next;
end;
StaticText1.Caption:= '共'+IntToStr(RecordCount)+'条记录';
Close;
end;
except
MessageDlg('查询失败',mtError,[mbok],0);
end;
end;
end.