创建新的 Tshape 组件问题,Delphi 7

问题描述

正在创建新的形状组件,其名称为:设备形状,但该组件未注册且未出现在组件面板中。

代码编译没有任何错误,但我无法注册新组件。

谁能帮忙。

unit DeviceShape;
interface
uses
  SysUtils,Windows,Classes,Graphics,Controls,ExtCtrls;
  type
 TdeviceType=(Smoke,Heat,Control_Module,Monitor_Module,Bell,Break_Glass,Sirin);
 TdeviceShape=class(TShape)
private
   FDevType:TdeviceType;
   FdeviceTxt:string;
   procedure  SetDeviceTxt(Value:String);
   procedure SetDeviceType (Value:TdeviceType);
public
    constructor Create (AOwner: TComponent); override;
 protected
 procedure Paint; override   ;
 published
    property Text: string read FdeviceTxt write SetDeviceTxt default 'S' ;
    property DeviceType:TdeviceType read FDevType write SetDeviceType default Smoke;
    property OnClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnMouseDown;
    property OnMouseMove;
    property onmouseup;
end;
procedure register ;
implementation
    procedure Register;
begin
RegisterComponents('Issam',[TdeviceShape]);
end;

在这里你可以找到下一个程序主体:

procedure TdeviceShape.Paint;
begin
Canvas.Font.Height:=Width-(Width div 4) ;
Canvas.textout(0,(Height div 2)-(Canvas.Font.Height div 2),FdeviceTxt);
inherited;
end;
procedure TdeviceShape.SetDeviceTxt(Value:String);
begin
case FDevType of
Smoke             : FdeviceTxt:='S';
Heat                  : FdeviceTxt:='H';
Control_Module : FdeviceTxt:='C';
Monitor_Module : FdeviceTxt:='M';
Bell                    : FdeviceTxt:='B';
Break_Glass     : FdeviceTxt:='BG';
Sirin                : FdeviceTxt:='SI' ;
end;
Invalidate;
end;
procedure TdeviceShape.SetDeviceType(Value: TdeviceType);
begin
  if FDevType <> Value then
  begin
    FDevType := Value;
    Invalidate;
  end;
end;
end. 

解决方法

来自the documentation on registering components

注册涉及在包的一个单元中编写单个程序,该程序必须具有名称注册Register 程序必须出现在您单元的界面部分,并且(与 Delphi 的其余部分不同)其名称区分大小写。

注意:虽然 Delphi 是一种不区分大小写的语言,但 Register 过程区分大小写,并且必须用大写的 R 拼写。 >

所以看起来你需要在接口部分写 Register 而不是 register