请教高手:unit2 如何调用 unit1中的函数呀?

yan32711 2009-07-26 08:50:52
如题:
...全文
153 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
ok1411 2009-07-30
  • 打赏
  • 举报
回复
孺子可教也
慢慢来- -
zshsuming 2009-07-29
  • 打赏
  • 举报
回复
楼主,你这样学习态度可不行啊,uint1和uint2只不过是个名称,你应该在大学给你讲解和指导的同时,进行思考,不明白的地方先去找书去看看,然后再来问。
hujun_zero 2009-07-28
  • 打赏
  • 举报
回复
这个帖子也顶得忒高了
hljiayou 2009-07-28
  • 打赏
  • 举报
回复
[Quote=引用 21 楼 yan32711 的回复:]
这么看来,是不需要在public中声明函数了,只要在需要调用的unit中写上used+调用的unit即可?
[/Quote]

差不多,在要调用的unit中的implementation下写uses + 调用的unit名字,就可以调用其中的属性、方法
yan32711 2009-07-28
  • 打赏
  • 举报
回复
这么看来,是不需要在public中声明函数了,只要在需要调用的unit中写上used+调用的unit即可?
yan32711 2009-07-28
  • 打赏
  • 举报
回复
8楼写的似乎是uint1调用uint2,而非uint2调用uint1?是这样吧?
macchen1224 2009-07-28
  • 打赏
  • 举报
回复
你好,請先use unit2,然後使用請用form2.,即可參考到你要的form2內的東西了。
hljiayou 2009-07-28
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 yan32711 的回复:]
8楼写的似乎是uint1调用uint2,而非uint2调用uint1?是这样吧?
[/Quote]

反过来用就可以了。
hljiayou 2009-07-28
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 yan32711 的回复:]
请教:我在unit1的public中声明unit2中要调用的函数TexToBuf后,编译有eror:unsatisfied forword or extrnal declaration:'TFORM1.TexToBuf'.可是我并没有找到其他地方的声明。这是怎么回事呀?
[/Quote]

在你的函数前面加上TForm1.
火龙岛主 2009-07-27
  • 打赏
  • 举报
回复
unit2.function1(10)
yan32711 2009-07-27
  • 打赏
  • 举报
回复
谢谢大家哈,我试试。
zz1001 2009-07-27
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 zshsuming 的回复:]
unit Unit2;

interface
uses dialogs;

procedure hello;

implementation

procedure hello;
begin
  ShowMessage('hello world');
end;

end.


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
hello;
end;

end.

[/Quote]
支持,写得经典
贝隆 2009-07-27
  • 打赏
  • 举报
回复
文件-》Use Unit
yan32711 2009-07-27
  • 打赏
  • 举报
回复
请教:我在unit1的public中声明unit2中要调用的函数TexToBuf后,编译有eror:unsatisfied forword or extrnal declaration:'TFORM1.TexToBuf'.可是我并没有找到其他地方的声明。这是怎么回事呀?
msky850917 2009-07-27
  • 打赏
  • 举报
回复
unit1里把函数定义为public类型的
unit2里 use unit1
然后form2.函数 的形式调用unit1里面的函数
yan32711 2009-07-27
  • 打赏
  • 举报
回复
我在unit1的public中声明unit2中要调用的函数TexToBuf后,编译有eror:unsatisfied forword or extrnal declaration:'TFORM1.TexToBuf'.可是我并没有找到其他地方的声明。这是怎么回事呀?
hljiayou 2009-07-27
  • 打赏
  • 举报
回复
如果是系统的单元文件,直接在uses后面添加

如果是自定义的单元文件,需要互相使用的话,就在implementation之后uses添加一下要使用的单元文件名
米的向日葵 2009-07-27
  • 打赏
  • 举报
回复
楼上的楼上真详细
bewild 2009-07-27
  • 打赏
  • 举报
回复
楼上真详细
zshsuming 2009-07-27
  • 打赏
  • 举报
回复
unit Unit2;

interface
uses dialogs;

procedure hello;

implementation

procedure hello;
begin
ShowMessage('hello world');
end;

end.


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
hello;
end;

end.
加载更多回复(5)

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧