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 用法的一段说明,不甚明白,请大虾们举例说明。

解决方案 »

  1.   

    memo1.lines.add('1');
    memo1.lines.add('2');
    memo1.lines.add('3');
    ----
    with memo1 do
    begin
      lines.add(1);
      lines.add('2');
      lines.add('3');end
      

  2.   

    帮助中不是给你举例了吗
    with OrderDate do
      begin
        Year := Unit1.Year
        ...
      end;OrderDate 和Unit1中都有Year变量时,你该如何做
      

  3.   

    如果obj的解释涉及的索引指针数组或提领,这些行动是执行一次,在语句执行。这使得具有高效率的陈述以及精简。这也意味着,转让给内声明变量可以在不影响当前执行的obj的解释与说明。这是Google的翻译。
      

  4.   

    To 1L:
    不是不知道基本用法,只是不知道那段话所说的情形。To 2L:
    这个例子是针对那段话下面的一段话所说的情形。To 3L:
    问题不是翻译,翻译不是问题。还有哪些大虾愿意拔刀相助……
      

  5.   

    如果一个对象是通过一个函数才返回的
    使用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;
    这样好像与自己把变量、指针去承接差不多了,但是可以省掉定义变量、指针的麻烦
      

  6.   

    而fungetobj(xxx).fielda:=1; fungetobj(xxx).fieldb:=2;显然就执行函数2次了 
      

  7.   

    with TStringList.Create() do
    //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;