获取组合框项目属性中的数据库名称列表

时间:2016-11-08 07:05:03

标签: delphi

如何在运行时使用驻留在我的applicaton.exe目录中的数据库名称(* .mdb)填充comboboxes items属性?

1 个答案:

答案 0 :(得分:1)

使用TDirectory.GetFiles函数枚举所有* .mdb文件并将结果存储在TStringDynArray内。遍历结果并将值插入组合框中。确保包含 System.IOUtils System.Types 单位。

var
  I: Integer;
  MyList: TStringDynArray;
begin
  MyList := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), '*.mdb',
    TSearchOption.soAllDirectories);
  for I := 0 to Length(MyList) - 1 do
  begin
    ComboBox1.Items.Add(MyList[I]);
  end;
end;

仅插入文件名而不使用路径:

ComboBox1.Items.Add(ExtractFileName(MyList[I]));