【delphi】请问在delphi中,如何把某文件夹下的文件读取到PopupMenu上 或者说 如何用PopupMenu遍历文件
就像这样的,怎么枚举指定文件夹下的文件我会,主要是想知道,怎么在PopupMenu上做出这个效果,请各位老师提点一下,最好有实例,谢谢各位了...
就像这样的,怎么枚举指定文件夹下的文件我会,主要是想知道,怎么在PopupMenu上做出这个效果,请各位老师提点一下,最好有实例,谢谢各位了
展开
展开全部
给个例子给你:
procedure TForm1.FormCreate(Sender: TObject);
const
ext='.TXT';
var
sr: TSearchRec;
eh: Integer;
pt: String;
mn: TMenuItem;
begin
pt := ExtractFilePath(Application.ExeName);
if pt[Length(pt)] <> '\' then pt := pt + '\';
eh := FindFirst(pt + '*.*', faAnyFile, sr);
while eh = 0 do begin
if (sr.Name <> '.') and (sr.Name <> '..') then begin
if Pos(UpperCase(ExtractFileExt(sr.Name)), ext) > 0 then begin
mn := TMenuItem.Create(PopupMenu1);
mn.Caption := sr.Name;
PopupMenu1.Items.Add(mn);
end;
end;
eh := FindNext(sr);
end;
FindClose(sr);
end;
procedure TForm1.FormCreate(Sender: TObject);
const
ext='.TXT';
var
sr: TSearchRec;
eh: Integer;
pt: String;
mn: TMenuItem;
begin
pt := ExtractFilePath(Application.ExeName);
if pt[Length(pt)] <> '\' then pt := pt + '\';
eh := FindFirst(pt + '*.*', faAnyFile, sr);
while eh = 0 do begin
if (sr.Name <> '.') and (sr.Name <> '..') then begin
if Pos(UpperCase(ExtractFileExt(sr.Name)), ext) > 0 then begin
mn := TMenuItem.Create(PopupMenu1);
mn.Caption := sr.Name;
PopupMenu1.Items.Add(mn);
end;
end;
eh := FindNext(sr);
end;
FindClose(sr);
end;
追问
您好,我想让他添加到图片中的'枚举指定文件夹'这个选项里,就像开始菜单中的附件那样,移动或者点击才显示
追答
procedure TForm1.FormCreate(Sender: TObject);
const
ext='.TXT';
var
sr: TSearchRec;
eh: Integer;
pt: String;
mj,mn: TMenuItem;
begin
pt := ExtractFilePath(Application.ExeName);
if pt[Length(pt)] '\' then pt := pt + '\';
eh := FindFirst(pt + '*.*', faAnyFile, sr);
mj := TMenuItem.Create(PopupMenu1);
mj.Caption := '枚举指定文件夹';
mj.ShortCut := 122;
PopupMenu1.Items.Add(mj);
while eh = 0 do begin
if (sr.Name '.') and (sr.Name '..') then begin
if Pos(UpperCase(ExtractFileExt(sr.Name)), ext) > 0 then begin
mn := TMenuItem.Create(mj);
mn.Caption := sr.Name;
PopupMenu1.Items[0].Add(mn);
end;
end;
eh:=FindNext(sr);
end;
FindClose(sr);
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询