请问,用Delphi编程时,怎样使编写的过程在整个工程通用?

来源:百度知道 编辑:UC知道 时间:2024/06/14 13:25:57
请问,用Delphi编程时,怎样使编写的过程在整个工程通用?
比如,我编了一个Procedure过程,在一个*.pas程序使用时,只需放到*.pas程序的某个地方,就可以多次调用。这样,就可以省去多次重复写代码的麻烦!
现在,我想在整个工程(*.dpr)中也调用这个Procedure过程,也就是说,只需要写一次代码,就可以在整个工程的多个*.pas程序中调用,请问如何实现?
有朋友说,“在其它unit添加上uses unit1;//unit1 里写有Procedure 过程。 就可以调用了。”还有朋友说,“放在public里面啊 默认都可以调用的”,但我试过,都不行。
请懂的朋友提供新的方法,并请尽量写详细一点!

unit Unit1
声明:

interface
procedure suiword;

procedure tform1.suiword;
begin
if dxt='一' then Ln:='1';
if dxt='乙' then Ln:='1';
if dxt='又' then Ln:='2';
if dxt='人' then Ln:='2';
if dxt='口' then Ln:='3';
if dxt='工' then Ln:='3';
if dxt='公' then Ln:='4';
if dxt='孔' then Ln:='4';
end;

unit Unit2;
implementation

{$R *.dfm}
uses Unit1;
procedure TForm1.FormCreate(Sender: TObject);
begin
form1.suiword;
end;

举个例子:
在工程里面新建一个unit,如test2.pas,里面输入以下内容:

unit test2;

interface//公共声明区标志

function ThisPro(i:integer):integer; //在这里声明一下

implementation//私区标志

function ThisPro(i:integer):integer; //在这里写函数具体内容
begin
Result:=i+1;
end;

end.

然后在需要用这个