我想问一下,假如我在一个窗体中定义了一个函数,怎么声明它,才能在另外一个窗体上去调用它,而不用在调用它的窗体中再重新定义一遍。

解决方案 »

  1.   

    unit1
    .....
    function GetNodeAt(X, Y: Integer): TTreeNode;
    ...unit2  
    ....
    uses unit1
    ...
    Treenode:=unit1.GetNodeAT(x,y);
    ...
      

  2.   

    把函数定义在implementation之前,如
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;function func: string;implementation{$R *.dfm}function func: string;
    begin
      Result := 'Hello'
    end;end.在另一个单元中
    uses Unit1;ShowMessage(func);
      

  3.   

    放在public里,也可放在published里,不过后一种一般都是用于控件的属性和事件定义!