请问如何声明一个自定义的函数?

解决方案 »

  1.   

    function MyFun(a, b: integer): integer;
    begin
      result:= a + b;
    end;这就是一个计算 a+b的函数
      

  2.   

    function GetExePath: String;function Tmain.GetExePath:String;
    begin
      Result:=ExtractFilePath(ParamStr(0));
      if Result[Length(Result)]<>'\' then
        Result:=Result+'\';
    end;
      

  3.   

    看看 Delphi 的帮助,建议大家在帮助和 CSDN 的搜索中都找不到答案时再来提问,这样自己才能有所进步。需要 interface 段声明,然后到 implementation 段实现。
    在 Delphi 帮助索引中使用 interface 看看它的例子。
      

  4.   

    单击工具菜单里面添加过程
    然后输入涵数名,如涵数名是made
    就会生成如下代码
    Private Function made()
        
    End Function例如:
    Private Function made(aa As Integer)
        aa = Int(8 * Rnd)
        made = aa
    End Function
    是反回0~7的随机数的涵数