下面是一段代码
unit Unit1
interface
uses
   Windows,Messages,SysUtils;
type
  TForm1=class(TForm)
  private
    {Private declarations}
  public
    {Public declarations}
  end;
var
  From1:TForm1;
implementation{$R*.DFM}
end1.如果unit1需使用unit2单元内的变量v2,则unit2应如何在unit1中进行声明?
2.外挂DLL库时,声明应写在单元的何处?
3.新建一个内部函数或过程时,其声明部分应写在单元的何处?其代码部分写在单元的何处?
4.语句TForm1=class(TForm)是什么意思?
5.在哪些位置可引用其他单元?

解决方案 »

  1.   

    1.File->Use Unit里加入Unit2即可!
    2.Interface处
    3.声明部分写在Interface处,安Ctrl+Shilft+C会自动在implementation添加定义。
    4.表示从TForm继承一个类,这个类叫做TForm1
    5.Interface和implementation处都可以
      

  2.   

    补充:
    1.在Unit2中声明的变量必须是全局变量或类的公有变量,即在Unit2的Interface部分声明的。
    4.在Interface中引用的单元一般是系统单元。implementation中引用的是用户自写单元。
      在单元循环引用是要分别放在Interface部分和implementation部分!
      

  3.   

    unit Unit1
    interface
    uses
       Windows,Messages,SysUtils;
    type
      TForm1=class(TForm)
      private
        {Private declarations}
      public
        {Public declarations}
      end;
    var
      From1:TForm1;
    implementation
    uses Unit1;//在这里也行的{$R*.DFM}
    procedure ....
    begin
      with .....TFormName... do
    begin
    //...要用的代码。
    end;
    end;end
      

  4.   

    还有,一个过程或函数的内部也可以有另外一个过程或函数,这时并不要声明,只要定义,然后使用就可以了,如:
    procedure aaa();
      procedure bbb()
      begin
        //code
      end;
    begin
      bbb();
    end;