請問如何在Runtime時 將 ClientDataSet 新增 LookupField |
尚未結案
|
neway
一般會員 發表:5 回覆:3 積分:1 註冊:2002-11-01 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
參考: http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=12827
Question: How can I create a lookup field at runtime? Answer: Creating a lookup field at runtime differs in only a few ways from
creating any standard TField object. Three properties of a field
that must be set in order to function as a Lookup field are
LookUpDataset, LookUpKeyFields and LookUpResultField. The sample
code below demonstrates how to create a Lookup field at runtime
using the two DBDEMOS tables 'customer.DB' and 'orders.DB'.
Example:
uses Forms, Classes, Controls, StdCtrls, Db, DBTables, DBCtrls; type TForm1 = class(TForm) Table1: TTable; // DBDemos customer table Table2: TTable; // DBDemos orders table Button1: TButton; DBLookupComboBox1: TDBLookupComboBox; DataSource1: TDataSource; Table2CustNo: TFloatField; // CustNo key field object used for Lookup procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); begin with TStringField.Create(Table2) do begin FieldName := 'MyLookup'; FieldKind:= fkLookup; DataSet := Table2; Name := Dataset.Name FieldName; KeyFields:= 'CustNo'; LookUpDataset:= Table1; LookUpKeyFields:= 'CustNo'; LookUpResultField:= 'Company'; DbLookupCombobox1.DataField:= FieldName; DataSource1.DataSet:= Dataset; Table2.FieldDefs.Add(Name, ftString, 20, false); end; DbLookupCombobox1.DataSource:= Datasource1; Table1.Active:= True; Table2.Active:= True; end; end.--- Everything I say is a lie. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |