秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  278 随笔 :: 0 文章 :: 308 评论 :: 20万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
简单记录一下编写lazarus控件的流程,控件demo下载链接: https://pan.baidu.com/s/1Xsz88dgkPJ87au63MFoe8g?pwd=rt6k 提取码: rt6k
1.Package-->New Package

 2.输入新建控件的名称

 3、鼠标右键点file-->Add Files from file System添加控件文件

 4、添加包含控件注册的文件
正常情况下Register unit应该打勾的,如果添加后没打勾,用鼠标点Register unit打勾就可以

 5、如果新建的控件包含必须的依赖控件,鼠标右键点击Requitred Packages添加相应的控件就可以

6、以上文件添加完成后就可以新建一个控件安装包了
7、包含控件注册的文件和delphi区别不大,以下是一个范例:

复制代码
unit QFDataSetDemo;

interface

uses
  Classes,
  SysUtils,
  math,
  DB,
  StdCtrls,
  ExtCtrls,
  lazutf8,
  LCLType,
  LCLIntf,
  BufDataSet
  ;

type

  TQFJsonConnectionDemo = class(TComponent)
  private
    FServerAddr: string ;
    FServerPort: string ;
    FUserName:string;
    FPassWord:string;
    Ftoken:string;
    FIsLogin:string;
    FConnectionDefName: string;
    FConnectionList:TStringList;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property UserName: string read FUserName write FUserName;
    property PassWord: string read FPassWord write FPassWord;
    property ConnectionList:TStringList read FConnectionList;
    property ConnectionDefName: string read FConnectionDefName write FConnectionDefName;
  end;

  TQFJSONTableDemo = class(TBufDataSet)
  private
    FQFJsonConnection:TQFJsonConnectionDemo;
    FSQL: string ;
    FTableName: string ;
    FKeyFields: string ;
  public
    constructor Create(AOwner: TComponent);override;
    destructor Destroy; override;
  published
    property Connection: TQFJsonConnectionDemo read FQFJsonConnection write FQFJsonConnection;
    property TableName: string read FTableName write FTableName;
    property KeyFields: string read FKeyFields write FKeyFields;
  end;

  TQFJSONQueryDemo = class(TBufDataSet)
  private
    FQFJsonConnection:TQFJsonConnectionDemo;
    FSQL: string ;
    FTableName: string ;
    FKeyFields: string ;
  public
    constructor Create(AOwner: TComponent);override;
    destructor Destroy; override;
  published
    property Connection: TQFJsonConnectionDemo read FQFJsonConnection write FQFJsonConnection;
    property TableName: string read FTableName write FTableName;
    property KeyFields: string read FKeyFields write FKeyFields;
  end;

  procedure Register;

implementation

{$R *.res}

procedure Register;
begin
  RegisterComponents('QFDataSetDemo', [TQFJsonConnectionDemo,TQFJSONTableDemo,TQFJSONQueryDemo]);
end;

constructor TQFJsonConnectionDemo.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FServerAddr:='localhost';
  FServerPort:='8112';
  FUserName:='qf';
  FPassword:='qf';
  FConnectionDefName:='';
  Ftoken:='';
  FIsLogin:='';
  FConnectionList:=TStringList.Create;
end;

destructor TQFJsonConnectionDemo.Destroy;
begin
  inherited Destroy;
  Ftoken:='';
  FIsLogin:='';
  FConnectionList.Free;
end;

constructor TQFJSONQueryDemo.Create(AOwner: TComponent);
begin
  inherited ;
  FSQL := '';
  FTableName :='';
  FKeyFields :='';
end;

destructor TQFJSONQueryDemo.Destroy;
begin
  inherited Destroy;
end;

constructor TQFJSONTableDemo.Create(AOwner: TComponent);
begin
  inherited ;
  FSQL := '';
  FTableName :='';
  FKeyFields :='';
end;

destructor TQFJSONTableDemo.Destroy;
begin
  inherited Destroy;
end;


initialization

end.
复制代码

8、最后,为控件添加图标,记得res资源文件中的名称要和控件名称一致才可以在IDE显示正确的图标

 安装后的控件:

 

posted on   秋·风  阅读(891)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示