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