線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2028
推到 Plurk!
推到 Facebook!

有關自訂物件的顯示位置?

缺席
JuliusChen
一般會員


發表:13
回覆:8
積分:4
註冊:2005-06-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-10-13 16:11:15 IP:220.134.xxx.xxx 未訂閱
請教各位前輩: 我有段程式碼如下: constructor TSearchText.Create(Aowner: TComponent); begin inherited Create(AOwner); //繼承原有的建構子 LblVisible := True ; //動態建構 Edit FEdit :=Tedit.Create(Self); FEdit.Parent:=Self; FEdit.Height:=22; FEdit.Width:=100; //動態建構 Button FButton:=TButton.Create(Self); FButton.Parent:=Self; FButton.Top:=FEdit.Top; FButton.Left:=FEdit.Left FEdit.Width; FButton.Width:=40; FButton.Caption :='搜尋'; //動態建構 Label FLabel:=TLabel.Create(Self); FLabel.Parent:=Self; FLabel.Left:=FEdit.Left FEdit.Width FButton.Width; Flabel.top:=Fedit.top; FLabel.Height:=FEdit.Height; FLabel.Width:=140; FLabel.Color:=clYellow; FLabel.AutoSize:=False; FLabel.Visible:=LblVisible; //動態建構 DBLookupListBox FDBLookupComboBox:=TDBLookupComboBox.Create(Self); //FDBLookupComboBox.Parent:=TWinControl(AOwner); //FDBLookupComboBox.Parent:=self; FDBLookupComboBox.Enabled:=False; FDBLookupComboBox.Left:=FEdit.Left FEdit.Width FButton.Width FLabel.Width; FDBLookupComboBox.top:=Fedit.top; FDBLookupComboBox.Height:=FEdit.Height; FDBLookupComboBox.Width:=140; FDBLookupComboBox.Visible:=True; //元件 Width:=FEdit.Width FLabel.Width FButton.Width 10; //元件的寬度 Height:=FLabel.Height 5; //元件的高度 ButtonOnClick:=dispose; //事件內容 TextOnChange:=TextKey; DBLCBOnExit:=DBLCBClick; end; 在關於 DBLookupcomboBox 部份. 我如果使用 FDBLookupComboBox.Parent:=self; 新增物件時會有 Control '' has no parent window error . 如果使用 FDBLookupComboBox.Parent:=TWinControl(AOwner); 他又不會在我定位的地方顯示. 如果不加這一行,就看不到它顯示了.. 不知有何解? 非常感謝!!
g9221712
高階會員


發表:145
回覆:344
積分:162
註冊:2006-07-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-01-23 20:47:54 IP:220.134.xxx.xxx 訂閱
我建議改用繼承TWinControl,因為你好像是使用複合物件!
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」
程式寫的越久,卻發現自己越來越不會寫程式!
nicktop
一般會員


發表:2
回覆:9
積分:7
註冊:2007-01-20

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-01-23 21:48:20 IP:125.232.xxx.xxx 訂閱
g9221712
高階會員


發表:145
回覆:344
積分:162
註冊:2006-07-06

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-01-29 04:04:26 IP:220.134.xxx.xxx 訂閱
 我測試了一下,問題跟你一樣! 而且錯誤只會出現在使用InfoPower元件的情況下,才會出現!不知道什麼原因?
Control '' Has no Parent window. 的錯誤
xxx.parent := tform(AOwner);
xxx.ParentWindow := tform(AOwner).Handle; //AOwner
xxx.parent := TWinControl(AOwner); // 你的方式

上個回答,我現在看來也是亂回答!真是對不起!

尋求版上前輩高手給予解答!

------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」
程式寫的越久,卻發現自己越來越不會寫程式!
hagar
版主


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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-01-29 18:21:31 IP:59.124.xxx.xxx 未訂閱
試試如下的方式:
type
TUDBLookupComboBox = class(TPanel)
private
FDBLookupComboBox: TDBLookupComboBox;
protected
procedure SetParent(AParent: TWinControl); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;

// ....


{ TUDBLookupComboBox }

constructor TUDBLookupComboBox.Create(AOwner: TComponent);
begin
inherited;

FDBLookupComboBox := TDBLookupComboBox.Create(Self);
FDBLookupComboBox.Left := 6;
FDBLookupComboBox.Top := 12;
FDBLookupComboBox.Width := 140;
FDBLookupComboBox.Visible := True;
end;

destructor TUDBLookupComboBox.Destroy;
begin

inherited;
end;

procedure TUDBLookupComboBox.SetParent(AParent: TWinControl);
begin
inherited;

if Assigned(FDBLookupComboBox) and (FDBLookupComboBox.Parent <> AParent) then
FDBLookupComboBox.Parent := AParent;
end;

// -----------------------------------------------------------------------------
var
c: TUDBLookupComboBox;


procedure TForm1.Button1Click(Sender: TObject);
begin
c := TUDBLookupComboBox.Create(nil);
c.Parent := Self;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if Assigned(c) then FreeAndNil(c);
end;
g9221712
高階會員


發表:145
回覆:344
積分:162
註冊:2006-07-06

發送簡訊給我
#6 引用回覆 回覆 發表時間:2007-01-29 18:35:58 IP:220.134.xxx.xxx 訂閱
一樣無法解決!
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」
程式寫的越久,卻發現自己越來越不會寫程式!
g9221712
高階會員


發表:145
回覆:344
積分:162
註冊:2006-07-06

發送簡訊給我
#7 引用回覆 回覆 發表時間:2007-01-30 01:46:55 IP:220.134.xxx.xxx 訂閱
我發現只要有用到Left、top、Height、Width這樣的屬性,就會出現Has no Parent window,真是奇怪,只要將這給行Mark起來就沒問題
而且若有宣告

FDBLookupComboBox.Left:=FEdit.Left FEdit.Width FButton.Width FLabel.Width;
FDBLookupComboBox.top:=Fedit.top;
FDBLookupComboBox.Height:=FEdit.Height;
FDBLookupComboBox.Width:=140;
protected
{ Protected declarations }
procedure CreateParams(var Params: TCreateParams); override;

他會在執行上述給行時,去呼叫CreateParams
procedure TYaoCombobox.CreateParams(var Params: TCreateParams);
begin
inherited;
FDBLookupComboBox.Parent := self;
end;



------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」
程式寫的越久,卻發現自己越來越不會寫程式!
系統時間:2024-04-26 12:49:17
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!