1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| type
TEdit = class(StdCtrls.TEdit)
function Equals(Obj: TObject): Boolean; override;
end;
// ceci ne fonctionne pas
//TEditHelper = class helper for TEdit
//public
//class operator EQUAL(a: TEdit; b: TEdit): boolean;
//end;
// par contre ceci oui
TCompareEdit = record
Data: TEdit;
public
class operator Implicit(a: TEdit): TCompareEdit;
class operator Equal(a: TCompareEdit; b: TCompareEdit): Boolean;
end;
TForm27 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form27: TForm27;
implementation
{$R *.dfm}
{ TEdit }
function TEdit.Equals(Obj: TObject): Boolean;
begin
Result := False;
if Obj is TEdit then
Result := Text = TEdit(Obj).Text;
end;
{ TCompareEdit }
class operator TCompareEdit.Implicit(a: TEdit): TCompareEdit;
begin
Result.Data := a;
end;
class operator TCompareEdit.Equal(a: TCompareEdit; b: TCompareEdit): Boolean;
begin
Result := a.Data.Text = b.Data.Text;
end;
procedure TForm27.Button1Click(Sender: TObject);
begin
if TCompareEdit(Edit1) = TCompareEdit(Edit2) then
MessageBox(Handle, 'Identiques', 'TCompareEdit(Edit1) = TCompareEdit(Edit2)', MB_OK)
else
MessageBox(Handle, 'Différents', 'TCompareEdit(Edit1) = TCompareEdit(Edit2)', MB_OK);
if Edit1.Equals(Edit2) then
MessageBox(Handle, 'Identiques', 'Edit1.Equals(Edit2)', MB_OK)
else
MessageBox(Handle, 'Différents', 'Edit1.Equals(Edit2)', MB_OK);
if Edit1 = Edit2 then
MessageBox(Handle, 'Identiques', 'Edit1 = Edit2', MB_OK)
else
MessageBox(Handle, 'Différents', 'Edit1 = Edit2', MB_OK);
end;
end. |
Partager