Parcourir la source

* Fix bug ID #36837: add ToObjectArray, ToStTringArray and SetStrings

git-svn-id: trunk@44632 -
michael il y a 5 ans
Parent
commit
0ff254e00f
3 fichiers modifiés avec 57 ajouts et 0 suppressions
  1. 6 0
      rtl/objpas/classes/classesh.inc
  2. 50 0
      rtl/objpas/classes/stringl.inc
  3. 1 0
      rtl/objpas/types.pp

+ 6 - 0
rtl/objpas/classes/classesh.inc

@@ -694,6 +694,10 @@ type
   public
     constructor Create;
     destructor Destroy; override;
+    function ToObjectArray(aStart,aEnd : Integer) : TObjectDynArray; overload;
+    function ToObjectArray: TObjectDynArray; overload;
+    function ToStringArray(aStart,aEnd : Integer) : TStringDynArray; overload;
+    function ToStringArray: TStringDynArray; overload;
     function Add(const S: string): Integer; virtual; overload;
     function AddObject(const S: string; AObject: TObject): Integer; virtual; overload;
     function Add(const Fmt : string; const Args : Array of const): Integer; overload;
@@ -704,6 +708,8 @@ type
     procedure AddStrings(TheStrings: TStrings; ClearFirst : Boolean); overload;
     procedure AddStrings(const TheStrings: array of string); overload; virtual;
     procedure AddStrings(const TheStrings: array of string; ClearFirst : Boolean); overload;
+    procedure SetStrings(TheStrings: TStrings); overload; virtual;
+    procedure SetStrings(TheStrings: array of string); overload; virtual;
     Procedure AddText(Const S : String); virtual;
     procedure AddCommaText(const S: String);
     procedure AddDelimitedText(const S: String; ADelimiter: char; AStrictDelimiter: Boolean); overload;

+ 50 - 0
rtl/objpas/classes/stringl.inc

@@ -689,6 +689,7 @@ begin
     Exclude(FOptions,soUseLocale);
 end;
 
+
 procedure TStrings.SetWriteBOM(AValue: Boolean);
 begin
   if AValue then
@@ -1018,6 +1019,43 @@ begin
   inherited destroy;
 end;
 
+function TStrings.ToObjectArray: TObjectDynArray;
+
+begin
+  Result:=ToObjectArray(0,Count-1);
+end;
+
+function TStrings.ToObjectArray(aStart,aEnd : Integer): TObjectDynArray;
+Var
+  I : Integer;
+
+begin
+  Result:=Nil;
+  if aStart>aEnd then exit;
+  SetLength(Result,aEnd-aStart+1);
+  For I:=0 to Count-1 do
+    Result[i]:=Objects[i];
+end;
+
+function TStrings.ToStringArray: TStringDynArray;
+
+begin
+  Result:=ToStringArray(0,Count-1);
+end;
+
+function TStrings.ToStringArray(aStart,aEnd : Integer): TStringDynArray;
+
+Var
+  I : Integer;
+
+begin
+  Result:=Nil;
+  if aStart>aEnd then exit;
+  SetLength(Result,aEnd-aStart+1);
+  For I:=0 to Count-1 do
+    Result[i]:=Strings[i];
+end;
+
 
 constructor TStrings.Create;
 begin
@@ -1120,6 +1158,18 @@ begin
   end;
 end;
 
+procedure TStrings.SetStrings(TheStrings: TStrings);
+
+begin
+  AddStrings(TheStrings,True);
+end;
+
+procedure TStrings.SetStrings(TheStrings: array of string);
+
+begin
+  AddStrings(TheStrings,True);
+end;
+
 Procedure TStrings.Assign(Source: TPersistent);
 
 Var

+ 1 - 0
rtl/objpas/types.pp

@@ -64,6 +64,7 @@ type
   TShortIntDynArray = array of ShortInt;
   TSmallIntDynArray = array of SmallInt;
   TStringDynArray = array of AnsiString;
+  TObjectDynArray = array of TObject;
   TWideStringDynArray   = array of WideString;
   TWordDynArray = array of Word;
   TCurrencyArray = Array of currency;