我有一个包含TOpenDialog
组件 ( OpenDialog1
) 和按钮的表单。
OpenDialog1
将ofAllowMultiSelect
(of Options
) 属性设置为 true。
单击按钮后,将AddFilesToListView
执行该方法:
procedure TForm4.AddFilesToListView();
var
ListItem : TListItem;
I: Integer;
F : File;
LengthOfAudio : TDateTime;
previousCursor : TCursor;
begin
previousCursor := Self.Cursor;
Self.Cursor := crHourGlass;
if OpenDialog1.Execute then
begin
for I := 0 to OpenDialog1.Files.Count - 1 do begin
if FileExists(OpenDialog1.FileName) then begin
ListItem:=ListView1.Items.Add;
ListItem.Caption := 'Test';
ListItem.SubItems.Add(ExtractFileName(OpenDialog1.Files[I]));
ListItem.SubItems.Add(ExtractFilePath(OpenDialog1.Files[I]));
end else
raise Exception.Create('File does not exist.');
end;
end;
Self.Cursor := previousCursor;
OpenDialog1.Files.Free;
end;
运行应用程序时,选择第一个文件,我没有问题,但是当我想选择第二个文件时,我收到一条错误消息“Project project3 引发了异常类 EInvalidPointer 并带有消息'无效指针操作'。”
这是什么原因,我该如何纠正?