组件编辑器可以在多个组件上执行吗? [英] Can a Component Editor be executed on multiple components?

查看:110
本文介绍了组件编辑器可以在多个组件上执行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短版本

我正在尝试为自己制作的自定义按钮实现我的第一个组件编辑器。在一些在线文章的帮助下,我已经成功安装了编辑器,并在窗体设计器中右键单击按钮时可以看到菜单项。

I am trying to implement my first ever Component Editor for a custom button I have made. With the help of some online articles I have successfully installed the editor and can see the menu item when I right click on my button in the Form Designer.

但是此组件编辑器选择多个按钮控件时,菜单不会显示。

But this component editor menu is not showing when selecting more than one of my button controls.

默认情况下,组件编辑器仅适用于单个选定控件,还是可以与多个选定控件一起使用,以及

Do Component Editors only work with single selected controls by default, or can they work with multiple selected controls and if so how?

长版

我当时正在实施一个TPropertyEditor用于我自己的一个组件,但现在决定更好地使用TComponentEditor,或者我想。

I was in the process of implementing a TPropertyEditor for one of my own components but have now decided that a TComponentEditor would be better served, or so I thought.

基本上,我有一个TCustomButton,我已经自己绘制过了,此按钮组件具有一些已发布的属性,用于更改外观,例如边框和填充颜色等。

Basically I have a TCustomButton which I have ownerdrawn, this button component has several published properties for changing the appearance such as the border and fill color etc.

我正在实现的组件编辑器在上下文菜单中显示一个新菜单项从文件加载设置。执行后,将显示一个简单的TOpenDialog,您可以在其中选择合适的文件,例如一个Ini File,然后我从中读取并设置File中的值。

The Component Editor I am implementing displays in the context menu a new menu item to "Load settings from a File". When executed a simple TOpenDialog is shown to which you can select the appropriate file, for example an Ini File which I then read and set the values from the File accordingly.

所有内容从我所看到的内容来看,它运行良好,但是由于我还是一个新手,并且在掌握Delphi的整个自定义控件方面,我注意到并没有发生某些事情-我不确定这是否是实际的预期行为,或者是否我可以更改它。

Everything is working good from what I can see, but as I am still sort of new and getting to grips with the whole custom controls side of Delphi I noticed something that does not happen - I am not sure if this is the actual intended behavior or whether I can change it.

问题是在按钮控件的多个选定实例上使用了组件编辑器菜单。如果仅选择一个按钮,然后在Designer中单击鼠标右键,则菜单会显示在上下文菜单的顶部,但是,多个选定的控件不会显示组件编辑器菜单。

The problem is using the Component Editor menu on multiple selected instances of my button control. If just one button is selected and I right click in the Designer, my menu is shown at the top of the context menu, however multiple selected controls do not display the Component Editor menu.

代码示例

type
  TMyButtonEditor = class(TComponentEditor)
  public
    procedure ExecuteVerb(Index: Integer); override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
  end;

implementation

{ TMyButtonEditor }

procedure TMyButtonEditor.ExecuteVerb(Index: Integer);
var
  OpenDialog: TOpenDialog;
begin
  case Index of
    0:
    begin
      OpenDialog := TOpenDialog.Create(nil);
      try
        OpenDialog.Filter := 'All Files (*.*)|*.*';

        if OpenDialog.Execute then
        begin
          // handle opened file..
        end;
      finally
        OpenDialog.Free;
      end;
    end;
  end;
end;

function TMyButtonEditor.GetVerb(Index: Integer): string;
begin
  case Index of
    0:
    begin
      Result := 'Load settings from File...';
    end;
  end;
end;

function TMyButtonEditor.GetVerbCount: Integer;
begin
  Result := 1;
end;

在注册过程中的单位:

RegisterComponentEditor(TMyButton, TMyButtonEditor);

根据我的观察,在任何给定时间,只有单个组件可以使用组件编辑器,或者我是错误并且可以在多个控件上使用它们?

From what I can see only single components can use a Component Editor at any given time, or am I wrong and they can be used on multiple controls?

我希望选择在表单设计器上选择3或4个按钮,然后使用组件编辑器应用导入的

I was hoping to select say maybe 3 or 4 of my buttons on the Form Designer and use the Component Editor to apply imported settings on those buttons all at once.

推荐答案

组件编辑器只能对单个组件进行操作。

Component editors can only operate on a single component.

这是一个非常好的理由,它希望尽可能通过对象检查器而不是组件编辑器来提供属性。因为对象检查器可以一次对多个组件进行操作。

This is one very good reason to prefer making properties available through the Object Inspector rather than component editors, wherever possible. Because the Object Inspector can operate on multiple components at once.

这篇关于组件编辑器可以在多个组件上执行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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