创建自定义控件.我必须给他们起个名字吗? [英] Creating custom controls. Do I have to give them a name?

查看:32
本文介绍了创建自定义控件.我必须给他们起个名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我从TPanel创建并安装了自己的控件.它仅包含一个按钮:

Let's say I create (from TPanel) and install my own control. It contains only one button:

constructor TMyPanel.Create(aOwner: TComponent);
begin
 inherited Create(aOwner);

 btn:= TButton.Create(Self);
 btn.Parent:= Self;   
 btn.Name:= 'xxx';      <-------- mandatory?
end;

为该面板命名是强制性的吗?

Is it mandatory to give a name to that panel?

这个问题从dummzeuch在这里发表的评论开始:

This question started from a comment posted by dummzeuch here:

这种情况发生在您的标签没有名字的时候.IDE添加仅当控件具有名称时才向类声明(否则如何应该声明吗?).

This happens when your label doesn't have a name. The IDE adds declarations to the class only if the control has got a name (how else should it declare it?).

(我仅指该评论)

推荐答案

否,您无需命名子组件.

No, you do not need to name sub components.

但是,如果您打算将对子组件的访问权限公开为在DFM中流式传输的属性,则确实需要标记子组件,至少:

However, if you intent on exposing access to a sub componenet as a property that gets streamed in a DFM, you do need to mark the sub component, at least:

constructor TMyPanel.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  btn := TButton.Create(Self);
  btn.Parent := Self;
  btn.SetSubComponent(True); // <-- ADD THIS
end;

这篇关于创建自定义控件.我必须给他们起个名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆