SRL Archive - OSR Help

tpointarray to str?


JPHamlett

2010-08-13 21:18:20

I there a way to do this using simba I ve been trying to make my own for a little while and I have been failing

Frement

2010-08-13 21:28:53

What you mean with it? You want all the values in a single string or?

JPHamlett

2010-08-13 21:38:53

i need


tpointarr := [point(1, 1), point(2, 2)]

to return


string := 'point(1, 1), point(2, 2)';

bullzeye95

2010-08-13 21:39:02

I think toStr() is what you're looking for.

EDIT: It won't return in exactly that format, but I'll code something that does.

function TPAToStr(P: TPointArray): String;
var
I: Integer;
begin
for I := 0 to high(P) do
Result := Result + 'point' + toStr(p[I]) + ', ';
Result := copy(Result, 1, length(Result) - 2);
end;
Is that what you want?

Frement

2010-08-13 21:43:26

program new;
{$I SRL/SRL.scar}

var TSA: TStringArray;
I: Integer;

function TPAtoTSA(TPA: TPointArray): TStringArray;
var I: Integer;
begin
SetArrayLength(Result, Length(TPA));
for I := 0 to High(TPA) do begin
Result[I] := IntToStr(TPA[I].X)+','+IntToStr(TPA[I].Y);
end;
end;

begin
SetupSRL;
TSA := TPAtoTSA([Point(0, 0), Point(1, 1), Point(2, 2), Point(3, 3)]);
for I := 0 to High(TSA) do begin
Writeln(TSA[I]);
end;
end.

Daniel

2010-08-14 01:20:16

[php]
// Converts an array of TPoint's to a String
function TPAToStr(TPA: TPointArray): String;
var
I, arrLnth: Integer;
begin
arrLnth := High(TPA);

for I := 0 to arrLnth do
Result := Result + 'Point(' + IntToStr(TPA.X) + ', ' + IntToStr(TPA.Y) + '), ';

SetLength(Result, Length(Result) - 2);
end;
[/php]

Although I don't really see the use of this, but there ya' go.

It will return something along the lines of:
[php]
Point(213, 522), Point(96, 174), Point(615, 263), Point(77, 400), Point(724, 583), Point(197, 259), Point(113, 240), Point(517, 438), Point(58, 477), Point(242, 201), Point(153, 462)
[/php]

;)