0

別の質問でもう一度。

Raize の shelllist を使用しており、クリック イベントにコードを追加して、選択した項目 (ファイル、フォルダー、または空白) が有効かどうかをテストしたいと考えていますが、これを正しく行う方法がわかりません。

これが私が持っているものです。

procedure ZipCheck;
var
  Path : string;
  i : integer;
  s : string;
  DecompStream : TMemoryStream;
  LExtention : string;
begin

  Path := form2.FileList.SelectedItem.PathName;
  form2.FNameEdit.Text := Path;

  if form2.FileList.SelectedItem.IsValid = true then
  begin
    LExtention :=  TPath.GetExtension(form2.filelist.SelectedItem.PathName);
    if tpath.GetExtension(LExtention) = '.zip' then
    begin
      Showmessage(LExtention);
    end;
  end;
end;

シェルリストの空白の領域をクリックすると、例外エラーが発生します。

4

2 に答える 2

1

SelectedItemそのメンバーのいずれかにアクセスしようとする前に、 nil でないことを確認してください。

于 2012-07-21T18:44:52.377 に答える
0

あなたの質問が正しいと理解できたら、ZipCheck をオン クリックのイベント ハンドラーとして機能させたいと考えています。イベント ハンドラーは正しいパラメーターを持つメソッド (クラス内のプロシージャー) でなければならないため、これは機能しません。

追加の利点は、フォーム var (form2) にアクセスする必要がないことです。

したがって、次のようになります。

   procedure TForm2.ZipCheck(Sender: TObject);
    var
      Path : string;
      i : integer;
      s : string;
      DecompStream : TMemoryStream;
      LExtention : string;
    begin

      Path := FileList.SelectedItem.PathName;
      FNameEdit.Text := Path;

      if FileList.SelectedItem.IsValid = true then
      begin
        LExtention :=  TPath.GetExtension(filelist.SelectedItem.PathName);
        if tpath.GetExtension(LExtention) = '.zip' then
        begin
          Showmessage(LExtention);
        end;
      end;
    end;
于 2012-07-21T15:22:31.297 に答える