{ ----------------------------------- 2003/06/15 SetTextで文字列を分解するときの改行コード分割処理を Winの#13#10だけで対応していたものを #13、#10単独での場合も動作するように改造 //----------------------------------- } {$ifdef interface} {$undef interface} TCommonStringRecordList = class(TRecordList) private procedure SetText(const Value: TRecord); function GetText: TRecord; public property Text: TRecord read GetText write SetText; end; {$endif} {$ifdef RecordEqual} {$undef RecordEqual} function RecordEqual(const Value1, Value2: TRecord): Boolean; begin if ( TRecord(Value1) = TRecord(Value2) ) then begin Result := True; end else begin Result := False; end; end; {$endif} (*----------------------------------- こんな風にして動作テストしてみました。 uses WideStringRecordList; procedure TForm1.Button1Click(Sender: TObject); var StrRecList: TWideStringRecordList; i: Integer; begin StrRecList := TWideStringRecordList.Create; try for i := 0 to StringResource1.Lines.Count-1 do begin StrRecList.Add(StringResource1.Lines.Strings[i]); end; for i := StrRecList.Count-1 downto 0 do begin if StrRecList.Items[i] = EmptyStr then StrRecList.Delete(i); end; for i := 0 to StrRecList.Count-1 do begin Memo1.Lines.Add(StrRecList.Items[i]); end; finally StrRecList.Free; end; end; procedure TForm1.Button2Click(Sender: TObject); var StrRecList: TWideStringRecordList; i: Integer; begin StrRecList := TWideStringRecordList.Create; try StrRecList.Text := StringResource1.Lines.Text; for i := StrRecList.Count-1 downto 0 do begin if StrRecList.Items[i] = #13#10 then StrRecList.Delete(i); end; for i := 0 to StrRecList.Count-1 do begin Memo1.Text := StrRecList.Text end; finally StrRecList.Free; end; end; procedure TForm1.Button3Click(Sender: TObject); begin testGetSetText; end; //-----------------------------------*) {$ifdef GetSetText} {$undef GetSetText} function TCommonStringRecordList.GetText: TRecord; var i: Integer; begin Result := ''; for i := 0 to Self.Count-1 do begin Result := Result + Self.Items[i]; end; end; procedure TCommonStringRecordList.SetText(const Value: TRecord); const LineBreakStrs: array[0..2] of TRecord = (#13#10, #13, #10); var i, j, Len, StrStartIndex, StrEndIndex: Integer; LineBreakStr: TRecord; begin Self.Clear; if Value = EmptyStr then begin Exit; end; Len := Length(Value); StrStartIndex := 1; StrEndIndex := 0; i := 1; while (i <= Len) do begin LineBreakStr := ''; for j := Low(LineBreakStrs) to High(LineBreakStrs) do begin if StringPartsCompare(LineBreakStrs[j], Value, i) then begin LineBreakStr := LineBreakStrs[j]; break; end; end; if LineBreakStr <> '' Then begin StrEndIndex := i + length(LineBreakStr)-1; Self.Add(Copy(Value, StrStartIndex, StrEndIndex-StrStartIndex+1)); i := StrEndIndex + 1; StrStartIndex := i; end else begin StrEndIndex := i; Inc(i); end; end; if 1 <= StrEndIndex-StrStartIndex+1 then begin Self.Add(Copy(Value, StrStartIndex, StrEndIndex-StrStartIndex+1)); end; end; (*----------------------------------- procedure TCommonStringRecordList.SetText(const Value: TRecord); const LineBreakStr: TRecord = #13#10; var i, Len, StrStartIndex, StrEndIndex: Integer; begin Self.Clear; if Value = EmptyStr then begin Exit; end; Len := Length(Value); StrStartIndex := 1; StrEndIndex := 0; i := 1; while (i <= Len) do begin if StringPartsCompare(LineBreakStr, Value, i) then begin StrEndIndex := i + length(LineBreakStr)-1; Self.Add(Copy(Value, StrStartIndex, StrEndIndex-StrStartIndex+1)); i := StrEndIndex + 1; StrStartIndex := i; end else begin StrEndIndex := i; Inc(i); end; end; if 1 <= StrEndIndex-StrStartIndex+1 then begin Self.Add(Copy(Value, StrStartIndex, StrEndIndex-StrStartIndex+1)); end; end; //-----------------------------------*) type TTestMyStringList = TCommonStringRecordList; function GetIndexString(StrList: TCommonStringRecordList; i: Integer): TRecord; begin Result := StrList.Items[i]; end; {$include TestMyStringList.pas} {$endif}