以下是我正在处理的文件预览系统项目的示例.主窗体上有两个ListBox.第一个[lst_fileList]显示目录[files]中所有".txt"文件的列表,每个文件都标有[order ###.txt],###是1到999之间的任意数字.程序运行后,它会在列表框中找到所选项目(.txt文件),然后在第二个ListBox [lst_filePreview]上显示文件中的每一行.
虽然在运行它时,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;
Run Code Online (Sandbox Code Playgroud)