【问题标题】:Creating new Tshape component problem ,Delphi 7创建新的 Tshape 组件问题,Delphi 7
【发布时间】:2021-05-02 05:17:48
【问题描述】:

正在创建新的形状组件,它的名称:设备形状,但该组件没有注册并且它没有出现在组件板中。

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

谁能帮忙。

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. 

【问题讨论】:

  • 你把它放在包里了吗?你有Register 程序吗?你安装包了吗?
  • 是的。抱歉,我已尝试附上代码...但该网站要求提供更多详细信息..
  • 好吧,那么您应该听从建议并提供更多详细信息。所有相关代码(尤其是Register 过程),以及您尝试安装组件的如何的描述:单元、包、方法(例如右键单击包并选择“安装”) ,以及所发生情况的描述:显示的消息文本。
  • 我已经减少了附加代码..

标签: delphi components shapes


【解决方案1】:

来自the documentation on registering components

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

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

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

【讨论】:

  • 另外,在代码格式化方面你真的应该更加小心!作为一名软件开发人员,一个非常重要的部分是关心细节。 方式的问题太多了,我无法在评论中一一指出,但这里有几个例子:(1) 为什么有 两个 空格SetDeviceTxt的前面? (2) 为什么(前面有空格,有的时候没有空格? (3):之后? (4);之前? (5),之后? (6) 为什么你有时会写String 大写S?等等。我确实认为对细节的关注与最终结果的质量相关。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-08
  • 2011-07-02
  • 1970-01-01
  • 2019-09-17
  • 2014-08-11
  • 1970-01-01
相关资源
最近更新 更多