unit testIntListProp3; interface uses Windows, Messages, SysUtils, Classes, IntValuesStr; type TPlusInteger = 0..MaxInt; TtestIntListProp3 = class(TComponent) private FIntValuesStrList: TStringList; FFixIntValuesCount: TPlusInteger; function GetIntValuesStr: TIntValuesStr; procedure SetIntValuesStr(const Value: TIntValuesStr); function GetIntValues(Index: Integer): Integer; procedure SetIntValues(Index: Integer; const Value: Integer); protected public constructor Create(AOwner: TComponent); override; destructor Destroy; override; property IntValues[Index: Integer]: Integer read GetIntValues write SetIntValues; published property FixIntValuesCount: TPlusInteger read FFixIntValuesCount write FFixIntValuesCount; property IntValuesStr: TIntValuesStr read GetIntValuesStr write SetIntValuesStr; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TtestIntListProp3]); end; {↓区切り文字を指定} const Delimiter: Char = ';'; { TtestIntListProp3 } {------------------------------- //起動・終了 //------------------------------} constructor TtestIntListProp3.Create(AOwner: TComponent); begin inherited; FIntValuesStrList := TStringList.Create; FIntValuesStrList.Delimiter := Delimiter; end; destructor TtestIntListProp3.Destroy; begin FIntValuesStrList.Free; inherited; end; //------------------------------ procedure SetStringsCount(Strings: TStrings; Count: TPlusInteger); var i, Loop: Integer; begin if Strings.Count < Count then begin Loop := Count - Strings.Count; for i := 1 to Loop do begin Strings.Add('0'); end; end else if Count < Strings.Count then begin Loop := Strings.Count - Count; for i := 1 to Loop do begin Strings.Delete(Strings.Count-1); end; end; end; {------------------------------- //数値列文字列プロパティのGet/Set //------------------------------} function TtestIntListProp3.GetIntValuesStr: TIntValuesStr; begin {↓StrListと指定数値個数が合わない場合、0を挿入してあわせる} SetStringsCount(FIntValuesStrList, FFixIntValuesCount); Result := FIntValuesStrList.DelimitedText; end; procedure TtestIntListProp3.SetIntValuesStr(const Value: TIntValuesStr); var StrBuff: String; i: Integer; Val: Integer; begin if Value <> FIntValuesStrList.DelimitedText then begin if Value = '' then Exit; StrBuff := FIntValuesStrList.DelimitedText; FIntValuesStrList.DelimitedText := Value; {↓数値列の数が指定と合わなければ受け付けない} if FFixIntValuesCount <> FIntValuesStrList.Count then begin FIntValuesStrList.DelimitedText := StrBuff; Exit; end; for i := 0 to FIntValuesStrList.Count-1 do begin {↓もし数値に変換できない文字列が混ざっている場合 元の値に戻して入力を受け付けない} if TryStrToInt(FIntValuesStrList.Strings[i], Val)=False then begin FIntValuesStrList.DelimitedText := StrBuff; Exit; end; end; end; end; //------------------------------ {------------------------------- //数値列文字列を数値列にして読み書きするプロパティ //------------------------------} function TtestIntListProp3.GetIntValues(Index: Integer): Integer; begin if (0<=Index) and (Index<=FFixIntValuesCount-1) then begin SetStringsCount(FIntValuesStrList, FFixIntValuesCount); Result := StrToInt(FIntValuesStrList.Strings[Index]); end else begin raise Exception.Create('範囲外のIndex値です'); end; end; procedure TtestIntListProp3.SetIntValues(Index: Integer; const Value: Integer); begin if (0<=Index) and (Index<=FFixIntValuesCount-1) then begin SetStringsCount(FIntValuesStrList, FFixIntValuesCount); FIntValuesStrList.Strings[Index] := IntToStr(Value); end else begin raise Exception.Create('範囲外のIndex値です'); end; end; //------------------------------ end.