The first encountered error on the line that reads:
"a := hexstr(header[1]);" is because HexStr function has an overloaded function that accepts a single parameter.
The drawback of that, in such case the provided parameter must be a pointer. See also
documentationAssuming that you wish to have a single character from your header array 'copied' into your variable named a, then you could use
a := Char(header[1]);Because your header variable is declared an array of bytes, each individual item inside that array is of type Byte.
So, header[1] will 'extract' the first byte from that array. But, it is still a byte. That is why the compiler would 'stumble' on that as well. Therefor we add an additional cast ( Char(...) ) so that the byte is seen by the compiler as a character.
The second error, most probably stems from the fact that you seem to believe that you can copy a range of characters from an array by providing a range. Pascal is not python and the likes
So, the line
"a := hexstr(header[1..5]);" should look something like
"for i := 1 to 5 do a := a + Char(header);"Here is your complete program with additional 'solutions' to your compilation errors.
program readheader;
var
header : array[1..10] of byte;
i : integer;
filename : file of byte;
numread : word;
a : string;
begin
assign (filename, 'data.bin');
reset (filename) ;
// read block (10 bytes)
blockread (filename, header, sizeof(header), numread);
writeln;
write('header = ');
for i := 1 to 10 do
write(hexstr(header[i], 2));
WriteLn;
// try to get one byte from the header
a := hexstr(header[1],2);
writeln('substring as hex = ', a);
a := Char(header[1]);
writeln('substring as ascii = ', a);
// or try to get several bytes from the header
a := '';
for i := 1 to 5 do a := a + hexstr(header[i],2);
writeln('substring as hex = ', a);
a := '';
for i := 1 to 5 do a := a + Char(header[i]);
writeln('substring as ascii = ', a);
SetString(a, PChar(@header[1]), 4);
writeln('substring as ascii = ', a);
close (filename);
end.
There are other solutions possible as well, but hopefully the above would be enough to get you going.