关于DELPHI的代码问题

来源:百度知道 编辑:UC知道 时间:2024/06/07 14:49:23
procedure TForm1.Button7Click(Sender: TObject);
var sqlstr:string;
begin
With Query2 do
begin
if radiobutton17.checked=true then
SqlStr:='select * from change where stuno like '+' '+QuotedStr('%'+edit18.Text+'%');
if radiobutton18.checked=true then
sqlstr:='select * from change where name like '+ ' '+quotedstr('%'+edit18.Text+'%');
if radiobutton19.checked=true then
sqlstr:='select * from change where class like '+' '+quotedstr('%'+edit19.text+'%');
Sql.Add(SqlStr);
close;
Sql.Clear;
Open;
end;
else
begin
messagedlg('对不起,没有找到你要查找的记录!',mtinformation,[mbok],0);
application.Terminate;
end;

end;

老是提示[Error] Unit1.pas(442): ';' not allowed before 'ELSE'

上面的提示是else 的语法不对,else是与if ... then ...else搭配使用的。例如
if a=1 then
begin
....
end
else
begin
....
end
还有我想你的思路是如果找不到一条记录就提示 ‘对不起,没有找到你要查找的记录!’。所以你的代码不但语法有错,而且算法也有误,你可以改为一下的代码试一下:
procedure TForm1.Button7Click(Sender: TObject);
var sqlstr:string;
begin
With Query2 do
begin
if radiobutton17.checked=true then
SqlStr:='select * from change where stuno like '+' '+QuotedStr('%'+edit18.Text+'%');
if radiobutton18.checked=true then
sqlstr:='select * from change where name like '+ ' '+quotedstr('%'+edit18.Text+'%');
if radiobutton19.checked=true then
sqlstr:='select * from change where class like '+' '+quotedstr('%'+edit19.text+'%');
Sql.Add(SqlStr);
close;
Sql.Clear;
Open;
end;
if Query2.eof then //此为改动部分
begin
messagedlg('对不起,没有找到你要查找的记录