Re: [Lazarus] Saving an array to a string

2014-07-01 Thread Michael Thompson
> > That's brilliant.  This answers a question I posted on the forum last
week.  Mind if I quote your link in there?
> > Mike
> Feel free to send it! :-)

Done
http://forum.lazarus.freepascal.org/index.php/topic,25017.msg151539.html#msg151539

Many thanks :-)

Mike
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread silvioprog
2014-07-01 12:21 GMT-03:00 Michael Thompson :

> > You can use RUtils plugin:
> > https://github.com/silvioprog/rutils
>
> That's brilliant.  This answers a question I posted on the forum last
> week.  Mind if I quote your link in there?
>
> Mike
>


Feel free to send it! :-)

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread silvioprog
2014-07-01 12:24 GMT-03:00 Jürgen Hestermann :

>
> 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
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread Jürgen Hestermann


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).



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread Michael Thompson
> You can use RUtils plugin:
> https://github.com/silvioprog/rutils

That's brilliant.  This answers a question I posted on the forum last week.
 Mind if I quote your link in there?

Mike
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread silvioprog
2014-07-01 12:04 GMT-03:00 Richard Mace :

> Thanks Michael. And reading it back?
>

You can use RUtils plugin again:

uses
  RUtils;

procedure TForm1.Button1Click(Sender: TObject);
var
  ar: array of string;
begin
  ar := RUtils.Explode('abc def ghi');
end;

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread silvioprog
2014-07-01 11:49 GMT-03:00 Richard Mace :

> Hi All,
> Is it possible to save an array of string to a single string for storing
> in a string field within a database?
> If so, could anyone give me any pointers please?
>
> Thanks
>

You can use RUtils plugin:

https://github.com/silvioprog/rutils

So:

uses
  RUtils;

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';

  // array of string to string
  ShowMessage(RUtils.Implode(ar));
end;

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread Philippe
 

you can use


http://www.freepascal.org/docs-html/rtl/classes/tstringlist.html 

var
lStrings : TStringList; 

begin 

 

 lStrings :=
TStringList.Create;
 with lStrings do
 begin
 delimiter :=
yourdelimiter; // don´t know if you can use "lineending"

strictdelimiter := true;
 DelimitedText := textfromyourfield;

 for n :=
0 to count - 1 do 

 myarray[ n] := strings[ n ]; 

 end; 


lStrings.free; 

Philippe 

Em 01.07.2014 12:04, Richard Mace escreveu:


> Thanks Michael. And reading it back? 
> On 1 Jul 2014 15:57,
"Michael Thompson"  wrote:
> 
>>> Is it
possible to save an array of string to a single string for storing in a
string field within a database?
>> 
>> Suspect it'll be something like

>> MyString := ''; 
>> For i := Low(MyArray) to High(MyArray) Do 
>>
MyString := MyString + MyArray[i] + LineEnding; 
>> 
>>
MyStringField.AsString := MyString; 
>> 
>> On 1 July 2014 16:49,
Richard Mace  wrote:
>> 
>>> Hi All,
>>> Is it
possible to save an array of string to a single string for storing in a
string field within a database? 
>>> If so, could anyone give me any
pointers please?
>>> 
>>> Thanks
>>> 
>>> Richard
>>> 
>>> --
>>>
___
>>> Lazarus mailing
list
>>> Lazarus@lists.lazarus.freepascal.org
>>>
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus [1]
>> 
>>
--
>> ___
>> Lazarus mailing
list
>> Lazarus@lists.lazarus.freepascal.org
>>
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus [1]
> 
>
--
> ___
> Lazarus mailing
list
> Lazarus@lists.lazarus.freepascal.org
>
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus [1]




Links:
--
[1]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread Michael Thompson
I'm lazy, I'd do it via a TStringList :-)

MyStringList := TStringList.Create;
MyStringList.Text := MyStringField.AsString;

SetLength(MyArray, MyStringlist.Count);
For i := 0 To MyStringList.Count-1 Do
  MyArray[i] := MyStringList[i];

MyStringList.Free;

In fact, I'd use a TStringList at both ends of the code, and not use an
Array Of String at all...  I like it when other code does my work for me :-)

Mike
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread Richard Mace
Thanks Michael. And reading it back?
On 1 Jul 2014 15:57, "Michael Thompson"  wrote:

> > Is it possible to save an array of string to a single string for storing
> in a string field within a database?
>
> Suspect it'll be something like
> MyString := '';
> For i := Low(MyArray) to High(MyArray) Do
>   MyString := MyString + MyArray[i] + LineEnding;
>
> MyStringField.AsString := MyString;
>
>
> On 1 July 2014 16:49, Richard Mace  wrote:
>
>> Hi All,
>> Is it possible to save an array of string to a single string for storing
>> in a string field within a database?
>> If so, could anyone give me any pointers please?
>>
>> Thanks
>>
>> Richard
>>
>> --
>> ___
>> Lazarus mailing list
>> Lazarus@lists.lazarus.freepascal.org
>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>>
>>
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread JB
I use this code in my project:

  for i := 0 to length(Args) - 1 do
  begin
sArgs := sArgs + VarToStr(Args[i]);

if i < (length(Args) - 1) then
  sArgs := sArgs + ';';
  end;


Att.


JB



José Benedito
JBS Soluções
Consulting Systems Development
c ont...@jbsolucoes.net
www.jbsolucoes.net

skype: s...@jbsolucoes.net


On Tue, Jul 1, 2014 at 11:55 AM, Michael Thompson 
wrote:

> > Is it possible to save an array of string to a single string for storing
> in a string field within a database?
>
> Suspect it'll be something like
> MyString := '';
> For i := Low(MyArray) to High(MyArray) Do
>   MyString := MyString + MyArray[i] + LineEnding;
>
> MyStringField.AsString := MyString;
>
>
> On 1 July 2014 16:49, Richard Mace  wrote:
>
>> Hi All,
>> Is it possible to save an array of string to a single string for storing
>> in a string field within a database?
>> If so, could anyone give me any pointers please?
>>
>> Thanks
>>
>> Richard
>>
>> --
>> ___
>> Lazarus mailing list
>> Lazarus@lists.lazarus.freepascal.org
>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>>
>>
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Saving an array to a string

2014-07-01 Thread Michael Thompson
> Is it possible to save an array of string to a single string for storing
in a string field within a database?

Suspect it'll be something like
MyString := '';
For i := Low(MyArray) to High(MyArray) Do
  MyString := MyString + MyArray[i] + LineEnding;

MyStringField.AsString := MyString;


On 1 July 2014 16:49, Richard Mace  wrote:

> Hi All,
> Is it possible to save an array of string to a single string for storing
> in a string field within a database?
> If so, could anyone give me any pointers please?
>
> Thanks
>
> Richard
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Saving an array to a string

2014-07-01 Thread Richard Mace
Hi All,
Is it possible to save an array of string to a single string for storing in
a string field within a database?
If so, could anyone give me any pointers please?

Thanks

Richard
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus