S
serenesky
Unregistered / Unconfirmed
GUEST, unregistred user!
关于动态建立lookup型field时所遇到的问题
procedure Tclientquiry.muactrecClick(Sender: TObject);
var
TTotal:array[0..7]of TStringField;//建立TStringField
tempfieldnames:tstringlist;
T: TStringField;//建立lookup型field
tempsql,tempsql_1:string;
i:integer;
begin
//从数据库中取出数据
tempsql:='SELECT * FROM market_activity WHERE companyid = '+quotedstr(dbmoduel.ClientDataSet1.fields[0].AsString) +'and contactid='+quotedstr(dbmoduel.ClientDataSet2.fields[0].AsString);
dbmoduel.ClientDataSet3.close;
dbmoduel.ClientDataSet3.CommandText:=tempsql;
dbmoduel.ClientDataSet3.open;
dbmoduel.ClientDataSet3.close;
//对应于lookupdataset
tempsql_1:='select * from activity_code';
dbmoduel.ClientDataSettemp1.Close;
dbmoduel.ClientDataSettemp1.CommandText:=tempsql_1;
dbmoduel.ClientDataSettemp1.Open;
/////
tempfieldnames:=tstringlist.Create;
tempfieldnames.CommaText:='companyid,contactid,activitynum,activitycode,sourcecode,userid,activity_status,sender';
///////////对应于数据库的字段建立8个Tfield
for i:=0 to 7do
begin
TTotal := TStringField.Create(dbmoduel.ClientDataSet3);
TTotal .FieldName := tempfieldnames;
TTotal .DataSet :=dbmoduel.ClientDataSet3;
dbmoduel.ClientDataSet3.FieldDefs.UpDate;
end;
/////////////建立lookup型的filed
T := TStringField.Create(dbmoduel.ClientDataSet3);
T.FieldName := 'ac';
T.DisplayLabel:='活动代码';
T.DataSet := dbmoduel.ClientDataSet3;
T.FieldKind := fkLookup;
T.Size := 200;
T.LookupDataSet := dbmoduel.ClientDataSettemp1;
T.LookupKeyFields := 'codeid';
T.KeyFields := 'activitycode';
t.ReadOnly:=false;
t.LookupCache:=true;
T.Lookup:=true;
T.LookupResultField := 'description';
dbmoduel.ClientDataSet3.FieldDefs.UpDate;
/////////////////////
dbmoduel.ClientDataSet3.open;
/////////弹出菜单
marketactivity.ShowModal();
结果,在dbmoduel.ClientDataSet3所对应的TDBGrid中的ac的column中可以有lookup的field
并且可以有下拉菜单产生,也可以修改所对应的keyfields的value,但是却在所对应的
TDBGrid的Cell中显示空白值,请问这是为什么
应该怎么修改
procedure Tclientquiry.muactrecClick(Sender: TObject);
var
TTotal:array[0..7]of TStringField;//建立TStringField
tempfieldnames:tstringlist;
T: TStringField;//建立lookup型field
tempsql,tempsql_1:string;
i:integer;
begin
//从数据库中取出数据
tempsql:='SELECT * FROM market_activity WHERE companyid = '+quotedstr(dbmoduel.ClientDataSet1.fields[0].AsString) +'and contactid='+quotedstr(dbmoduel.ClientDataSet2.fields[0].AsString);
dbmoduel.ClientDataSet3.close;
dbmoduel.ClientDataSet3.CommandText:=tempsql;
dbmoduel.ClientDataSet3.open;
dbmoduel.ClientDataSet3.close;
//对应于lookupdataset
tempsql_1:='select * from activity_code';
dbmoduel.ClientDataSettemp1.Close;
dbmoduel.ClientDataSettemp1.CommandText:=tempsql_1;
dbmoduel.ClientDataSettemp1.Open;
/////
tempfieldnames:=tstringlist.Create;
tempfieldnames.CommaText:='companyid,contactid,activitynum,activitycode,sourcecode,userid,activity_status,sender';
///////////对应于数据库的字段建立8个Tfield
for i:=0 to 7do
begin
TTotal := TStringField.Create(dbmoduel.ClientDataSet3);
TTotal .FieldName := tempfieldnames;
TTotal .DataSet :=dbmoduel.ClientDataSet3;
dbmoduel.ClientDataSet3.FieldDefs.UpDate;
end;
/////////////建立lookup型的filed
T := TStringField.Create(dbmoduel.ClientDataSet3);
T.FieldName := 'ac';
T.DisplayLabel:='活动代码';
T.DataSet := dbmoduel.ClientDataSet3;
T.FieldKind := fkLookup;
T.Size := 200;
T.LookupDataSet := dbmoduel.ClientDataSettemp1;
T.LookupKeyFields := 'codeid';
T.KeyFields := 'activitycode';
t.ReadOnly:=false;
t.LookupCache:=true;
T.Lookup:=true;
T.LookupResultField := 'description';
dbmoduel.ClientDataSet3.FieldDefs.UpDate;
/////////////////////
dbmoduel.ClientDataSet3.open;
/////////弹出菜单
marketactivity.ShowModal();
结果,在dbmoduel.ClientDataSet3所对应的TDBGrid中的ac的column中可以有lookup的field
并且可以有下拉菜单产生,也可以修改所对应的keyfields的value,但是却在所对应的
TDBGrid的Cell中显示空白值,请问这是为什么
应该怎么修改