Einzelnen Beitrag anzeigen

Delphi.Narium

Registriert seit: 27. Nov 2017
2.490 Beiträge
 
Delphi 7 Professional
 
#2

AW: TStrings/TStringlist : funktioniert aber ...

  Alt 1. Aug 2024, 16:56
Wofür brauchst Du SelectedFiles?
Delphi-Quellcode:
var
  OpenDialog: TOpenDialog;
begin
  OpenDialog := TOpenDialog.Create(nil);
  try
    OpenDialog.Options := [TOpenOption.ofAllowMultiSelect];
    // Customize the filter as needed
    OpenDialog.Filter := 'All Files|*.*';
    if OpenDialog.Execute then
    begin
      // Process the selected files (e.g., display their names)
      ShowMessage('Selected files: ' + OpenDialog.Files.Text);

      lst_ImageList.clear;
      lst_ImageList.items.AddStrings(OpenDialog.Files) ;

      EvaluateSelectedFiles(TStringList(OpenDialog.Files));
    end;
  finally
    OpenDialog.Free;
  end;
end;

procedure TForm.EvaluateSelectedFiles(SelectedFiles : TStringList);
Und damit sollte dann klar sein, warum der Typcast erforderlich ist, EvaluateSelectedFiles erwartet eine TStringList, OpenDialog.Files ist aber vom Typ TStrings.
Delphi-Quellcode:
var
  OpenDialog: TOpenDialog;
  SelectedFiles: TStringList;
begin
  OpenDialog := TOpenDialog.Create(nil);
  SelectedFiles := TStringList.Create;
  try
    OpenDialog.Options := [TOpenOption.ofAllowMultiSelect];
    // Customize the filter as needed
    OpenDialog.Filter := 'All Files|*.*';
    if OpenDialog.Execute then
    begin
      // Process the selected files (e.g., display their names)
      SelectedFiles.AddStrings(OpenDialog.Files);
      ShowMessage('Selected files: ' + SelectedFiles.Text);

      lst_ImageList.clear;
      lst_ImageList.items.AddStrings(OpenDialog.Files) ;

      EvaluateSelectedFiles(SelectedFiles);
    end;
  finally
    SelectedFiles.Free;
    OpenDialog.Free;
  end;
end;

procedure TForm.EvaluateSelectedFiles(SelectedFiles : TStringList);
Dann geht's auch ohne Typcast.
  Mit Zitat antworten Zitat