Delphi 如果选择的是文件、文件夹或空白,则测试外壳列表
再问我一个问题 我正在使用raize的shelllist,希望向on click事件添加一些代码,以测试所选项目是否有效(文件、文件夹或空白),但我不确定如何正确执行此操作 这是我的Delphi 如果选择的是文件、文件夹或空白,则测试外壳列表,delphi,Delphi,再问我一个问题 我正在使用raize的shelllist,希望向on click事件添加一些代码,以测试所选项目是否有效(文件、文件夹或空白),但我不确定如何正确执行此操作 这是我的 procedure ZipCheck; var Path : string; i : integer; s : string; DecompStream : TMemoryStream; LExtention : string; begin Path := form2.FileList.S
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;
当我单击外壳列表的空白区域时,会出现异常错误。如果我理解您的问题是正确的,您希望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;
在尝试访问其任何成员之前,请确保
SelectedItem
不是nil。我尝试了更改,但在单击外壳列表中的空白处时仍然存在相同的问题。我在表单和单元中尝试过这一点。我很好奇“selecteditem.isvalid”的语法是否可能不是我应该使用的语法?你得到的错误是什么?感谢所有的帮助,我和一个raize的家伙谈过,他建议我做以下事情。如果filelist.selecteditem=nil,则开始退出;结束;