{ ----------------------------------- 履歴 2007/07/20 ・関数ベースからレコードベースの コードに変更した。 //----------------------------------- } unit StringListUnit; interface uses Classes; type TCheckLineFunction = function(Line: String): Boolean; TConvertStringFunction = function(Line: String): String; TStringListFunction = record private FStrings: TStrings; public constructor Create(Strings: TStrings); procedure InsertAdd(Index: Integer; AddText: String); procedure InsertNext(Index: Integer; AddText: String); procedure DeleteLine(f: TCheckLineFunction); procedure ConvertLine(f: TConvertStringFunction); end; implementation { TStringListUnit } constructor TStringListFunction.Create(Strings: TStrings); begin FStrings := Strings; end; {------------------------------- // 挿入か追加を行う関数 機能: Stringsに対してIndexが普通の場合はInsert、 Indexが最終行+1の場合は最終行に追加する 備考: 履歴: 2006/11/13(月) 23:11 //------------------------------} procedure TStringListFunction.InsertAdd(Index: Integer; AddText: String); begin if Index = FStrings.Count then begin FStrings.Add(AddText); end else begin FStrings.Insert(Index, AddText); end; end; //------------------------------ {------------------------------- // 指定した次の行に挿入を行う関数 機能: 通常のInsertでは指定行の前にInsertだが InsertNextでは次の行にInsertする 備考: 履歴: 2006/11/13(月) 23:11 //------------------------------} procedure TStringListFunction.InsertNext(Index: Integer; AddText: String); begin if Index = FStrings.Count-1 then begin FStrings.Add(AddText); end else begin FStrings.Insert(Index+1, AddText); end; end; //------------------------------ {------------------------------- // 条件に一致する行を削除する 機能: 備考: 履歴: 2007/07/20(金) 00:45 //------------------------------} procedure TStringListFunction.DeleteLine(f: TCheckLineFunction); var i: Integer; begin for i := FStrings.Count - 1 downto 0 do begin if f(FStrings[i]) then begin FStrings.Delete(i); end; end; end; //------------------------------ {------------------------------- // 行を変換する 機能: 備考: 履歴: 2007/07/20(金) 00:45 //------------------------------} procedure TStringListFunction.ConvertLine(f: TConvertStringFunction); var i: Integer; begin for i := 0 to FStrings.Count - 1 do begin FStrings[i] := f(FStrings[i]); end; end; //------------------------------ end.