1日目 列挙型をもとにした構造体サンプル


type
  TPairEnum = (
    peEURUSD,
    peGBPUSD,
    peUSDCHF,
    peUSDJPY,
    peEURGBP,
    peEURCHF,
    peEURJPY,
    peGBPCHF,
    peGBPJPY,
    peCHFJPY,
    peUSDCAD,
    peEURCAD,
    peAUDUSD,
    peAUDJPY,
    peNZDUSD,
    peNZDJPY);


type
  TPair = record
  private
    FEnum: TPairEnum;

    function getName(): String;

    procedure setEnum(const Value: TPairEnum);
    procedure setName(const Value: String);
    function getCount: Integer;
    function getSerial: Integer;
    procedure setSerial(const Value: Integer);


  public
    property Enum:      TPairEnum read FEnum        write setEnum;
    property Serial:    Integer   read getSerial    write setSerial;
    property Name:      String    read getName      write setName;
    property ShortName: String    read getShortName;

    property Count: Integer read getCount;
  end;

implementation

{ TPair }

function TPair.getCount: Integer;
var
  tmpInfo :PTypeInfo;
  tmpData :PTypeData;
begin
  tmpInfo :=TypeInfo(TPairEnum);
  tmpData :=GetTypeData(tmpInfo);
  Result := tmpData.MaxValue - tmpData.MinValue + 1;
end;

function TPair.getName: String;
begin
  case FEnum of
    peEURUSD: result := 'EURUSD';
    peGBPUSD: result := 'GBPUSD';
    peUSDCHF: result := 'USDCHF';
    peUSDJPY: result := 'USDJPY';
    peEURGBP: result := 'EURGBP';
    peEURCHF: result := 'EURCHF';
    peEURJPY: result := 'EURJPY';
    peGBPCHF: result := 'GBPCHF';
    peGBPJPY: result := 'GBPJPY';
    peCHFJPY: result := 'CHFJPY';
    peUSDCAD: result := 'USDCAD';
    peEURCAD: result := 'EURCAD';
    peAUDUSD: result := 'AUDUSD';
    peAUDJPY: result := 'AUDJPY';
    peNZDUSD: result := 'NZDUSD';
    peNZDJPY: result := 'NZDJPY';
  else
    ShowMessage('TPair.getName');
  end;
end;

function TPair.getSerial: Integer;
begin
  result := Integer(FEnum);
end;

procedure TPair.setEnum(const Value: TPairEnum);
begin
  FEnum := Value;
end;

procedure TPair.setName(const Value: String);
var
  tmpValue: String;
begin
  tmpValue := trim(Value);
       if tmpValue = 'EURUSD' then self.enum := peEURUSD
  else if tmpValue = 'GBPUSD' then self.enum := peGBPUSD
  else if tmpValue = 'USDCHF' then self.enum := peUSDCHF
  else if tmpValue = 'USDJPY' then self.enum := peUSDJPY
  else if tmpValue = 'EURGBP' then self.enum := peEURGBP
  else if tmpValue = 'EURCHF' then self.enum := peEURCHF
  else if tmpValue = 'EURJPY' then self.enum := peEURJPY
  else if tmpValue = 'GBPCHF' then self.enum := peGBPCHF
  else if tmpValue = 'GBPJPY' then self.enum := peGBPJPY
  else if tmpValue = 'CHFJPY' then self.enum := peCHFJPY
  else if tmpValue = 'USDCAD' then self.enum := peUSDCAD
  else if tmpValue = 'EURCAD' then self.enum := peEURCAD
  else if tmpValue = 'AUDUSD' then self.enum := peAUDUSD
  else if tmpValue = 'AUDJPY' then self.enum := peAUDJPY
  else if tmpValue = 'NZDUSD' then self.enum := peNZDUSD
  else if tmpValue = 'NZDJPY' then self.enum := peNZDJPY
  else
    ShowMessage('TPair.setName');
end;


procedure TPair.setSerial(const Value: Integer);
begin
  FEnum := TPairEnum(Value);
end;


コメントを残す

メールアドレスが公開されることはありません。


9 − = 七

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>