国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Delphi > 正文

DELPHI8操作符重載的例子

2019-11-18 18:24:59
字體:
供稿:網(wǎng)友

unit WinForm;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data;

type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict PRivate
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    Button1: System.Windows.Forms.Button;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    constructor Create;
  end;

  //寫成類也可以,這里我用了記錄。由于記錄是值類型省去了創(chuàng)建實(shí)例的麻煩
  TClassTest=record
  public
    FA:Integer;
    //重載了“+”操作符
    class Operator add(A,B:TClassTest):TClassTest;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]

implementation

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm.InitializeComponent;
begin
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.SuspendLayout;
  //
  // Button1
  //
  Self.Button1.Location := System.Drawing.Point.Create(96, 88);
  Self.Button1.Name := 'Button1';
  Self.Button1.Size := System.Drawing.Size.Create(392, 112);
  Self.Button1.TabIndex := 0;
  Self.Button1.Text := 'Button1';
  Include(Self.Button1.Click, Self.Button1_Click);
  //
  // TWinForm
  //
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 14);
  Self.ClientSize := System.Drawing.Size.Create(560, 357);
  Self.Controls.Add(Self.Button1);
  Self.Name := 'TWinForm';
  Self.Text := 'WinForm';
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var
  A,B,C:TClassTest;
begin
  A.FA :=1;
  B.FA :=2;
  C:=A+B; //兩個(gè)結(jié)構(gòu)(或者類)用+操作,在DELHI8以前是不可想象的
  system.Windows.Forms.MessageBox.Show(System.Convert.ToString(C.FA) );
end;

{ TClassTest }

//重載“+”操作符的實(shí)現(xiàn)
class operator TClassTest.add(A, B: TClassTest): TClassTest;
begin
  Result.FA:=A.FA + B.FA;
end;

end.


上一篇:Delphi實(shí)現(xiàn)對(duì)注冊(cè)表的監(jiān)視和掃描

下一篇:DELPHI中DBGrid中行的定位及著色實(shí)現(xiàn)

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
學(xué)習(xí)交流
熱門圖片

新聞熱點(diǎn)

疑難解答

圖片精選

網(wǎng)友關(guān)注

主站蜘蛛池模板: 拜城县| 昭通市| 同仁县| 常宁市| 宁远县| 普兰店市| 奉节县| 蓬安县| 壶关县| 沐川县| 紫金县| 云浮市| 安宁市| 阳高县| 新闻| 邛崃市| 许昌市| 太康县| 五大连池市| 松江区| 肃北| 淮滨县| 临城县| 策勒县| 灵宝市| 新丰县| 潢川县| 河池市| 南通市| 靖安县| 千阳县| 北京市| 大名县| 定日县| 合作市| 南陵县| 临朐县| 昌江| 淅川县| 东莞市| 吉首市|