如何调用一个独立单元中的函数?(50分)

  • 主题发起人 Enigma0702
  • 开始时间
E

Enigma0702

Unregistered / Unconfirmed
GUEST, unregistred user!
我用一个独立的单元写公用函数,但怎么定义,才能在其他的单元中使用这个单元中的函数呢?
 
单元头改为Function写法类似于函数。在其他单元中用use把这个函数包括进去就行了。
 
建一个单元文件,加入所有的公用函数,然后在需调用的单元中uses该单元,即可直接调用其中的函数了
 
在要使用的单元文件中使用uses
那么在定义的单元文件中如何定义呢?
直接function displayPosition():integer;
这样为什么不行呢?
 
和一般的unit没有什么区别
 
unit Global;
interface
uses
Messages,Controls,Classes,Forms,windows,StrUtils, SysUtils;
function MsgBox(Msg:Variant;Title:string='';Flag:longint=0):integer;
implementation
function MsgBox(Msg:Variant;Title:string='';Flag:longint=0):integer;
//简化MessageBox函数
begin
if length(title)=0 then
title:=SAppName;
if flag=0 then
flag:=MB_OK + MB_ICONINFORMATION;
Result:=application.MessageBox(pchar(vartostr(Msg)),pchar(Title),flag);
end;
 
unit UnitCommFunc;
interface
uses Forms;
//function GetDisplayPosition():integer;

implementation
function GetDisplayPosition():integer;
begin
if (Screen.Width=800)then
Result:=1
else
if(Screen.Width=1024)then
Result:=2
else
Result:=3;
end;

end.
 
多人接受答案了。
 
顶部