有关单元文件的小问题(50分)

P

pototo

Unregistered / Unconfirmed
GUEST, unregistred user!
刚学delphi,有个小问题想请教各位高手
我想在一个新的、不含任何窗体的单元文件中提供一个aaa函数给别的单元使用,
该怎么做啊?
 
在别的单元中
uses yourunit 即可。
 
//------------------------------------------------------------------------------
//Global.pas
//共享模块,保存字符串资源和共享常量、变量、函数及过程
//------------------------------------------------------------------------------
unit Global;
interface
uses
Messages,Controls,Classes,Forms,windows,Variants;
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;

//------------------------------------------------------------------------------
//TForm1.pas
//------------------------------------------------------------------------------
unit MDIMain;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms,Global;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
protected
public
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MsgBox('OK');
end;
 
unit unit1 //提供服务的单元,该窗体的名字为form1
...
function TheServer
...
unit unit2 //调用单元
implementation
uses unit1;//引用
a:=form1.TheServer;//调用unit1单元的函数
应该写的很清楚了


 
顶部