Delphi 控件ComboBox的问题

来源:百度知道 编辑:UC知道 时间:2024/05/25 20:54:44
我想用COMBOBOX控件获取指定文件夹下的指定后缀名文件,例如文本文件,当新添加一个文本文件,下次启动程序,点下COMBOBOX下拉框,都能够全部显示指定文件夹下的所有文本文件,或加多一个按钮刷新一下,就能全部显示出来.请问该如何实现,如何写代码.如果知道的请详细写出...

其实主要就是个遍历文件夹操作。
{-------------------------------------------------------------------------------
过程名: MakeFileList 遍历文件夹及子文件夹
参数: Path,FileExt:string 1.需要遍历的目录 2.要遍历的文件扩展名
返回值: TStringList

Eg:ListBox1.Items:= MakeFileList( 'E:\指定的文件路径','.exe') ;
ListBox1.Items:= MakeFileList( 'D:\指定的文件路径','.*') ;
-------------------------------------------------------------------------------}
function MakeFileList(Path,FileExt:string):TStringList ;
var
sch:TSearchrec;
begin
Result:=TStringlist.Create;

if rightStr(trim(Path), 1) <> '\' then
Path := trim(Path) + '\'
else
Path := trim(Path);

if not DirectoryExists(Path) then
begin
Result.Clear;
exit;
end;

if FindFirst(Path + '*', faAnyfile, sch) = 0 then
begin
repeat
Application.P