Delphi 关键字详解 (3)
virtual
//Virtual用于声明一个虚方法,
//虚方法可以被覆盖, 并且可以使程序运行速度尽可能的快(区别于Dynamic).
procedure X(i: Integer); virtual;
while
//While关键字用于引出While循环语句, 循环前先进行循环条件的判断, 如果条件为真则执行循环.
i := 0;
while i < 100 do
begin
sum := sum + i;
Inc(i);
end;
with
//With关键字用于将相同的对象集合起来处理, 它可以省去输入大量重复的代码, 使代码看上去比较精简.
with Form1.Memo1.Lines do
begin
Clear;
Append('abc');
Append('def');
SaveToFile('C:\demo.txt');
end;
//上面这段代码如果不使用With语句, 则显得非常冗余复制内容到剪贴板代码:
Form1.Memo1.Lines.Clear;
Form1.Memo1.Lines.Append('abc');
Form1.Memo1.Lines.Append('def');
Form1.Memo1.Lines.SaveToFile('C:\demo.txt');
write
//Write用于标识属性中写入所使用的成员或方法.
private
fValue: Integer;
published
property Value: Integer write fValue;
//上例中即表明Value属性的值写入到fValue成员上.
writeonly
//writeonly关键字用于标识一个对象是否只写.
property writeonly;
//当writeonly设为True时, 不允许用户读取属性, 只能通过其他对象来操作.
xor
//Xor用于取异或, 当两个操作数相等时, 返回False, 不等时返回True.
var
a,b: Integer;
begin
a := 2; b := 3;
if a xor b then
WriteLn('a xor b')
else
WriteLn('a not xor b');
end;
//Xor也用于计算异或值
WriteLn(IntToStr(3 xor 5)); {6}