下面是我正在处理的文件预览系统项目的一个示例。主窗体上有两个ListBox。第一个[lst_fileList]显示目录[files]中所有“.txt”文件的列表,每个文件都标有[order ###。txt],其中###是1到999之间的任意数字。运行该过程,它会在列表框中找到所选项(.txt文件),然后在第二个ListBox [lst_filePreview]中显示文件内的每一行。德尔福错误:得到“无类型”,预计“AnsiString”
尽管在我运行它时,在ReadLn(selectedFile)的第21行发生了一个错误。错误状态(不兼容类型:有“无类型”,预计为“AnsiString”)。
我已经看了几个小时现在这个错误,无济于事...任何帮助将不胜感激,谢谢。
procedure TForm1.btn_getPreviewClick(Sender: TObject);
var
checkSelect:integer;
orderSelect:string;
i:integer;
selectedFile:textFile;
begin
if lst_fileList.SelCount > 0 then
begin
for checkSelect:= 0 to (lst_fileList.Items.Count - 1) do
if lst_fileList.Selected [checkSelect] then
begin
orderSelect:=lst_fileList.Items[checkSelect];
orderSelect:=RightStr(orderSelect,3);
if fileexists('files\order'+orderSelect+'.txt') then
begin
assignFile(selectedFile,'files\order'+orderSelect+'.txt');
reset(selectedFile);
while not EOF(selectedFile) do
begin
lst_filePreview.Items.Add(readLn(selectedFile)); // Error occurs here: //
end;
closeFile(selectedFile);
end;
end;
end else
ShowMessage('Please select an item first!');
end;
在我看到的问题,它被声明为 “文本文件”。 – 2014-10-12 14:14:20