函数要怎么调用呀?各位说说吧

解决方案 »

  1.   

    一个意义不大不过完全合乎你的需求的例子
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure GetMessage(MIndex:integer);
        function GetIndex(num:integer):integer;  end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.GetMessage(MIndex:integer);
    begin
      case MIndex of
        10: ShowMessage('the 10 message!');
        20: ShowMessage('the 20 message!');
      else
            ShowMessage('The wrong message!');
      end;
    end;
    function TForm1.GetIndex(num:integer):integer;
    begin
      case num of
      1: Result := 10;
      2: Result := 20;
      else
         Result := 30; 
      end;end;procedure TForm1.Button1Click(Sender: TObject);
    var
      FIndex:integer;
    begin
      FIndex := GetIndex(1);
      GetMessage(FIndex);
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      FIndex:integer;
    begin
      FIndex := GetIndex(2);
      GetMessage(FIndex);end;procedure TForm1.Button3Click(Sender: TObject);
    var
      FIndex:integer;
    begin
      FIndex := GetIndex(3);
      GetMessage(FIndex);end;end.