delphi中 while not Eof do的作用是干嘛的?
procedure THHLR.showPP();
var
i: integer;
query: TQuery;
ZSBID, ZBASEID: Integer;
ZNAME: string;
begin
if DataMain.selectpp(FHH, ZSBID, ZBASEID, ZNAME) >= 1 then
begin
try
edHH.Visible := False;
ListBox.Visible := not edHH.Visible;
listBox.Clear;
I := 0;
while not Eof do ///////////////////////到这里,就直接跳出这个函数了,不在运行下面的步骤。连选择品牌什么的都没有走。。。
begin
SendToExeLog('H11');
listBox.Items.Add(IntToStr(ZSBID) + ' ' + ZNAME);
setlength(myPP, i + 1);
myPP[I].myInx := (ZBASEID);
inc(I);
end;
RgBox.Caption := '请选择品牌';
ListBox.SetFocus();
except
on E: Exception do
begin
DataMain.sLastError := e.Message;
SendToExeLog(e.Message);
end;
end;
end;
下面是selectpp函数:
function TDataMainCustom.selectpp(FHH: string; var SBID, BASEId: Integer; var HHNAME: string): Integer;
begin
try
with FQuery do
begin
Close;
SQL.Clear;
SQL.Text := 'select DISTINCT B.SBID,B.NAME,S.SP_ID from BASESP S,SPSB B';
SQL.Add(' WHERE S.HH = ''' + FHH + '''');
SQL.Add(' AND S.SB=B.SBID');
Open;
Result := FQuery.RecordCount; ///////////////以上运行了
if Result <= 0 then //////////////这里没有运行
begin
Close;
SQL.Clear;
SQL.Text := 'select DISTINCT B.SBID,B.NAME,S.BASEID from SPXX S,SPSB B';
SQL.Add(' WHERE S.HH = ''' + FHH + '''');
SQL.Add(' AND S.SB=B.SBID');
Open;
Result := FQuery.RecordCount;
end;
if not Eof then //////////////以下 运行了
begin
SBID := Fields[0].AsInteger;
HHNAME := Fields[1].AsString;
BASEId := Fields[2].AsInteger;
end;
Close;
end;
except
end;
end;
以上涉及到的两条sql语句都可以在数据库中查到涉及到的数据。但是运行后,会提示I/O error 6 错误,查出在showpp函数中的while not Eof do 语句,有异常,这之后就不在走下面的步骤了,但没有查出是什么原因?能告知下吗?
还有while not Eof do这条语句有什么作用,可以去掉吗?去掉之后有影响吗?