请问怎么在delphi中新建一个单元,用来定义并实现自己定义的函数?
比如我新建一个单元unit2
unit Unit2;interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;type
  function test(i:Integer):Integer ;
implementation
function TForm1.test(i: Integer): Integer;
beginend;
end.报错:[Error] Unit2.pas(9): Identifier expected but 'FUNCTION' found
[Error] Unit2.pas(11): Function needs result type
[Error] Unit2.pas(9): Unsatisfied forward or external declaration: 'test'
[Fatal Error] Project1.dpr(6): Could not compile used unit 'Unit2.pas'

解决方案 »

  1.   

    function TForm1.test(i: Integer): Integer;
    beginend;
    改为
    function test(i: Integer): Integer;
    beginend;
      

  2.   

    那在别的单元引用的时候怎么引用呢?我在unit2中建立了,在unit1中使用出错:
    [Error] Unit1.pas(30): Undeclared identifier: 'test'
    [Fatal Error] Project1.dpr(6): Could not compile used unit 'Unit1.pas'
      

  3.   

    这个提示是说你的unit1.pas单元有问题,仅靠这些提示,而又没有unit1.pas的源码,估计除了神仙没人能帮你了