Delphi中删除控件的默认命名

时间:2018-04-27 06:31:21

标签: delphi delphi-10.2-tokyo

当我在设计时在我的表单上添加新控件时,Delphi会为它们提供默认名称。 TLabel控件将命名为'Label1''Label2'等。

我创建了自己的组件类:tMyLabel。请注意小写t。 Delphi将这些控件命名为'tMyLabel1''tMyLabel2'等。我不想在开头使用't'。

我意识到这与班级名称有关。在这种情况下,Delphi似乎区分大小写。

如果我将班级重命名为TMyLabel,那么一切正常。

为什么Delphi在这个问题上区分大小写?我能说服德尔福不要区分'tMyLabel''TMyLabel'吗?

我使用的是Delphi 10.2.3,但是Delphi多年来一直表现得很好。

编辑(2018-04-30): 肯要求代码

    unit MySpeedButton;

    interface

    uses
      SysUtils, Classes, Controls, Vcl.Graphics, Buttons;

    type
      tMySpeedButtonProps = class(TPersistent)
      private
        fParent      : pointer      ;
        constructor Create( pParent : pointer );
        destructor  Destroy; override;
      end;

    type
      tMySpeedButton = class( TSpeedButton )
      private
        fMyProps      : tMySpeedButtonProps  ;
      protected
        procedure    Click ; override;
      public
        function  GetCanvas: TCanvas;                 //Allow access to the Canvas            procedure Paint ; override ;
        constructor Create( AOwner : TComponent ); override;
        destructor  Destroy; override;
      published
        property TM : tMySpeedButtonProps read fMyProps write fMyProps;
      end;

    procedure Register;

    implementation

    uses
      Forms, Windows;

    constructor tMySpeedButtonProps.Create( pParent : pointer );
    begin
      inherited Create;
      fParent  := pParent ;
    end;

    destructor tMySpeedButtonProps.Destroy;
    begin
      inherited Destroy;
    end;

    constructor tMySpeedButton.Create(AOwner: TComponent);
    begin
      fMyProps := tMySpeedButtonProps.Create( self );
      inherited Create(AOwner);

    {$ifdef RegisterFormular }
    {$endif}
    end;

    destructor tMySpeedButton.destroy;
    begin
      fMyProps.Free;
      inherited destroy;
    end;

    procedure tMySpeedButton.Click ;
    begin
      inherited Click;
    end;

    procedure tMySpeedButton.Paint ;
    begin
      inherited Paint;
    end;

    function tMySpeedButton.GetCanvas: TCanvas;
    begin
      Result:= Canvas;
    end;

    procedure Register;
    begin
      RegisterComponents( 'Test' , [ tMySpeedButton ] );
    end;

    end.

我编译后&注册tMySpeedButton我得到以't'开头的不需要的名字。

0 个答案:

没有答案