【问题标题】:TMemo descendant with empty lines带有空行的 TMemo 后代
【发布时间】:2012-03-24 08:19:40
【问题描述】:

我的 TMemo 后代有构造函数

constructor TMyMemo.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Lines.Clear;
end;

当我将 TMyMemo 放在表单上时,我收到错误“Control '' has no parent window.”。为什么?

【问题讨论】:

  • 如果忽略它的设置,为什么要首先发布 Lines。而是从 TCustomMemo 派生。
  • @David - 我希望将“空”备忘录放在表单上。通常/总是然后我把 TMemo 放在我清除线条的表格上。我很懒:)
  • 你现在得到了一个很好的答案,但这个问题也很好地说明了为什么你应该解释你的潜在问题。
  • 我喜欢拥有无字幕控件(tpanel、tmemo 等)的想法。

标签: delphi vcl


【解决方案1】:

新创建的备忘录没有内容。但是,一旦组件获得名称,就会添加内容,这是由设计者自动完成的。为了防止这种情况,请从ControlStyle 中删除csSetCaption

constructor TMyMemo.Create(AOwner: TComponent); 
begin 
  inherited Create(AOwner); 
  ControlStyle := ControlStyle - [csSetCaption];
end; 

【讨论】:

  • 很好的答案。我想我也要创建一个 MyPanel 和 MyEdit。 :) 或者它是您可以在设计器中切换的选项?
【解决方案2】:

移动 Lines.Clear 以覆盖 CreateWnd 方法。创建执行期间不存在底层窗口控件(多行编辑)

【讨论】:

  • 这会在调用 CreateWnd 时清除内容,这比您想象的要多。
猜你喜欢
  • 1970-01-01
  • 2013-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多