全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1544
推到 Plurk!
推到 Facebook!

請問如何在Runtime時 將 ClientDataSet 新增 LookupField

尚未結案
neway
一般會員


發表:5
回覆:3
積分:1
註冊:2002-11-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-03 19:31:55 IP:218.165.xxx.xxx 未訂閱
請問各位大大 如何在 ClientDataSet 在Runtime 新增一個 LookupField 謝謝
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-12-04 08:16:06 IP:202.39.xxx.xxx 未訂閱
參考: 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.
系統時間:2024-05-13 12:28:18
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!