[fpc-pascal] From C to Pascal -- Help!

Jilani Khaldi jilani at cheapnet.it
Mon Nov 12 20:25:13 CET 2007


Hi All,
I am translating a piece of code from C to Pascal...
Any help? Thanks!

/* C code */
void draw_fonts (HPDF_Page   page)
{
     int i;
     int j;

     HPDF_Page_BeginText (page);

     /* Draw all character from 0x20 to 0xFF to the canvas. */
     for (i = 1; i < 17; i++) {
         for (j = 1; j < 17; j++) {
             unsigned char buf[2];
             int y = PAGE_HEIGHT - 55 - ((i - 1) * CELL_HEIGHT);
             int x = j * CELL_WIDTH + 50;

             buf[1] = 0x00;

             buf[0] = (i - 1) * 16 + (j - 1);
             if (buf[0] >= 32) {
                 double d;

                 d  = x - HPDF_Page_TextWidth (page, (char*)buf) / 2;
                 HPDF_Page_TextOut (page, d, y, (char*)buf);

             }
         }
     }

     HPDF_Page_EndText (page);
}

// Pascal translation
procedure draw_fonts(page: HPDF_Page);
var
   buf: array[0..1] of byte;
   i, j, x, y: integer;
   d: double;
   PP: PChar;
begin
   HPDF_Page_BeginText (page);
   //* Draw all character from 0x20 to 0xFF to the canvas. */
   for i := 1 to 16 do
     for j := 1 to 16 do
     begin
        y := PAGE_HEIGHT - 55 - ((i - 1) * CELL_HEIGHT);
        x := j * CELL_WIDTH + 50;
        buf[1] := $0;
        buf[0] := (i - 1) * 16 + (j - 1);
        if (buf[0] >= 32) then
        begin
          PP := PChar(buf[0]);
          d := x - HPDF_Page_TextWidth(page, PP) / 2;
          ///////// Executing the line above gives an Access Violation!!!!!
          HPDF_Page_TextOut (page, d, y, PP);
        end;
     end;
     HPDF_Page_EndText (page);
end;


-- 
Jilani KHALDI




More information about the fpc-pascal mailing list