Example of Delphi8 operator overload

zhaozj2021-02-08  216

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 ///

/// Required designer variable /// Components:. System.ComponentModel. Container; Button1: System.Windows.Forms.Button; /// /// Required Method for Designer Support - do not modifi //////// procedure InitializeComponent; procedure Button1_Click (sender: System.Object; e: System.EventArgs); {$ eNDREGION} strict protected /// /// Clean up any resources being used /// procedure Dispose. (Disposing: boolean); OVERRIDE; Private {private deflarations} public constructor crete;

// Write into a class can also be used, here I have used records. Since the record is a value type, the trouble Tclasstest = Record Public Fa: Integer; // Heavy loaded " " operator Class Operator Add (A, B: TCLASSTEST): TCLASSTEST; END;

[Assembly: RuntimeRequidattribute (Typeof (TwinForm)]]]

IMPLEMENTATION

{$ Region 'Windows Form Designer Generated Code'} ///

/// Required Method for Designer Support - Do Not Modify /// The contents of this method with the code editor./// 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 the beginningnesss.dispose (); DISPOSE (); End; inherited dispose

CONSTRUCTOR TWINFORM.CREATE; begin inherited create; // // Required for windows form design; /// 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; / / Two structures (or class) use operation, before delhi8 is an unimaginable system.windows.Forms.MessageBox.show (System.Convert.TOString (C.fa));

{Tclasstest}

// Reute the " " operator implementation Class Operator Tclasstest.Add (A, B: Tclasstest): Tclasstest; Begin Result.fa: = A.FA B.FA; End;

转载请注明原文地址:https://www.9cbs.com/read-2876.html

New Post(0)