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;

当我单击 shelllist 的空白区域时会发生什么情况,我得到一个异常错误。

4

2 回答 2

1

SelectedItem在尝试访问其任何成员之前,请确保它不是 nil。

于 2012-07-21T18:44:52.377 回答
0

如果我理解您的问题是正确的,您希望 ZipCheck 充当 on click 的事件处理程序。这将不起作用,因为事件处理程序必须是具有正确参数的方法(类中的过程)。

另一个优点是您不需要访问表单 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 回答