Invalid pointer operation

I have a form containing component TOpenDialog( OpenDialog1) and button. OpenDialog1has the ofAllowMultiSelect(of Options) property equal to true.

After clicking the button, the method is executed 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;

When launching the application, selecting the first file, I have no problem, but if you want to select the second, I get an error: "Project project3 raised the EInvalidPointer exception class with the message" Invalid Operation Pointer ".

What is the reason for this, how can I fix it?

+3
source share
4 answers

" " , , . :

  • , .
  • , .
  • , .

TOpenDialog Files. , , , , , , . Dialogs.pas . , , , . .

, , . , , .

+22

if FileExists(OpenDialog1.Files[I]) then begin

if FileExists(OpenDialog1.FileName) then begin

, .

?

OpenDialog1.Files.Free;
+3

TOpenDialog .

+2

, , " ". ! , , !

0

Source: https://habr.com/ru/post/1711601/


All Articles