在Delphi的数字之前"$"是什么意思?

sif*_*all 10 vb.net delphi syntax

我正在尝试将Delphi代码转换为vb.net,我不确定这一行:

stream.Seek($42, soFromBeginning);
Run Code Online (Sandbox Code Playgroud)

我熟悉在文件流上使用搜索(在vb.net中),但我不确定$42.

我假设这对应于某个职位,但这又如何转化为vb.net?

小智 14

$是十六进制常量的前缀.在VB.NET中,那是&H,所以你会写&H42.

  • @ az01现在我已经尝试过了,就Delphi而言,我认为0x是无稽之谈. (2认同)
  • @ Az01可能正在考虑*字符串*被转换为整数.`Val`函数接受`$`,`x`,`X`,`0x`和`0X`作为十六进制前缀,`Val`是`StrToInt`和`Read`使用的.但是`Val`不是解析Delphi语言时使用的东西; 编译器只接受十六进制数的`$`. (2认同)

Dav*_*nan 5

The code required for VB.net is almost identical:

stream.Seek(&H42, SeekOrigin.Begin)
Run Code Online (Sandbox Code Playgroud)

The points of note here are:

  • $ in Delphi is the prefix for hexadecimal.
  • The soFromBeginning corresponds to SeekOrigin.Begin.