Участник:ArmorAdmin/Нумератор

Материал из Бронетанковой Энциклопедии — armor.kiev.ua/wiki
Перейти к: навигация, поиск

CounterDiagram.png

unit counter;

interface

uses
  Classes, StdCtrls, ExtCtrls, Controls, SysUtils, RegExpr, Dialogs;

type

ICounters = interface(IUnknown)
  ['{75533674-8A39-4501-97E7-0A8F9BB5625F}']
  // Возвращает список имеющихся во внешней системе счётчиков
  procedure GetTriggers(aList: TStrings);

  // Возвращает следующее значение счётчика
  function TriggerNext(TriggerName: string): string;

  // Возвращает список системных полей SystemCode=Caption
  // SystemCode - код поля в системе
  // Caption - название поля
  procedure GetSystemCodes(aList: TStrings);

  // Возвращает текущее значение поля в системе
  function SystemCode(CodeName: string): string;
end;


TCounterPart = class;
TCounterPartClass = class of TCounterPart;

TCounter = class(TStringList)
private
  FCounterName: string;
  FICounters: ICounters;
public
  constructor Create(aName: string; I: ICounters; template: string = '');
  procedure AddPart(Part: TCounterPart);
  procedure Clear; override;
  function GetTemplate: string;
  procedure ParceTemplate(template: string);
  function GetSample: string;
  function Generate: string;
  property CounterName: string read FCounterName write FCounterName;
  property CounterInterface: ICounters read FICounters;
end;

TCounterPart = class abstract (TPersistent)
private
  FValue: string;
  FCounter: TCounter;
  function GetValue: string;
  procedure SetValue(const aValue: string);
public
  function GetControlType: TControlClass; virtual;
  function GetName: string; virtual;
  function GetTemplate: string;
  function GetSample: string; virtual;
  function Generate: string; virtual;
  procedure InitControlData(aControl: TControl); virtual;
  property Value: string read GetValue write SetValue;
end;


TCounterPartText = class(TCounterPart)
public
  function GetName: string; override;
  function GetControlType: TControlClass; override;
end;

TCounterPartDate = class(TCounterPart)
public
  function GetName: string; override;
  function GetControlType: TControlClass; override;
  function Generate: string; override;
  procedure InitControlData(aControl: TControl); override;
end;

TCounterPartTrigger = class(TCounterPart)
public
  function GetName: string; override;
  function GetControlType: TControlClass; override;
  function Generate: string; override;
  procedure InitControlData(aControl: TControl); override;
  function GetSample: string; override;
end;

TCounterPartCase = class(TCounterPart)
public
  function GetName: string; override;
  function Generate: string; override;
  function GetSample: string; override;
end;

TFieldsComboBox = class(TComboBox)
private
  FFieldItems: TStrings;
  procedure SetFieldItems(const Value: TStrings);
  function GetFieldName: string;
public
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
  property FieldItems: TStrings read FFieldItems write SetFieldItems;
  property FieldName: string read GetFieldName;
end;

TCounterPartField = class(TCounterPart)
public
  function GetName: string; override;
  function GetControlType: TControlClass; override;
  function Generate: string; override;
  procedure InitControlData(aControl: TControl); override;
end;


const

  PartsClassArray : array [0..3] of TCounterPartClass = (
    TCounterPartText,
    TCounterPartDate,
    TCounterPartTrigger,
    TCounterPartField
  );

implementation

{.......}



var
  PC: TCounterPartClass;

initialization

for PC in PartsClassArray do
  RegisterClass(PC);

end.