Delphi ^ A语法:记录,隐含或无文档? [英] Delphi ^A syntax: Documented, implied, or undocumented?
问题描述
procedure TForm1.FormKeyPress(Sender:TObject; var Key:Char);
begin
如果Key = ^ C然后
ShowMessage('用户想要复制的东西')
如果Key = ^ V然后
ShowMessage('The用户想粘贴。')
end;
检查Ctrl + C和Ctrl + V键盘命令。实际上,相同的语法适用于Ctrl + A,其中A是任何字符,当然,您也可以使用案例
语句,而不是,如果
s。你甚至可以执行 ShowMessage(^ A)
,所以显然, ^ A
被认为是一个 char
。
但是,当浏览官方Delphi文档,我找不到任何这种语法的引用。但是,也许 ^ A
语法是很常见的,它被理解为底层纯文本文件格式的一部分?还是只是Delphi编程语言的一个无证的功能? (请注意,上述结构实际上是在RTL / VCL源代码中使用的,但是当然,只有Embarcadero和Embarcadero才允许使用未记录的功能,如果存在这些功能)。
这是从很久以前的一个转义字符,使您能够以更可读的方式为控制字符添加const。
const
CtrlC = ^ C;
begin
写(Ord(CtrlC));
结束。
这定义了一个值为#3的Char常量
,然后在Borland Pascal 7中写入 3
,我记得几年前就看到了。
我只是检查了Turbo Pascal 5.0和Borland Pascal 7.0语言指南,但找不到它,因此似乎没有记录。
编辑:
我记得这是一个Borland的事情,只是检查:它不是ISO Pascal标准的一部分(以前这是ANSI Pascal Standard,谢谢Sertac注意到这一点)。
它 是。 html#x20-190001.8>免费Pascal文档。
SGI使用反斜杠作为转义字符,如他们的文档。
找到它:刚刚在 Turbo Pascal 3参考手册。
- 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 if
s. 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屋!