注册 登录
编程论坛 Delphi论坛

[求助]关于函数调用

tendzzss 发布于 2006-04-12 23:29, 755 次点击

我在unit2定义了一个函数 在unit1里调用不了
uses里已经添加unit2
还需要干什么才能调用了
指点下

9 回复
#2
yuxue19852006-04-13 10:44

你用的是不是MDI子窗体?

你把事情说的明白一点!~有点不清楚

最好把你的代码穿上来

#3
tendzzss2006-04-13 11:59

我传上来了 下下去帮我看看
我还只懂一点皮毛 对于面向对象语言我一点不懂

[URL=http://lovemj.aa.topzj.com/viewthread.php?tid=114928&sid=FbncQj]http://lovemj.aa.topzj.com/viewthread.php?tid=114928&sid=FbncQj[/URL]
#4
tendzzss2006-04-14 11:51

谁帮我看看啊

#5
tendzzss2006-04-14 22:15

我把相关代码发上来 帮我看看
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation

{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
i:=7;
edit1.text:=change(i);
end;
end.

unit Unit2;
interface
uses
SysUtils,Windows;
implementation
function change(x:integer):string;
begin
change:=inttostr(x);
end;
end.
我照着写了个 大概能反映我的问题吧 说change函数没声明

#6
yuxue19852006-04-15 10:46

他们怎么能连接上啊

都不在一个窗体上

你要是想调用做一个全局变量

也就是所谓的先声明

要不就是做个MDI子窗体!~

然后在调用

不会的自己看书

一定要好好的学习

#7
tendzzss2006-04-15 11:01
怎么声明啊  写个大概代码行不 我只想在unit2中定义一些函数然后调用他 不知道怎么声明啊
#8
yuxue19852006-04-15 11:27
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
就是在这里加个全局声明就可以了!~

函数的声明格式如下

procedure 过程名称(参数表达式);声明修饰符 :过程语法

例子:procedure valpro(x:intteger;y:string);//自定义全局过程原型声明函数

function 函数名称(参数表达式);返回值的类型 :函数声明的语法


#9
xu20002006-04-15 11:55

这样写试试
unit Unit2;
interface
uses
SysUtils,Windows;
function change(x:integer):string;
implementation
begin
change:=inttostr(x);
end;
end.

#10
tendzzss2006-04-15 13:20
可以了  非常感谢  
1