Board index » cppbuilder » It doesn't Paint for new TPoint?

It doesn't Paint for new TPoint?

I have this works fine:

void __fastcall DrawWave(TPaintBox *PaintBox, double
*data_array, int data_length)
{
     PaintBox->Canvas->Brush->Color = clBlack;
     PaintBox->Canvas->FillRect(PaintBox->Canvas->ClipRect);

     PaintBox->Canvas->Pen->Color = clGreen;
     TPoint points[512]; // <<===== Note here!
     for(int i=0; i<data_length; i++) points[i] = Point(i,
(int)data_array[i]);
     PaintBox->Canvas->Polyline(EXISTINGARRAY(points));

Quote
}

But, I have to force data_length = 512 (whatever the points
size
is declared).

Because data_length is variable, I tried this:

void __fastcall DrawWave(TPaintBox *PaintBox, double
*data_array, int data_length)
{
     PaintBox->Canvas->Brush->Color = clBlack;
     PaintBox->Canvas->FillRect(PaintBox->Canvas->ClipRect);

     PaintBox->Canvas->Pen->Color = clGreen;
     TPoint *points; // <<===== Note here!
     points = new TPoint[data_length];
     for(int i=0; i<data_length; i++) points[i] = Point(i,
(int)data_array[i]);
     PaintBox->Canvas->Polyline(EXISTINGARRAY(points));
     delete[] points;

Quote
}

No error compiling, but nothing was drawn in the PaintBox.
What I did wrong?
 

Re:It doesn't Paint for new TPoint?


Quote
"Jian" <jxw...@uoguelph.ca> wrote:
> But, I have to force data_length = 512 (whatever the points
> size is declared).

What about calling Polyline like this:
    PaintBox->Canvas->Polyline(points, data_length-1)?

Quote
> No error compiling, but nothing was drawn in the PaintBox.

Take a look at EXISTINGARRAY:
  #define EXISTINGARRAY(a) (a), ((sizeof(a)/sizeof(a[0]))-1)

Your code translates to: ...->Polyline(points,
(sizeof(points)/sizeof(points[0]))-1);
Which is: ...->Polyline(points, 4/8 - 1);

Again, call ...->Polyline(points, data_length-1).

M.F.

Other Threads