大家好:我在UNIT中用到了一个变量,每个过程中都能用到,所以我在PRIVATE中定义了,如下unit ***;interfaceprivate  abc : string;
implementationuses ....procedure.....
begin
 abc := 'abcdeff';end但是这样,每一个PROCEDURE中都要写一遍abc := 'abcdeff';有没有什么办法在interface或implementation直接一次赋值吗?(不想再用一个PUBVAR单元)谢谢,在线等

解决方案 »

  1.   

    initialization  Form1.abc := 'abcdeff'
      

  2.   

    在构造函数里面写呀unit Unit1;interfaceuses Classes,Dialogs;type
      TMyClass = class
       private
         FValue:string;
       public
         procedure ShowValue();
         constructor Create;
      end;implementationconstructor TMyClass.Create;
    begin
      FValue:='abcdefg';
    end;procedure TMyClass.ShowValue();
    begin
      ShowMessage(FValue);
    end;end.
      

  3.   

    晕,你说的似乎是常量哦,常量就直接用const
      

  4.   

    我定义的有这几个变量类型: string,tadoquery,tdatasource等
      

  5.   

    usesconst
      abc: string='abcdeff';