Delphi ^ A语法:记录,暗示或无证? [英] Delphi ^A syntax: Documented, implied, or undocumented?

查看:220
本文介绍了Delphi ^ A语法:记录,暗示或无证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我以一个例子来解释。在Delphi中,你可以写

  procedure TForm1.FormKeyPress(Sender:TObject; var Key:Char); 
begin
如果Key = ^ C then
ShowMessage('用户想要复制的东西'。)
else if Key = ^ V then
ShowMessage用户想要粘贴。)
end;

检查Ctrl + C和Ctrl + V键盘命令。事实上,同样的语法适用于Ctrl + A,其中A是任何字符,当然也可以使用 case 语句,而不是 if 。你甚至可以 ShowMessage(^ A),所以,显然, ^ A 被认为是 char



但是,在浏览官方Delphi文档,我找不到任何引用这个语法。但也许 ^ A 语法是如此常见,它被理解为基本纯文本文件格式的一部分?还是仅仅是Delphi编程语言的一个无证的特性? (注意,上面的结构实际上是在RTL / VCL源代码中使用的,但是,当然,Embarcadero和Embarcadero可以使用未记录的特性,如果存在的话)。


<这是很久以前的转义字符,使您能够以更可读的方式使控制字符的常量。


$ b

$ b

  const 
CtrlC = ^ C;
begin
Write(Ord(CtrlC));
end。

这定义了一个值为的char常量,然后在Borland Pascal 7中写入 3 ,我记得在这之前也看到它。



检查Turbo Pascal 5.0和Borland Pascal 7.0语言指南,但找不到它,因此似乎没有记录。



编辑:
我记得这是一个Borland的东西,只是检查:它不是ISO Pascal标准的一部分以前是ANSI Pascal标准,感谢Sertac注意到这一点)。



记录在免费Pascal文档



SGI使用反斜杠作为转义字符,如他们的文档



更多编辑:我发现它 Delphi基础网站



找到了:发现它在 Turbo Pascal 3的第37页参考手册



- jeroen


Let me explain by an example. In Delphi, you can write

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = ^C then
    ShowMessage('The user wants to copy something.')
  else if Key = ^V then
    ShowMessage('The user wants to paste.')
end;

to check for Ctrl+C and Ctrl+V keyboard commands. In fact, the same syntax works for Ctrl+A, where A is any character, and -- of course -- you can also use a case statement instead of ifs. You can even do ShowMessage(^A), so, apparently, ^A is considered a char.

However, when browsing the official Delphi documentation, I cannot find any reference to this syntax. But maybe the ^A syntax is so common that it is understood as a part of the underlying plain text file format? Or is it simply an undocumented feature of the Delphi programming language? (Notice that the above constructions are actually used in the RTL/VCL source code. But, of course, Embarcadero, and Embarcadero alone, is allowed to use undocumented features, if any such exists.)

解决方案

This is from long ago as an escape character to enable you to have consts for control characters in a more readable way.

const
  CtrlC = ^C;
begin
  Write(Ord(CtrlC));
end.

This defines a Char constant with value #3, then writes 3 in Borland Pascal 7, and I remember seeing it years before that too.

I just checked the Turbo Pascal 5.0 and Borland Pascal 7.0 languages guides, but could not find it, so it seems undocumented.

Edit: I do remember this was a Borland thing, and just checked: it is not part of the ISO Pascal standard (formerly this was ANSI Pascal Standard, thanks Sertac for noticing this).

It is documented in the Free Pascal documentation.

SGI uses the backslash as escape character, as per their docs.

More Edit: I found it documented in Delphi in a Nutshell and the Delphi Basics site.

Found it: Just found it on page 37 of the Turbo Pascal 3 Reference Manual.

--jeroen

这篇关于Delphi ^ A语法:记录,暗示或无证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆