On 04/01/12 05:13, Marco van de Voort wrote:
> In our previous episode, Michael Van Canneyt said:
>>> I was thinking about TStrings possibly having an overloaded function Add
>>> or AddStrings where the argument is an array of string?
>>>
>>> procedure Add(strs: array of string); overload;
>>> or
>>> procedure AddStrings(strs: array of string); overload;
>>>
>>
>> Better implement the second.
>> AddStrings already exists for a TStrings, it is more similar in
>> functionality.
>
> Maybe better extending tprocess to have a array of const function than
> tstrings?
> _______________________________________________
> fpc-devel maillist - [email protected]
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
Here are two patches that do both. One extends TStrings with AddStrings
and the other extends TProcess with AddParams.
I'll let someone else decide which is better. :)
Regards,
Andrew
Index: packages/fcl-process/src/process.pp
===================================================================
--- packages/fcl-process/src/process.pp (revision 20684)
+++ packages/fcl-process/src/process.pp (working copy)
@@ -115,6 +115,7 @@
procedure CloseInput; virtual;
procedure CloseOutput; virtual;
procedure CloseStderr; virtual;
+ procedure AddParams(const AParams: array of string);
Function Resume : Integer; virtual;
Function Suspend : Integer; virtual;
Function Terminate (AExitCode : Integer): Boolean; virtual;
@@ -254,6 +255,14 @@
Inherited Destroy;
end;
+Procedure TProcess.AddParams(const AParams: array of string);
+var
+ s: string;
+begin
+ for s in AParams do
+ Parameters.Add(s);
+end;
+
Procedure TProcess.FreeStreams;
begin
If FStderrStream<>FOutputStream then
Index: rtl/objpas/classes/stringl.inc
===================================================================
--- rtl/objpas/classes/stringl.inc (revision 20684)
+++ rtl/objpas/classes/stringl.inc (working copy)
@@ -603,8 +603,22 @@
end;
end;
+Procedure TStrings.AddStrings(const TheStrings: array of string);
+Var Runner : longint;
+begin
+ try
+ beginupdate;
+ if Count + High(TheStrings)+1 > Capacity then
+ Capacity := Count + High(TheStrings)+1;
+ For Runner:=Low(TheStrings) to High(TheStrings) do
+ self.Add(Thestrings[Runner]);
+ finally
+ EndUpdate;
+ end;
+end;
+
Procedure TStrings.Assign(Source: TPersistent);
Var
Index: rtl/objpas/classes/classesh.inc
===================================================================
--- rtl/objpas/classes/classesh.inc (revision 20684)
+++ rtl/objpas/classes/classesh.inc (working copy)
@@ -607,6 +607,7 @@
function AddObject(const S: string; AObject: TObject): Integer; virtual;
procedure Append(const S: string);
procedure AddStrings(TheStrings: TStrings); virtual;
+ procedure AddStrings(const TheStrings: array of string); overload; virtual;
procedure Assign(Source: TPersistent); override;
procedure BeginUpdate;
procedure Clear; virtual; abstract;
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel