这是推动我坚果.... 我取回我的数据库的名称来填充cxComboBox1:缺少的表名称属性
procedure TForm1.FormShow(Sender: TObject);
var
I: Integer;
DBList: TStringDynArray;
begin
DBList := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), '*.abs', TSearchOption.soAllDirectories);
for I := 0 to Length(DBList) - 1 do
begin
cxCombobox1.Properties.Items.Add(DBList[I]);
end;
end;
这工作我的数据库OK.The列表中显示的cxCombobox1 。
在第二个cxCombobox中,我填充属于数据库 的表名称,显示在cxCombobox1中。
procedure TForm1.cxComboBox1PropertiesChange(Sender: TObject);
var
TABLES: TStringList;
i: integer;
begin
if ABSTable1.Active = True then
ABSTable1.Close;
cxComboBox2.properties.Items.Clear;
TABLES := TStringList.Create;
ABSDatabase1.DatabaseFileName:=cxCombobox1.Text;
try
ABSDatabase1.Open;
ABSDatabase1.GetTablesList(TABLES);
for i:= 0 to TABLES.Count-1 do
cxComboBox2.properties.Items.Add(TABLES[i]);
finally
TABLES.free;
end;
end;
这基本上工作正常。选择cxComboBox1中的数据库将使用相关表格填充cxComboBox2 。
所以一般的想法是在cxComboBox2中选择时打开表格。 而我所做的:
procedure TForm1.ABSTable1BeforeOpen(DataSet: TDataSet);
begin
ABSTable1.DatabaseName:= ABSDatabase1.DatabaseName;
ABSTable1.TableName := cxComboBox2.Text;
end;
而且在combobox2更改事件我所做的:
procedure TForm1.cxComboBox2PropertiesChange(Sender: TObject);
begin
cxGrid1DBTableView1.ClearItems;
ABSTable1.Open;
cxGrid1DBTableView1.DataController.CreateAllItems;
end;
该工程确定。但是只有当我打开combobox2中显示的选定数据库(combobox1) 中的表格时。 说我打开了表格,然后去选择combobox1中的另一个数据库 我收到错误“Missing ABSTable1.Tablename”!
我在这里错过了什么?我的桌子名称在哪里丢失? 如果我更换change事件combobox2一个按钮:
procedure TForm1.cxButton2Click(Sender: TObject);
begin
if ABSTable1.Active = True then
ABSTable1.Close;
cxGrid1DBTableView1.ClearItems;
ABSTable1.Open;
cxGrid1DBTableView1.DataController.CreateAllItems;
end;
然后一切工程....
'cxComboBox2.properties.Items.Clear;'触发组合框2的更改事件。在combobox2的更改事件中,仅当在combobox2中选择一个表时才打开数据库。 – NineBerry