简单的问题 ( 积分: 20 )

  • 主题发起人 主题发起人 cooldren
  • 开始时间 开始时间
C

cooldren

Unregistered / Unconfirmed
GUEST, unregistred user!
一个窗口如何调用另一个单元的函数


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(add(2,3));
end;

end.



unit Unit2;

interface

implementation


function Add(i,j:integer):integer;
begin
result:=i+j;
end;
end.
怎么调用Unit2中的Add呀?
谢谢!
 
一个窗口如何调用另一个单元的函数


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(add(2,3));
end;

end.



unit Unit2;

interface

implementation


function Add(i,j:integer):integer;
begin
result:=i+j;
end;
end.
怎么调用Unit2中的Add呀?
谢谢!
 
在单元unit2写
public
function Add(i,j:integer):integer;
 
能给unit2的全部内容吗?试了一下,不行
 
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function Add(i,j:integer):integer;
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

function TForm2.Add(i,j:integer):integer;
begin
result:=i+j;
end;

end.
 
unit Unit2;
interface
function Add(i,j:integer):integer;
implementation
function Add(i,j:integer):integer;
begin
result:=i+j;
end;
end.
..........无话可说
 
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function Add(i,j:integer):integer;
{ Public declarations }
end;

function TForm1.Add(i,j:integer):integer;
begin
result:=i+j;
end;
别的单元就可以调用了调用时写:Tform1.add();
 
谢谢各位
 

Similar threads

I
回复
0
查看
686
import
I
I
回复
0
查看
541
import
I
I
回复
0
查看
673
import
I
I
回复
0
查看
763
import
I
I
回复
0
查看
740
import
I
后退
顶部