Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-11

From C to Pascal -- Help!

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jilani Khaldi

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
Mattias Gaertner
to Jilani Khaldi
Show quoted text 55 lines
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]);
           PP := PChar(@buf[0]);
Show quoted text 7 lines
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;

Mattias