procedure a1;
const  bASC:Boolean=True;
begin
  bASC:= not bASC;
end;
我用Delphi6的时候这段程序编译通过,为什么同样的程序到了Delphi7下面就不行了呢?

解决方案 »

  1.   

    可能D7把const认为是真的常量了
      

  2.   

    {$J+}
    procedure a1;
    const  bASC:Boolean=True;
    begin
      bASC:= not bASC;
    end;
    {$J-}
    通过编译器开关J来显式指定常量为静态变量
      

  3.   

    D7也行的,主要是设置.
    在Project Properties对话框里,有个叫什么Assignable typed constant(好象是,类似的)的复选框,选上就行了.
      

  4.   

    D7关于J的开关的默认值变了, 你参考一下D7的What's New.但是, 你这种写法是不值得提倡的, 常量就是常量, 变量就是变量, 不要混用. 另外, 定义常量时, 建议不要加类型定义. -----------------
    procedure a1;
    const  bASC:Boolean=True;
    begin
      bASC:= not bASC;
    end;
    我用Delphi6的时候这段程序编译通过,为什么同样的程序到了Delphi7下面就不行了呢?
      

  5.   

    up 
    good,上面的朋说得有道理~~~~~~~~~~~~~`
      

  6.   

    [Delphi Help]
    Writeable typed constants//可写类型的常量TypeSwitch
    Syntax{$J+} or {$J-}{$WRITEABLECONST ON} or {$WRITEABLECONST OFF}
    Default{$J-}{$WRITEABLECONST OFF}
    ScopeLocal
    The $J directive controls whether typed constants can be modified or not. In the {$J+} state, typed constants can be modified, and are in essence initialized variables. In the {$J-} state, typed constants are truly constant, and any attempt to modify a typed constant causes the compiler to report an error.
    Writeable consts refers to the use of a typed const as a variable modifiable at runtime. For example:const   foo: Integer = 12;
    begin
        foo := 14;end.With $WRITEABLECONST OFF, this code produces a compile error on the assignment to the foo variable in the begin..end block.  To fix it, change the const declaration to a var declaration.In previous versions of Delphi and Borland Pascal, typed constants were always writeable, corresponding to the {$J+} state. Old source code that uses writeable typed constants must be compiled in the {$J2B} state, but for new applications it is recommended that you use initialized variables and compile your code in the {$J-} state.———————————
    ┏━★━━◆━━★━┓ 
    ♂欢|◢CSDN◣|使♂       
    ┃迎|◥论坛助手◤|用┃       
    ┗━☆━━◇━━━☆┛      
      

  7.   

    支持,
    'D7也行的,主要是设置.
    在Project Properties对话框里,有个叫什么Assignable typed constant(好象是,类似的)的复选框,选上就行了.'
      

  8.   

    似乎d7中变量定义时初始化是改为 var  somevar := somevalue方式
      

  9.   

    定义成const改变了变量的存活