我需要从两个不同的ListBox中读取两个名称,并将这两个名称关联到DataSet中的注册表中。但是,在DataSet上,关系是由人的ID,它只是一个LookUp的名称。
在我的脑海里:
第1步:阅读姓名并获取此人ID。
第2步:在导航器的事件BeforeInsert上,在相应的列中插入ID。
Importante信息:
关系来自员工ID和经理ID。
我是Delphi的新手。
问题:
实现失败,因为DataSet与ListBox位于不同的单元中,我不知道如何在不更改项目的情况下修复此问题。
答案 0 :(得分:1)
将包含DataSet
的单元添加到具有implementation
的单元的ListBox
uses子句中。如果TDataSet
DataSet1
位于TDataModule
dmMyData
MyDataMod.pas
unit Main;
interface
uses Forms, ....
type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
protected
procedure Button1Click(Sender: TObject);
private
...
public
...
end;
implementation
uses
MyDataMod; // Use the actual unit name, of course
procedure TForm1.Button1Click(Sender: TObject);
begin
if (ListBox1.ItemIndex <> -1) then
if (ListBox2.ItemIndex <> -1) then
begin
// Access the dataset however you need here
dmMyData.DataSet1.Insert;
end;
end;
,您可以这样做(请参阅我的注意强>下面):
{{1}}
注意当然,更好的方法是将数据与UI分开,并创建一个过程,将员工和经理信息作为参数并处理该信息的所有处理那里。然而,这与你在这里提出的问题完全不同。