在线等 --50分 Delphi中怎么声明一个全局数组

解决方案 »

  1.   

    public
         在此定义就行了,,
      

  2.   

    var
      Form1: TForm1;
      a: array[0..12] of DataType;
      

  3.   

    按照soldier7451说的做~~~其他的方法均不可取,保证各单元之间只有一层藕合关系
      

  4.   

    学习,我以前也是声明在var
      Form1: TForm1;
      a: array[0..12] of DataType;
      

  5.   

    var
      Form1: TForm1;
      a: array[0..12] of DataType;
      

  6.   

    按照soldier7451说的做~~~其他的方法均不可取,保证各单元之间只有一层藕合关系
      

  7.   

    public
         在此定义就行了,,和var
      Form1: TForm1;
      a: array[0..12] of DataType;两种方法定义有什么区别呢?
      

  8.   

    public
         在此定义就行了,,和var
      Form1: TForm1;
      a: array[0..12] of DataType;两种方法定义有什么区别呢?
    //第一种方法访问时要加上单元名,如unit1.变量名。
    第二种方法直接写变量名就可以了。
      

  9.   

    如果需要定义程序中使用的全局变量,那么把这个变量定义在Interface段中。如果需要定义单元中使用的全局变量,那么把这个变量定义在Implementation中。一般情况下,最好把全局的数据单独定义在一个单独的单元文件中,这样比较好维护。以下是一个例子:unit CNGP_Protocol;interfaceType
        //CNGP TLV Record
        TCNGP_TLV = Packed Record
            Paramter_Tag : SmallInt; //Tag of parameter
            Length       : SmallInt; //Length of value
            Value        : ShortInt; //Value
        End;    //CNGP Message Head
        PCNGP_HEAD = ^TCNGP_HEAD;
        TCNGP_HEAD = Packed Record
            Total_Length   : Longword; //Package length( include head and body )
            Command_ID     : Longword; //Communication command
            Command_Status : Longword; //Command execute status code
            Sequence_ID    : Longword; //Working serial
        End;    //CNGP login request body
        PCNGP_LOGIN = ^TCNGP_LOGIN;
        TCNGP_LOGIN = Packed Record
            Client_ID            : Array [ 0 .. 9 ] Of Char;  //SP Corporation ID
            Authenticator_Client : Array [ 0 .. 15 ] Of Char; //Client MD5 result
            Login_Mode           : Byte;                      //Login types
            Timestamp            : Longword;                  //Login timestamp, format is 'mmddhhmmss'
            Version              : Byte;                      //Client support the highest CNGP protocol version
        End;    //CNGP login respond body
        TCNGP_RESP_LOGIN = Packed Record
            Authenticator_Server : Array [ 0 .. 15 ] Of Char; // Server MD5 result
            Version              : Byte;                      //Server support the highest CNGP protocol version
        End;    //CNGP submit body
        PCNGP_SUBMIT = ^TCNGP_SUBMIT;
        TCNGP_SUBMIT = Packed Record
            SP_ID              : Array [ 0 .. 9 ] Of Char;  //SP Corporation ID
            Sub_Type           : Byte;                      //Short message sub tpyes
            Need_Report        : Byte;                      //Flag of report
            Priority           : Byte;                      //Short message transmit priority
            Service_ID         : Array [ 0 .. 9 ] Of Char;  //Servcie of short message
            Fee_Type           : Array [ 0 .. 1 ] Of Char;  // Fee type of short message
            Fee_User_Type      : Byte;                      // Fee user type of short message
            Fee_Code           : Array [ 0 .. 5 ] Of Char;  //Fee of short message, unit is FEN
            Msg_Format         : Byte;                      //Short message format
            Vaild_Time         : Array [ 0 .. 16 ] Of Char; //Valid timestamp of short message, format is 'yyyymmddhhmmss'
            At_Time            : Array [ 0 .. 16 ] Of Char; //Transmit timestamp of short message, format is 'yyyymmddhhmmss'
            Src_Term_ID        : Array [ 0 .. 20 ] Of Char; //Source user phone code
            Charge_Term_ID     : Array [ 0 .. 20 ] Of Char; //Fee user phone code
            Dest_Term_ID_Count : Byte;                      //Count of transmit user
            //Dest_Term_ID       : Array [ 0 .. 20 ] Of Char; //Target user phone code
            //Msg_Length         : Byte;                      //Length of short message
        End;    //CNGP submit respond body
        TCNGP_RESP_SUBMIT = Packed Record
            Msg_ID           : Array [ 0 .. 9 ] Of Char; //Message ID of short message
            Congestion_State : TCNGP_TLV;                //TLV
        End;    //CNGP deliver body
        PCNGP_DELIVER = ^TCNGP_DELIVER;
        TCNGP_DELIVER = Packed Record
            Msg_ID       : Array [ 0 .. 9 ] Of Char;  //Message ID of short message
            Is_Report    : Byte;                      //Flag of report
            Msg_Format   : Byte;                      //Short message format
            Recv_Time    : Array [ 0 .. 13 ] Of Char; //Recieve Timestamp
            Src_Term_ID  : Array [ 0 .. 20 ] Of Char; //Source user phone code
            Dest_Term_ID : Array [ 0 .. 20 ] Of Char; //Target user phone code
            Msg_Length   : Byte;                      //Length of short message
        End;    //CNGP deliver respond body
        TCNGP_RESP_DELIVER = Packed Record
            Msg_ID           : Array [ 0 .. 9 ] Of Char; //Message ID of short message
            Congestion_State : TCNGP_TLV;                //TLV
        End;    //CNGP MT report body
        PCNGP_MT_REPORT = ^TCNGP_MT_REPORT;
        TCNGP_MT_REPORT = Packed Record
            ID          : Array [ 0 .. 9 ] Of Char;  //Message ID of short message
            Sub         : Array [ 0 .. 2 ] Of Char;  //value is '001';
            Dlvrd       : Array [ 0 .. 2 ] Of Char;  //value is '001';
            Submit_Date : Array [ 0 .. 9 ] Of Char;  //Submit timestamp of short message, format is 'yymmddhhmm'
            Done_Date   : Array [ 0 .. 9 ] Of Char;  //Report timestamp of short message, format is 'yymmddhhmm'
            Stat        : Array [ 0 .. 6 ] Of Char;  //State of short message
            Err         : Array [ 0 .. 2 ] Of Char;  //Error code of short message
            Txt         : Array [ 0 .. 19 ] Of Char; //Information of short message
        End;    //Map of report error code and report state
        TCNGP_REPORT_ERROR_STATE_MAP = Packed Record
            Error_Code : Array [ 0 .. 2 ] Of Char; //Error Code
            State      : Array [ 0 .. 6 ] Of Char; //Report state
        End;    ......Var
       //以下就是你需要的全局数组的定义!!!
       Report_Map : Array [ 0 .. 10 ] Of TCNGP_REPORT_ERROR_STATE_MAP =
                  (
                    ( Error_Code : REPORT_ERROR_SUCCESS;          State : REPORT_STATE_DELIVERED ),
                    ( Error_Code : REPORT_ERROR_COMUNICATION;     State : REPORT_STATE_EXPIRED ),
                    ( Error_Code : REPORT_ERROR_USER_BUSY;        State : REPORT_STATE_EXPIRED ),
                    ( Error_Code : REPORT_ERROR_INVALID_TERM;     State : REPORT_STATE_UNDELIVERABLE ),
                    ( Error_Code : REPORT_ERROR_INVALID_USER;     State : REPORT_STATE_UNDELIVERABLE ),
                    ( Error_Code : REPORT_ERROR_BLACK_LIST;       State : REPORT_STATE_UNDELIVERABLE ),
                    ( Error_Code : REPORT_ERROR_SYSTEM;           State : REPORT_STATE_UNDELIVERABLE ),
                    ( Error_Code : REPORT_ERROR_OUTOF_MEMORY;     State : REPORT_STATE_EXPIRED ),
                    ( Error_Code : REPORT_ERROR_INVALID_SRC_TERM; State : REPORT_STATE_UNDELIVERABLE ),
                    ( Error_Code : REPORT_ERROR_DATA;             State : REPORT_STATE_UNDELIVERABLE ),
                    ( Error_Code : REPORT_ERROR_LOST_DATA;        State : REPORT_STATE_UNDELIVERABLE )
                  );
                  
    implementationend.
      

  10.   

    Application级的,定义在一个单元文件中,要用到的窗口或单元引用那个单元。
    窗口级的,我一般定义在
      private
        { Private declarations }
        FStep:integer;或
    implementation
    var
      FStep:integer;如果这个变量是这个窗口的,但其它的窗口会访问到。刚放在
      public
        { Public declarations }
        FStep:integer;