unit testIntListProp1; interface uses Windows, Messages, SysUtils, Classes, IntValuesStr; type TtestIntListProp1 = class(TComponent) private FIntValuesStrList: TStringList; function GetIntValues(Index: Integer): Integer; function GetIntValuesCount: Integer; function GetIntValuesStr: TIntValuesStr; procedure SetIntValuesStr(const Value: TIntValuesStr); protected public constructor Create(AOwner: TComponent); override; destructor Destroy; override; property IntValues[Index: Integer]: Integer read GetIntValues; property IntValuesCount: Integer read GetIntValuesCount; published property IntValuesStr: TIntValuesStr read GetIntValuesStr write SetIntValuesStr; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TtestIntListProp1]); end; {↓区切り文字を指定} const Delimiter: Char = ';'; { TtestIntListProp1 } {------------------------------- //起動・終了 //------------------------------} constructor TtestIntListProp1.Create(AOwner: TComponent); begin inherited; FIntValuesStrList := TStringList.Create; FIntValuesStrList.Delimiter := Delimiter; end; destructor TtestIntListProp1.Destroy; begin FIntValuesStrList.Free; inherited; end; //------------------------------ {------------------------------- //数値列文字列プロパティのGet/Set //------------------------------} function TtestIntListProp1.GetIntValuesStr: TIntValuesStr; begin Result := FIntValuesStrList.DelimitedText; end; procedure TtestIntListProp1.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; 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 TtestIntListProp1.GetIntValues(Index: Integer): Integer; begin if (0<=Index) and (Index<=FIntValuesStrList.Count-1) then begin Result := StrToInt(FIntValuesStrList.Strings[Index]); end else begin raise Exception.Create('範囲外のIndex値です'); end; end; function TtestIntListProp1.GetIntValuesCount: Integer; begin Result := FIntValuesStrList.Count; end; //------------------------------ end.