程序如下,创建好控件后,拖在窗体上,cpu的使用率是1000%
不久就出现栈溢出
这是怎么回事,如何解决?
type
TNComboBoxEx = class(TComboBox)
protected
ComboBoxBtn : TButton;
public
procedure CreateParams(var Params: TCreateParams); override;procedure TNComboBoxEx.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
ComboBoxBtn := TButton.Create(self);
ComboBoxBtn.Parent := self;
ComboBoxBtn.Top := 0;
ComboBoxBtn.Height := Height;
ComboBoxBtn.Width := Height;
ComboBoxBtn.Left := Width-ComboBoxBtn.Width;
ComboBoxBtn.Visible :=true;
end;
不久就出现栈溢出
这是怎么回事,如何解决?
type
TNComboBoxEx = class(TComboBox)
protected
ComboBoxBtn : TButton;
public
procedure CreateParams(var Params: TCreateParams); override;procedure TNComboBoxEx.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
ComboBoxBtn := TButton.Create(self);
ComboBoxBtn.Parent := self;
ComboBoxBtn.Top := 0;
ComboBoxBtn.Height := Height;
ComboBoxBtn.Width := Height;
ComboBoxBtn.Left := Width-ComboBoxBtn.Width;
ComboBoxBtn.Visible :=true;
end;
解决方案 »
- 请教怎么实现tcombobox的效果?!
- 求救啊!帮忙翻译一段delphi的代码到C#
- 阻塞型Socket的例子下载不了,能发给我一份吗?
- delphi写的dll,被pb调用时非法操作
- 应该自豪的一刻!中国进行首次载人航天 神舟五号发射升空
- 为什么调试的时候打开“打开”对话框总是进入cpu调试窗口?
- 如何快速地在adoquery中查找?
- 求Interbase 6 的Unlock Key
- 如何得到DELPHI6的Samples页的ShellTreeView控件的选中结点的路径的全名?
- 请问各位好人帮帮小妹:关于语音卡等相关录音功能
- com初级问题(答案满意可以继续加分)
- STRINGGRID中怎样把其中的字段值相加呢
type
TNComboBoxEx = class(TComboBox)
protected
ComboBoxBtn : TButton;
FUsesButton: bool;
procedure SetUsesButton(Value: bool);
public
procedure CreateParams(var Params: TCreateParams); override;
published
property UsesButton: bool read FUsesButton write SetUsesButton default false;
end;
procedure Register;
...procedure TNComboBoxEx.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
if(fUsesButton) then
begin
ComboBoxBtn := TButton.Create(self);
ComboBoxBtn.Parent := self;
ComboBoxBtn.Top := 0;
ComboBoxBtn.Height := Height;
ComboBoxBtn.Width := Height;
ComboBoxBtn.Left := Width-ComboBoxBtn.Width;
ComboBoxBtn.Visible :=true;
end;
end;
procedure TNComboBoxEx.SetUsesButton(Value: bool);
begin
if(FUsesButton<>Value) then
begin
if(Assigned(ComboBoxBtn)) then
ComboBoxBtn.Free;
FUsesButton := Value;
if(value) then
Style := csSimple
else
self.Style := csDropDown ;
end;
end;
就这样就会出现死循环(在编辑环境下),在运行环境下是好的。
ComboBoxBtn.Parent := self;代码时的 时候就会重新调用CreateParams函数。
不过我还是搞不懂为什么会调用?
CreateParam函数是用来改变窗口的风格的。