我有一个包含TOpenDialog
组件(OpenDialog1
)和一个按钮的窗体。 OpenDialog1
将ofAllowMultiSelect
(的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,并显示消息'Invalid Pointer Operation'。“
这是什么原因,我该如何纠正?
除了释放不属于您的内存之外,您可以获得无效指针操作异常。它只是意味着你跟随了一个糟糕的指针。释放别人的数据是其中一个原因,而不是它的唯一原因。 – 2009-06-30 23:17:33