7

Q1: What does this mean: WriteLn (#$0b)?

$0b should hexadecimal like 0x0b, but what about the # sign?

Q2:

x:=readkey;
if ( x = #5) do...

Does #5 mean five? Then what is the# sign for?

Many thanks.

Nick Dandoulakis
  • 42,588
  • 16
  • 104
  • 136
  • (Note that in (even not so) recent Delphi and FPC versions larger numbers than 255 are widechars, 16-bit base entity used a base for UTF16 string types) – Marco van de Voort Apr 27 '13 at 10:40

2 Answers2

7

The # in front of a number represents a character with the indicated value (both decimal, and hex numbers preceded by a $, are accepted). So #5 is the same as chr(5), or CtrlE.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Had to look up [`chr`](http://physinfo.ulb.ac.be/cit_courseware/pascal/pas036.htm) for this answer to help, but at least I knew to look up `chr`. `chr(65) = #65 = 'A'` – DCShannon May 27 '15 at 03:25
  • Not always. In D3..D2007 and FPC, you can afaik define a widechar with #$1234 and chr() will only return a byte value. I'm away from my development machine so can't quickly test const xx= #$1234; begin writeln(sizeof(xx), sizeof(chr($1234))); end. – Marco van de Voort Oct 11 '22 at 17:15
2

Ah, memories ...

#x is indeed the equivalent of chr(x), like Greg Hewgill said.

I'd like to add a little info.
Extended keys, ie the arrow keys, send zero and the char's code:

  ch := ReadKey;
  if ch = #0 then
  begin // extended key
    ch := ReadKey; // <-- read again to get the actual code
  end else ...
Community
  • 1
  • 1
Nick Dandoulakis
  • 42,588
  • 16
  • 104
  • 136