unit Dev_FA_Motion;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Protocol_Modbus;
type
{ TMotionItem }
TMotionItem = class(TCollectionItem)
private
FRepeatCount: Cardinal;
procedure SetRepeatCount(AValue: Cardinal);
protected
// function GetDisplayName: string; override;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
public
procedure Assign(Source: TPersistent); override;
published
property RepeatCount: Cardinal read FRepeatCount write SetRepeatCount default 1;
end;
TDev_FA_Motion = class;
TDeviceEnumerator = class(TCollectionEnumerator)
public
function GetCurrent: TMotionItem;
property Current: TMotionItem read GetCurrent;
end;
{ TMotionList }
TMotionList = class(TCollection)
private
FOwner: TDev_FA_Motion;
function GetDevice(AIndex: Integer): TMotionItem;
protected
function GetOwner: TPersistent; override;
public
constructor Create(AOwner: TDev_FA_Motion);
function GetEnumerator: TDeviceEnumerator; inline;
property Device[AIndex: Integer]: TMotionItem read GetDevice; default;
end;
{ TDev_FA_Motion }
TDev_FA_Motion = class(TProtocol_Modbus)
private
FDevices: TMotionList;
procedure SetDevices(AValue: TMotionList);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
public
function Add: TMotionItem;
published
property Devices: TMotionList read FDevices write SetDevices;
end;
procedure Register;
implementation
procedure Register;
begin
{$I dev_fa_motion_icon.lrs}
RegisterComponents('MyFun',[TDev_FA_Motion]);
end;
{ TDeviceEnumerator }
function TDeviceEnumerator.GetCurrent: TMotionItem;
begin
Result := TMotionItem(inherited GetCurrent);
end;
{ TMotionItem }
procedure TMotionItem.Assign(Source: TPersistent);
begin
inherited Assign(Source);
end;
constructor TMotionItem.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
FRepeatCount := 1;
end;
destructor TMotionItem.Destroy;
begin
inherited Destroy;
end;
procedure TMotionItem.SetRepeatCount(AValue: Cardinal);
begin
if FRepeatCount = AValue then exit;
FRepeatCount := AValue;
end;
{ TMotionList }
constructor TMotionList.Create(AOwner: TDev_FA_Motion);
begin
inherited Create(TMotionItem);
FOwner := AOwner;
end;
function TMotionList.GetEnumerator: TDeviceEnumerator;
begin
Result := TDeviceEnumerator.Create(Self);
end;
function TMotionList.GetOwner: TPersistent;
begin
Result := FOwner;
end;
function TMotionList.GetDevice(AIndex: Integer): TMotionItem;
begin
Result := Items[AIndex] as TMotionItem;
end;
{ TDev_FA_Motion }
function TDev_FA_Motion.Add: TMotionItem;
begin
Result := TMotionItem(FDevices.Add);
end;
constructor TDev_FA_Motion.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDevices := TMotionList.Create(Self);
end;
destructor TDev_FA_Motion.Destroy;
begin
FreeAndNil(FDevices);
inherited Destroy;
end;
procedure TDev_FA_Motion.SetDevices(AValue: TMotionList);
begin
if FDevices = AValue then exit;
FDevices := AValue;
end;
end.
Lazarus|delphi中,自定义控件中实现items列表操作【最小框架】
最新推荐文章于 2023-09-15 13:59:55 发布