[fpc-pascal] Accessing open array

Koenraad Lelong fpascal at brouwerij.homelinux.net
Sun Jun 3 17:53:02 CEST 2012


Hi,

Im trying to access an open array but I get a runtime error. I googled a 
bit, and found some suggestions, but for me they don't work.
It's actually a port of some C-library I want to use on a STM32-processor.

This is my test-code :

program LCDtest1;

type
  TArray = array of byte;

var
  nCols : cardinal;
  nRows : cardinal;
  nBytes : cardinal;
  pFont : ^TArray;

{$include fonts.inc}

begin

// get pointer to the beginning of the selected font table
pFont:=@FONT6x8;
writeln('0');
setlength(pFont^,8);  <-- here it crashes
writeln('1');
nCols:=pFont^[0];
//nCols:=pFont^[low(pFont^)];
{writeln('2');
nRows:=pFont^[1];
writeln('3');
nBytes:=pFont^[2];}
writeln('end');
end.

I didn't have the setlength at first, then it crashed at the first 
access of the array (ncols:=...).

The include file contains this (only partly shown) :

originally :

const
   FONT6x8 : array[0..96] of array[0..7] of byte = (
($06,$08,$08,$00,$00,$00,$00,$00), // columns, rows, num_bytes_per_char
($00,$00,$00,$00,$00,$00,$00,$00), // space $20
($20,$20,$20,$20,$20,$00,$20,$00), // !
($50,$50,$50,$00,$00,$00,$00,$00), // "
($50,$50,$F8,$50,$F8,$50,$50,$00), // #
...

modified (with the same error) :

const
   FONT6x8 : array[0..775] of byte = (
($06,$08,$08,$00,$00,$00,$00,$00, // columns, rows, num_bytes_per_char
($00,$00,$00,$00,$00,$00,$00,$00, // space $20
($20,$20,$20,$20,$20,$00,$20,$00, // !
($50,$50,$50,$00,$00,$00,$00,$00, // "
($50,$50,$F8,$50,$F8,$50,$50,$00, // #
...

Any suggestions how I can correct my code ?

Thanks,

Koenraad Lelong.



More information about the fpc-pascal mailing list