繼承TDBLookupComboBox物件,編譯無錯誤,表單使用出現Has no Parent window. |
缺席
|
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
各位前輩和版主大人:
我欲繼承TDBLookupComboBox,這個物件,之前使用TDBEDIT來開發自訂vcl元件都沒有錯誤,但改用TDBLookupComboBox卻出現 Has no Parent window.錯誤訊息,不知道要怎麼改正! 懇請大家幫忙! 謝謝! unit TUCombobox_; interface uses DateUtils, Forms, Windows, Messages, SysUtils, Classes, Controls, StdCtrls, DBCtrls, Dialogs, Buttons, DB, Graphics, ADODB, Variants; type TUCombobox = class(TWinControl) private { Private declarations } Fparent: Variant; UTDBLookupComboBox: TDBLookupComboBox; protected { Protected declarations } procedure CreateParams(var Params: TCreateParams); override; //--------------------------------------------------------- function Get_Datasource: TDatasource; procedure Set_Datasource(aDS: TDatasource); //--------------------------------------------------------- function Get_DataField: string; procedure Set_DataField(aField: string); //--------------------------------------------------------- procedure Loaded; override; public { Public declarations } procedure Setfocus; override; constructor Create(Aowner: TComponent); override; destructor Destroy; override; published { Published declarations } property Datasource: TDatasource read Get_Datasource write Set_Datasource; property DataField: string read Get_DataField write Set_DataField; end; procedure Register; implementation uses TYaoCalendar_PAS, Math; procedure TUCombobox.CreateParams(var Params: TCreateParams); begin inherited; UTDBLookupComboBox.Parent := self; end; constructor TUCombobox.Create(AOwner: TComponent); // 建構子、建立物件初始狀態 begin inherited Create(AOwner); UTDBLookupComboBox := TDBLookupComboBox.Create(Self); UTDBLookupComboBox.parent := self; UTDBLookupComboBox.width := 100; UTDBLookupComboBox.Height := 20; UTDBLookupComboBox.TOP := 0; UTDBLookupComboBox.Font.Size := 12; UTDBLookupComboBox.Font.Name := '新細明體'; UTDBLookupComboBox.DataSource := nil; UTDBLookupComboBox.DataField := ''; self.Height := 25; self.Width := 240; end; destructor TUCombobox.Destroy; begin UTDBLookupComboBox.Free; inherited Destroy; end; procedure Register; begin RegisterComponents('YAOS', [TUCombobox]); end; procedure TUCombobox.Loaded; begin inherited Loaded; end; procedure TUCombobox.Setfocus(); begin UTDBLookupComboBox.SetFocus; end; function TUCombobox.Get_Datasource: TDatasource; begin Result := UTDBLookupComboBox.DataSource; end; procedure TUCombobox.Set_Datasource(aDS: TDatasource); begin if (aDS <> UTDBLookupComboBox.Datasource) then begin UTDBLookupComboBox.DataSource := aDS; end; if aDS = nil then begin UTDBLookupComboBox.DataField := ''; UTDBLookupComboBox.DataSource := nil; end; end; //============================================================================== function TUCombobox.Get_DataField: string; begin Result := UTDBLookupComboBox.DataField; ; end; procedure TUCombobox.Set_DataField(aField: string); var i: Integer; begin if (UTDBLookupComboBox.DataField <> aField) then begin UTDBLookupComboBox.DataField := aField; end; end; end.
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」 程式寫的越久,卻發現自己越來越不會寫程式! |
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
我看了原始vcl的定義,TDBLookupComboBox元件好像還有很多子元件,不知道是否我繼承時還需要指定子元件的Parent
constructor TDBLookupComboBox.Create(AOwner: TComponent); begin inherited Create(AOwner); ControlStyle := ControlStyle [csReplicatable]; Width := 145; Height := 0; FDataList := TPopupDataList.Create(Self); FDataList.Visible := False; FDataList.Parent := Self; FDataList.OnMouseUp := ListMouseUp; FButtonWidth := GetSystemMetrics(SM_CXVSCROLL); FDropDownRows := 7; end; 昏到中,這個我會用就有鬼啦!救人啊!
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」 程式寫的越久,卻發現自己越來越不會寫程式! |
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
我在表單上動態建立是OK的啊,不知道少什麼?
procedure TFRM_USER.Button1Click(Sender: TObject); var tb: TDBLookupComboBox; begin tb := TDBLookupComboBox.Create(self); tb.Parent := self; tb.Top := 50; tb.Width := 200; tb.DataSource := self.DS1; tb.DataField := '員工編號'; tb.ListSource := self.DataSource1; tb.ListField := '姓名'; tb.KeyField := '員工編號'; end;
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」 程式寫的越久,卻發現自己越來越不會寫程式! |
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
改成如下也是不行:真是想破頭了! 大家幫幫忙!
constructor TUCombobox.Create(AOwner: TComponent); // 建構子、建立物件初始狀態 begin inherited Create(AOwner); if AOwner is TForm then begin Set_Parent(TForm(AOwner).Name); end; UTDBLookupComboBox := TDBLookupComboBox.Create(Self); UTDBLookupComboBox.parent := self; UTDBLookupComboBox.ParentWindow := tform(Application.FindComponent(TForm(AOwner).Name)).Handle; UTDBLookupComboBox.width := 100; UTDBLookupComboBox.Height := 20; UTDBLookupComboBox.TOP := 0; UTDBLookupComboBox.Font.Size := 12; UTDBLookupComboBox.Font.Name := '新細明體'; UTDBLookupComboBox.DataSource := nil; UTDBLookupComboBox.DataField := ''; self.Height := 25; self.Width := 240; end;
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」 程式寫的越久,卻發現自己越來越不會寫程式! |
hagar
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
|
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
我又試了,在表單上動態建立TDBComboBox,原來我不會,不知道怎麼建立才正確
var tudbCombobox: TDBComboBox; begin tudbCombobox := TDBComboBox.Create(self); tudbCombobox.DataField := '員工編號'; tudbCombobox.DataSource := DS1; tudbCombobox.Parent := FRM_USER; tudbCombobox.CreateParented(FRM_USER.WindowHandle); end; 拖拉式開發太久,真的不會寫啦! Has no Parent window
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」 程式寫的越久,卻發現自己越來越不會寫程式! |
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
表單上動態建立TDBComboBox改成如下程式碼就ok!但是若寫成物件還是一樣失敗http://delphi.ktop.com.tw/board.php?cid=31&fid=97&tid=86526
var tudbCombobox: TDBComboBox; begin tudbCombobox := TDBComboBox.Create(self); tudbCombobox.Parent := FRM_USER; tudbCombobox.CreateParented(FRM_USER.WindowHandle); tudbCombobox.DataField := '員工編號'; tudbCombobox.DataSource := DS1; end; 拖拉式開發太久,真的不會寫啦! Has no Parent window
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」 程式寫的越久,卻發現自己越來越不會寫程式! |
hagar
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
拿掉藍色的部份, 改成紅色的部份試試
把 Create TDBLookupComboBox 的部份放到 CreateWnd
typeTUCombobox = class(TWinControl) private { Private declarations } UTDBLookupComboBox: TDBLookupComboBox; Fparent: string; protected { Protected declarations } //procedure CreateParams(var Params: TCreateParams); override; //--------------------------------------------------------- function Get_Parent: string; // 傳回值 procedure Set_Parent(Value: string); // 設定值,不傳回值 //--------------------------------------------------------- function Get_Datasource: TDatasource; procedure Set_Datasource(aDS: TDatasource); //--------------------------------------------------------- function Get_DataField: string; procedure Set_DataField(aField: string); //--------------------------------------------------------- procedure Loaded; override; procedure CreateWnd; override; public { Public declarations } procedure Setfocus; override; constructor Create(Aowner: TComponent); override; destructor Destroy; override; published { Published declarations } property Datasource: TDatasource read Get_Datasource write Set_Datasource; property DataField: string read Get_DataField write Set_DataField; property RunParent: string read Get_Parent write Set_Parent; end; procedure Register; implementation {procedure TUCombobox.CreateParams(var Params: TCreateParams); begin inherited; // UTDBLookupComboBox.Parent := self; // UTDBLookupComboBox.Parent := tform(Get_DataField); // 亂下的 // UTDBLookupComboBox.ParentWindow := tform(Get_DataField).Handle; // 亂下的 end; } constructor TUCombobox.Create(AOwner: TComponent); // 建構子、建立物件初始狀態 begin inherited Create(AOwner); // 設定上層物件 // ================================ //if AOwner is TForm then //begin // Set_Parent(TForm(AOwner).Name); //end; self.Height := 25;
self.Width := 240; end;
destructor TUCombobox.Destroy;begin UTDBLookupComboBox.Free; inherited Destroy; end; procedure Register; begin RegisterComponents('YAOS', [TUCombobox]); end; procedure TUCombobox.Loaded; begin inherited Loaded; end; procedure TUCombobox.Setfocus(); begin UTDBLookupComboBox.SetFocus; end; function TUCombobox.Get_Datasource: TDatasource; begin Result := UTDBLookupComboBox.DataSource; end; procedure TUCombobox.Set_Datasource(aDS: TDatasource); begin if (aDS <> UTDBLookupComboBox.Datasource) then begin UTDBLookupComboBox.DataSource := aDS; end; if aDS = nil then begin UTDBLookupComboBox.DataField := ''; UTDBLookupComboBox.DataSource := nil; end; end; //============================================================================== function TUCombobox.Get_DataField: string; begin Result := UTDBLookupComboBox.DataField; ; end; procedure TUCombobox.Set_DataField(aField: string); begin if (UTDBLookupComboBox.DataField <> aField) then begin UTDBLookupComboBox.DataField := aField; end; end; //============================================================================== function TUCombobox.Get_Parent: string; begin Result := Fparent; end; procedure TUCombobox.Set_Parent(Value: string); begin if Fparent <> Value then begin Fparent := Value; end; end; procedure TUCombobox.CreateWnd; begin inherited; UTDBLookupComboBox := TDBLookupComboBox.Create(Self); UTDBLookupComboBox.Parent := Self; UTDBLookupComboBox.DataSource := nil; UTDBLookupComboBox.DataField := ''; UTDBLookupComboBox.width := 100; UTDBLookupComboBox.Height := 20; UTDBLookupComboBox.TOP := 0; UTDBLookupComboBox.Font.Size := 12; UTDBLookupComboBox.Font.Name := '新細明體'; end; end. |
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
|
danny
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:100 回覆:522 積分:595 註冊:2002-03-11 發送簡訊給我 |
|
danny
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:100 回覆:522 積分:595 註冊:2002-03-11 發送簡訊給我 |
|
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
|
syntax
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:26 回覆:1139 積分:1258 註冊:2002-04-23 發送簡訊給我 |
|
g9221712
高階會員 ![]() ![]() ![]() ![]() 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |