I have a form that contains a TOpenDialog
component (OpenDialog1
) and a button.
OpenDialog1
has the ofAllowMultiSelect
(of Options
) property set to true.
Upon clicking the button the method AddFilesToListView
is executed:
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;
When running the application, selecting the first file, I have no problem but when wanting to select the second one, I get an error saying "Project project3 raised an exception class EInvalidPointer with message 'Invalid Pointer Operation'."
What's the cause of this, how do I correct this?