[Lazarus] Saving an array to a string

silvioprog silvioprog at gmail.com
Tue Jul 1 18:57:52 CEST 2014


2014-07-01 12:24 GMT-03:00 Jürgen Hestermann <juergen.hestermann at gmx.de>:

>
> Am 2014-07-01 17:14, schrieb silvioprog:
>
>  procedure TForm1.Button1Click(Sender: TObject);
>> var
>>   ar: array of string;
>> begin
>>   // your array
>>   SetLength(ar, 2);
>>   ar[0] := 'abc';
>>   ar[1] := 'def';
>>   ar[2] := 'ghi';
>>
>
> ar[2] will lead to an error if you set the length
> of the array to 2 (only indices 0 and 1 are allowed).
>

Oops, fast typing in reply. ^^'

...
SetLength(ar, 3);
...

So:

program project1;

{$mode objfpc}{$H+}

var
  s: string;
  ar: array of string;
begin
  // your array
  SetLength(ar, 3);
  ar[0] := 'abc';
  ar[1] := 'def';
  ar[2] := 'ghi';
  for s in ar do
    WriteLn(s);
end.

output:

abc
def
ghi

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140701/47ae63a1/attachment-0003.html>


More information about the Lazarus mailing list