Board index » delphi » How To Store Points in a Dynamic Array of Record Type

How To Store Points in a Dynamic Array of Record Type

Does someone know how can i store Start Points and End Points at run time in a array to draw lines with it, for exemple:

type
  TLine = Record
  StartPoint, EndPoint: TPoint;
  end;

  ....

  ArrayOfPoints = Arrat of TLine;

  ....

and draw
for j:= Low(ArrayOfPoints) to High(ArrayOfPoints) do
begin
  Canvas.MoveTo(ArrayOfPoints[j].StartPoint.x,
              ArrayOfPoint[j].StartPoint.y);
  Canvas.LineeTo(ArrayOfPoints[j].EndPoint.x,
               ArrayOfPoints[j].EndPoint.y);
end;

 

Re:How To Store Points in a Dynamic Array of Record Type


I think you should set the size of the array first

SetLength(ArrayOfPoints, 10); // 10 points

for i:=0 to 9 do
  begin
    ArrayOfPoints[i].StartPoint.x := i;
    ArrayOfPoints[i].StartPoint.y := Round(10*Sin(i*Pi/5));
    ArrayOfPoints[i].EndPoint.x := Succ(i);
    ArrayOfPoints[i].EndPoint.y := Round(10*Sin(Succ(i)*Pi/5));
  end;

[]s
Arthur

agnaldo <agna...@tqs.com.br> escreveu nas notcias de
mensagem:3e70e5e...@newsgroups.borland.com...

Quote

> Does someone know how can i store Start Points and End Points at run time

in a array to draw lines with it, for exemple:
Quote

> type
>   TLine = Record
>   StartPoint, EndPoint: TPoint;
>   end;

>   ....

>   ArrayOfPoints = Arrat of TLine;

>   ....

> and draw
> for j:= Low(ArrayOfPoints) to High(ArrayOfPoints) do
> begin
>   Canvas.MoveTo(ArrayOfPoints[j].StartPoint.x,
>               ArrayOfPoint[j].StartPoint.y);
>   Canvas.LineeTo(ArrayOfPoints[j].EndPoint.x,
>                ArrayOfPoints[j].EndPoint.y);
> end;

Re:How To Store Points in a Dynamic Array of Record Type


You mean like the PolyLine and Polygon functions.
look in the API help.
PolyPolyLine.
PolyPolyGon.
PolyDraw et.c.
they all use Point arrays
Quote
agnaldo wrote:
> Does someone know how can i store Start Points and End Points at run time in a array to draw lines with it, for exemple:

> type
>   TLine = Record
>   StartPoint, EndPoint: TPoint;
>   end;

>   ....

>   ArrayOfPoints = Arrat of TLine;

>   ....

> and draw
> for j:= Low(ArrayOfPoints) to High(ArrayOfPoints) do
> begin
>   Canvas.MoveTo(ArrayOfPoints[j].StartPoint.x,
>               ArrayOfPoint[j].StartPoint.y);
>   Canvas.LineeTo(ArrayOfPoints[j].EndPoint.x,
>                ArrayOfPoints[j].EndPoint.y);
> end;

Re:How To Store Points in a Dynamic Array of Record Type


Thanks for replay but, I think you don't know my question !
I know that I need set a Length of vector but, How Can I set it
at runtime and Stored at the disk.

ps. I trying to doing a vector Drawing program !

Quote
"Arthur E.F.Heinrich" <art...@xperiment.com> wrote:
>I think you should set the size of the array first

>SetLength(ArrayOfPoints, 10); // 10 points

>for i:=0 to 9 do
>  begin
>    ArrayOfPoints[i].StartPoint.x := i;
>    ArrayOfPoints[i].StartPoint.y := Round(10*Sin(i*Pi/5));
>    ArrayOfPoints[i].EndPoint.x := Succ(i);
>    ArrayOfPoints[i].EndPoint.y := Round(10*Sin(Succ(i)*Pi/5));
>  end;

>[]s
>Arthur

>agnaldo <agna...@tqs.com.br> escreveu nas notcias de
>mensagem:3e70e5e...@newsgroups.borland.com...

>> Does someone know how can i store Start Points and End Points at run time
>in a array to draw lines with it, for exemple:

>> type
>>   TLine = Record
>>   StartPoint, EndPoint: TPoint;
>>   end;

>>   ....

>>   ArrayOfPoints = Arrat of TLine;

>>   ....

>> and draw
>> for j:= Low(ArrayOfPoints) to High(ArrayOfPoints) do
>> begin
>>   Canvas.MoveTo(ArrayOfPoints[j].StartPoint.x,
>>               ArrayOfPoint[j].StartPoint.y);
>>   Canvas.LineeTo(ArrayOfPoints[j].EndPoint.x,
>>                ArrayOfPoints[j].EndPoint.y);
>> end;

Other Threads