在设计时将TDataSet嵌入到表单中

Wil*_*der 3 delphi data-binding tdataset

I am looking for a way to provide a ListSource to a TDBLookupComboBox in delphi without having an actual table on the database server to draw that list from. The DataField for the Combo Box is a 1 character field that contains a coded value such as 'A' = 'Drivers License', 'B' = 'Passport', 'C' = 'Library Card', etc. That is to say that the table only contains A, B, or C. The application is responsible for Displaying 'Drivers License' in the GUI. Normally a database might have a look up table but this database does not and I can not add one. My idea is that the DataSource and ListSource for a DB Look-up control do not have to be the same database, so if it were possible to define a small table in my form that contains the look-up data then I could use that an not require a real database table.

有没有人知道delphi组件允许在表单上定义TDataSet而不在其后面有任何实际的数据文件?

jac*_*ate 6

我知道有不同的内存数据集.Delphi附带了TClientDataSet,您可以按照自己的方式使用它.您必须使用可执行文件部署midas.dll才能工作,或者必须在uses子句中包含MidasLib,以便在可执行文件中静态链接此库(运行时不需要midas.dll).

要从TClientDataSet获得所需内容,您可以创建字段并:

  • 将记录存储在xml文件中(例如,使用您制作的另一个辅助工具).在运行时使用TClientDataSet的LoadFromFile方法加载数据.此外,您可以将此xml作为资源与$ R指令一起存储,并在运行时操作此资源以向您的ClientDataSet提供包含的数据,以防止使用您的exe部署(和可能修改)xml文件.
  • 使用CreateDataSet方法并在运行时插入/填充记录

代码示例:

procedure TFrom1.Init;
begin
  cdsIDType.CreateDataSet;
  cdsIDType.InsertRecord('A', 'Drivers License');
  cdsIDType.InsertRecord('B', 'Passport');
  //etcetera.
end;
Run Code Online (Sandbox Code Playgroud)