{---------------------------------------- 2010/06/10(木) ・ WordDecompose>>DelimitedTextUnit 2011/06/10(金) ・DelimitedTextUnit>>StringSplitterUnit //----------------------------------------} unit RectStringUnit; interface uses Types, SysUtils, StringSplitterUnit, RectPointUnit, uses_end; function RectToString(R: TRect): String; function StringToRect(S: String): TRect; function RectSizeToString(RS: TRectSize): String; function StringToRectSize(S: String): TRectSize; implementation {------------------------------- // Rect⇔String変換 機能: スペース区切り形式でRectと文字列を相互変換する 備考: 履歴: 2006/12/23(土) 00:26 //--▼----------------------▽--} {Rect→文字列変換関数} function RectToString(R: TRect): String; begin Result := IntToStr(R.Left) + ' ' + IntToStr(R.Top) + ' ' + IntToStr(R.Right) + ' ' + IntToStr(R.Bottom); end; {エラー処理なしの文字列→Rect変換関数 スペース区切りの文字列をRectにする} function StringToRect(S: String): TRect; var WD: TStringSplitter; begin Result := Rect(0, 0, 0, 0); WD := TStringSplitter.Create(S, [' '], dmDelimiterExactly); try if WD.Count = 4 then begin Result.Left := StrToIntDef( WD.Words[0], 0); Result.Top := StrToIntDef( WD.Words[1], 0); Result.Right := StrToIntDef( WD.Words[2], 0); Result.Bottom := StrToIntDef( WD.Words[3], 0); end; finally WD.Free; end; end; //--△----------------------▲-- {------------------------------- // RectSize⇔String変換 機能: 100x200形式でRectSizeと文字列を相互変換する 備考: 履歴: 2006/12/23(土) 00:26 //--▼----------------------▽--} function RectSizeToString(RS: TRectSize): String; begin Result := IntToStr(RS.Width) +'x'+ IntToStr(RS.Height); end; function StringToRectSize(S: String): TRectSize; begin Result := RectSize(0, 0); if WordCount(S, ['x'], dmDelimiterExactly)=2 then begin Result.Width := StrToIntDef(WordGet(S, ['x'], 0, dmDelimiterExactly), 0); Result.Height := StrToIntDef(WordGet(S, ['x'], 1, dmDelimiterExactly), 0); end; end; ////123x456からRectSizeを取り出す関数 //function TMainForm.GetRectSize(Value: String): TRectSize; //begin // Result := RectSize(0, 0); // if WordCount('x', Value, dmDelimiterExactly)=2 then // begin // Result.Width := StrToIntDef( // WordGet('x', Value, 0, dmDelimiterExactly), 0); // Result.Height := StrToIntDef( // WordGet('x', Value, 1, dmDelimiterExactly), 0); // end; //end; //--△----------------------▲-- end.