【发布时间】:2014-04-25 13:27:39
【问题描述】:
我遇到了一些我无法解决的简单代码问题。我正在使用应用了所有更新的 Delphi 5。
我有这个代码块:
procedure TForm1.LoadBtnClick(Sender: TObject);
var
s1, s2, s3 : Textfile;
sa, sb, RString, SQLString : string;
begin
with sourcequery do begin
Close;
SQL.Clear;
SQL.Add('delete * from source');
ExecSQL;
Close;
AssignFile(S2, 'c:\delphi programs\events\source1.txt');
AssignFile(S1, 'c:\delphi programs\events\source2.txt');
Reset(s2);
Reset(s1);
while not eof(s1) do begin
readln(s1, RString);
SQLString := 'insert into source1(f1, f2) values(';
SQLstring := SQLString+ QuotedStr(copy(Rstring, 1, pos(chr(9), Rstring)-1))+', ';
SQLString := SQLString+QuotedStr(copy(Rstring, pos(chr(9),Rstring)+1,length(Rstring)))+')';
with sourcequery do begin
close;
SQL.Clear;
SQL.Add(SQLString);
ExecSQL;
end;
end;
end;
end;
但是,当我尝试编译它时,它在这一行的“eof(”之后停止:
while not eof(s1) do begin
带有“缺少运算符或分号”的错误消息。
尽我所能,我找不到任何错误 - 缺少运算符或分号。我已经注释掉了文件读取块,它编译得很好。我已经重新输入了很多次,以防有隐藏的特殊字符。到目前为止,这是除了标题信息之外的整个程序。
谁能发现这个愚蠢的错误?
【问题讨论】:
-
您可能遇到了范围解析问题。请改用
while not System.eof(s1)...。 -
这就是为什么你不应该使用
with -
"with" 是邪恶的,因为它使代码难以阅读。 IDE看不懂你的意思,下一个看代码的开发者也会吃亏。
-
“被认为有害” -- hallvards.blogspot.com/2004/08/…
-
一个嵌套的?!?它燃烧!它燃烧!让它停下来!
标签: delphi text-files