[fpc-pascal] add a string to existed open array

ik idokan at gmail.com
Tue Jan 31 10:32:32 CET 2012


On Tue, Jan 31, 2012 at 11:19, Sven Barth <pascaldragon at googlemail.com>wrote:

> Am 31.01.2012 09:55, schrieb ik:
>
>  Hello,
>>
>> I wish to create something like this:
>>
>> function foo(a : String; b : array of const) : string;
>> begin
>>   Result := bar([a] + b);
>> end;
>>
>> But this works only on Sets.
>> The thing is, that A must be before the rest of "b". and it is different
>> then the b values, that's why I extract it to a different parameter.
>>
>> How can I add a to the list, and make it the first element ?
>>
>
> There is no easy way, only the following:
>
> function foo(a: String; b: array of const): String;
> var
>  tmp: array of TVarRec;
>  i: LongInt;
> begin
>  SetLength(tmp, Length(b) + 1);
>  tmp[0].VType := vtAnsiString; // Note: Only if "foo" is in a unit with
> {$H+} set (or mode Delphi)
>  tmp[0].VAnsiString := Pointer(a);
>  for i := 0 to High(b) do
>    tmp[i + 1] := b[i];
>  Result := bar(tmp);
> end;
>
> Regards,
> Sven
>

Thanks, that's what I was afraid of. :)

Ido


> ______________________________**_________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.**org<fpc-pascal at lists.freepascal.org>
> http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20120131/c46c1f62/attachment.html>


More information about the fpc-pascal mailing list