zoukankan      html  css  js  c++  java
  • Delphi学习(三)——面向对象

    1、新建单元,代码如下
    unit Models;

    interface
        uses Windows, SysUtils, Messages,Dialogs;

    type
        Tstudent = class(TObject)    //创建类
        public
            sno : string;
            sname:string;
            Ssex : string;
            SAge : string;
            procedure SayHelloBy(name:string);
            function SayHelloByF(name:string): string;
        end;
    implementation

    procedure Tstudent.SayHelloBy(name:string);
    begin
        showmessage('234'+sname);
    end;

    function Tstudent.SayHelloByF(name:string):string;
    begin
        Result:=name;
    end;
    end.

    窗体button Click事件如下
    uses
        Models;

    {$R *.dfm}

    procedure TForm1.btn1Click(Sender: TObject);
    var
        student : Tstudent;
    begin

    实例化类
        student := Tstudent.Create;
        student.sname :='rxy';
        student.SayHelloBy('12');

        student.Free;//撤销类Free或Destroy

    end;

  • 相关阅读:
    codevs 3049 舞蹈家怀特先生
    洛谷P2530 [SHOI2001]化工厂装箱员
    洛谷P2736 “破锣摇滚”乐队 Raucous Rockers
    Phalanx
    Treats for the Cows
    Very Simple Problem
    Alice and Bob
    FatMouse and Cheese
    Tickets
    Piggy-Bank
  • 原文地址:https://www.cnblogs.com/rongxiaoya/p/2787748.html
Copyright © 2011-2022 走看看