[fpc-pascal]sizeof returns wrong size?

James_Wilson at i2.com James_Wilson at i2.com
Tue Mar 26 22:34:13 CET 2002

I'm attempting to write a generic writeln type of procedure for win32 
console mode programs, but I'm having trouble using sizeof. I'm reasonably 
certain I've got it written correctly, but perhaps I'm missing something. 
The procedure looks like this:

Procedure Win32Write (Col,Row : byte; var SourceData);

  BuffSize  : TCoord;
  BuffCoord  : TCoord;
  DestRect  : TSmallRect;


  // BuffSize is how big a window to write
  BuffSize.X := sizeof (SourceData);
  BuffSize.Y := 1;

  // BuffCoord is where in the window to start
  BuffCoord.X := 0;
  BuffCoord.Y := 0;

  // DestRec is where on the screen to write, here it's at Col,Row
  DestRect.Top := pred (Row);
  DestRect.Bottom := pred (Row);
  DestRect.Left := pred (Col);
  DestRect.Right := pred (sizeof (SourceData));

  WriteConsoleOutput (getstdhandle (std_output_handle), @SourceData, 
BuffSize, BuffCoord, DestRect);


Data being passed as SourceData is an array of tcharinfo.

Where I'm having the problem is that sizeof returns invalid information 
about the actual size of the SourceData variable. For example, if I pass 
an array with only [1..10] elements sizeof doesn't return a value of 10. 
And WriteConsoleOutput needs to have the correct sizes established for 
BuffSize.X and DestRectRight, or it prints garbage (if the numbers for 
those variables are larger then the data you're trying to print the 
remainder of the line is random, colored blocks). 

Since SourceData can be any size, how do I know how large it is so I can 
set those values properly?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20020326/1d8213a7/attachment.html>

More information about the fpc-pascal mailing list