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

Design-time及Runtime的問題!!

答題得分者是:mustapha.wang
ucdesign2
一般會員


發表:24
回覆:33
積分:11
註冊:2002-10-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-23 10:15:07 IP:211.23.xxx.xxx 未訂閱
先前問了如何在自製元件的屬性中可下拉資料供選取,那問題已得到解答! 但那下拉資料內容如果是來自在自製元件create時所產生的資料,請問要如何 做?試了很久都失敗!想請眾前輩幫忙,謝謝!!! Source code 簡略如下,有edit2tableReg.pas及doedit2table.pas 在edit2tableReg.pas中有uses doedit2table, MasterTable屬性資料要如何取得FConnect所指資料庫中的所有資料表名稱?    unit Edit2TableREG; interface uses   Windows, Classes, Forms, StdCtrls,DesignIntf, DesignEditors; type   TMasterTableProperty = class(TStringProperty) // Property Editor Class   public     function GetAttributes: TPropertyAttributes; override;     procedure GetValues(Proc: TGetStrProc); override;   end;   procedure Register;    implementation USES doedit2table; {$R *.DCR} { TMasterTableProperty } function TMasterTableProperty.GetAttributes: TPropertyAttributes; begin Result := [paValueList, paAutoUpdate, paSortList]; end; procedure TMasterTableProperty.GetValues(Proc: TGetStrProc); var MasterTable: TStrings; TableNum: Integer; begin MasterTable := nil; try MasterTable := TStringList.Create; //此處如何實做MasterTable屬性的內容 //MasterTable.Add('MTable1'); // will add into Combobox item //MasterTable.Add('MTable2'); for TableNum := 0 to MasterTable.Count - 1 do Proc(MasterTable[TableNum]); finally MasterTable.Free; end; end; procedure Register; begin RegisterComponents('Custom', [TEdit2Table]); RegisterPropertyEditor(TypeInfo(String), TEdit2Table, 'MasterTable', TMasterTableProperty); end; end. //-------------------DOEdit2Table------------------------ unit DOEdit2Table; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls……, type TEditDataLink1 = class; TEdit2Table = class(TCustomPanel) private FDataLink1: TEditDataLink1; SL: TStrings; FConnect:TADOConnection; FAdoDataSet1:TADODataSet; FAdoDataSet2:TADODataSet; FDatasource1: TDataSource; FDatasource2: TDataSource; FMasterTable:String; protected procedure Resize;override; procedure DataChanged; procedure EditingChanged; procedure ActiveChanged; procedure Notification(AComponent: TComponent; Operation: TOperation); override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Loaded; override; published property MasterTable:String read FMasterTable write FMasterTable; : : constructor TEdit2Table.Create(AOwner: TComponent); var opt1:TDBGridOptions; opt2:TDBGridOptions; INDEX:INTEGER; begin inherited Create(AOwner); FDataLink1 := TEditDataLink1.Create(Self); : : FDatasource1:=TDataSource.Create(Self); FDatasource2:=TDataSource.Create(Self); FConnect:=TADOConnection.Create(self); FConnect.Name:='ADOConnection1'; FConnect.ConnectionString:='Provider=SQLOLEDB.1;Password=1209;Persist Security Info=True;User ID=sa;Initial Catalog=PRS;Data Source=server'; SL := TStringList.Create; FConnect.GetTableNames(SL,False); // ←
mustapha.wang
資深會員


發表:89
回覆:409
積分:274
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-23 13:40:02 IP:218.80.xxx.xxx 未訂閱
procedure TMasterTableProperty.GetValues(Proc: TGetStrProc);
var
  TableNum: Integer;
  ATable:TEdit2Table;
begin
  ATable:=TEdit2Table(GetComponent(0));
  for TableNum := 0 to ATable.SL.Count - 1 do
    Proc(ATable.SL[TableNum]);
end;
久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听
------
江上何人初见月,江月何年初照人
ucdesign2
一般會員


發表:24
回覆:33
積分:11
註冊:2002-10-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-23 14:08:19 IP:211.23.xxx.xxx 未訂閱
非常感謝mustapha.wang前輩的指導!! 問題已解決了!謝謝!!!< >< >
系統時間:2024-05-17 15:10:14
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!