zoukankan      html  css  js  c++  java
  • 类方法(method)的声明和使用

     1type
     2  TMan = class(TObject)
     3  public
     4    procedure sleep(TheHour: Integer);
     5    // Public declarations
     6  end;
     7type
     8  TForm1 = class(TForm)
     9    Button1: TButton;
    10    procedure Button1Click(Sender: TObject);
    11  private
    12    { Private declarations }
    13  public
    14    { Public declarations }
    15  end;
    16
    17implementation
    18
    19
    20{ type
    21  TMan = class(TObject)
    22  public
    23    procedure sleep(TheHour: Integer);
    24    // Public declarations
    25  end;
    26PROCEDURE TMan.sleep(TheHour: Integer); //在 implementation里也可以声明类 TMan }
    27PROCEDURE TMan.sleep(TheHour: Integer); // 在 interface里声明类 TMan
    28BEGIN
    29   CASE TheHour OF    //
    30     0..5: ShowMessage('不睡觉干嘛?') ;
    31     6..8: ShowMessage('还是想睡!') ;
    32     9..12: ShowMessage('无奈一天已过了一半' + #13 + '起来好了!') ;
    33     13..20: ShowMessage('呒,你是小@#') ;
    34     21..24: ShowMessage('你和树袋熊是同宗的哦??') ;
    35   else
    36      ShowMessage('一天只有24小时吧??');
    37   END;    // case
    38END;
    39procedure TForm1.Button1Click(Sender: TObject);
    40VAR
    41  Stime: TMan;
    42  i: Integer;
    43begin
    44  i := StrToInt( InputBox('一天睡事知多少<>','输入每天睡眠时数','8'));
    45  Stime := TMan.Create;
    46  Stime.sleep(i);
    47  Stime.Free;
    48end;
    49
    50
  • 相关阅读:
    PAT乙级1002. 写出这个数 (20)
    PAT乙级1001. 害死人不偿命的(3n+1)猜想 (15)
    HDU 4520 小Q系列故事——最佳裁判
    POJ 3414 Pots(BFS)
    POJ 1118 Lining Up
    POJ 2484 A Funny Game
    POJ 2231 Moo Volume
    HDU 5718 Oracle(高精度)
    FZU 1502 Letter Deletion(DP)
    HDU 1564 Play a game
  • 原文地址:https://www.cnblogs.com/dreamszx/p/1572019.html
Copyright © 2011-2022 走看看