如何何到全局过程声明?
刚学习delphi的新人,碰到一个问题。以往用的是C++,函数都是先声明,后定义。在类定义的public或private区声明,即可在其它函数里使用。可在delphi里却实现不了这点,郁闷。
例如:
unit Score;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComObj, StdCtrls, xmldom, XMLIntf, msxmldom, XMLDoc;
type
TForm1 = class(TForm)
btnWord: TButton;
btnExcel: TButton;
btnPowerPoint: TButton;
dlgOpen: TOpenDialog;
procedure btnWordClick(Sender: TObject);
private
{ Private declarations }
public
procedure search();
{ Public declarations }
end;
var
Form1: TForm1;
WordApp: variant;
WordDoc: variant;
WordRange: variant;
xmlDocument: IXMLDocument;
Root: IXMLNode;
Parent_Node: IXMLNode;
Child_Node: IXMLNode;
implementation
......
procedure wordconnect(.....);
var
.....
begin
.......search();......................第112行
end;
procedure search();
var
....
begin
.....
end;
编译就提示第112行处search是无定义。将search放于type区后,同样提示错误,难道delphi中必需要先定义后使用吗?请大侠指点。
[解决办法]
C++
class TForm1
{
//....
int func();
};
int TForm1::func()
{
//...
}
------------------------
Delphi
type
TForm1 = class(TForm)
function func():integer;
end;
//...
function TForm1.func():integer;
begin
//...
end;