If the interpretation of obj involves indexing arrays or dereferencing pointers, these actions are performed once, before statement is executed. This makes with statements efficient as well as concise. It also means that assignments to a variable within statement cannot affect the interpretation of obj during the current execution of the with statement.——
这是 delphi7 自带帮助中对 with 用法的一段说明,不甚明白,请大虾们举例说明。
这是 delphi7 自带帮助中对 with 用法的一段说明,不甚明白,请大虾们举例说明。
memo1.lines.add('2');
memo1.lines.add('3');
----
with memo1 do
begin
lines.add(1);
lines.add('2');
lines.add('3');end
with OrderDate do
begin
Year := Unit1.Year
...
end;OrderDate 和Unit1中都有Year变量时,你该如何做
不是不知道基本用法,只是不知道那段话所说的情形。To 2L:
这个例子是针对那段话下面的一段话所说的情形。To 3L:
问题不是翻译,翻译不是问题。还有哪些大虾愿意拔刀相助……
使用with fungetobj(xxx) do
begin
fielda:=1;
fieldb:=2;
end;
只要执行函数一次
而fungetobj(xxx).a:=1; fungetobj(xxx).b:=2;显然就执行函数2次了如果一个对象是通过数组的原始才返回的,也是类似:with objarr[i] do
不过我还是更希望有这样的语法:
with x.a.obj as oa,y.b.obj as ob do
begin
oa.fielda:=1;
ob.fieldb:=2;
end;
这样好像与自己把变量、指针去承接差不多了,但是可以省掉定义变量、指针的麻烦
//If the interpretation of obj involves indexing arrays or dereferencing pointers, these actions are performed once, before statement is executed.
//这个 Create 在 with 里头的语句执行前只执行一次
begin
Add('1');
s := Strings[0];//It also means that assignments to a variable within statement cannot affect the interpretation of obj during the current execution of the with statement.
end;