unit Unit1; {$mode objfpc}{$H+} {$modeswitch typehelpers}
interface
uses Classes, StdCtrls, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
type TIntegerHelper = type helper for Integer
function Str: string; end;
type BUA = ( buaKauf, buaVkf, buaBewert, buaReal );
TBuchArtHelper = type helper for BUA
function Int( AEnum : BUA ): Integer;
function Str( AEnum : BUA ): String;
function Val( AEnum : BUA ): Integer;
end;
type { TForm1 } TForm1 = class( TForm)
Button1 : TButton;
Button2 : TButton;
procedure Button1Click( Sender : TObject) ;
procedure Button2Click( Sender : TObject) ;
private
public
end;
var Form1 : TForm1;
implementation {$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click( Sender : TObject) ;
var
intval: LongInt = 33;
begin
ShowMessage( intval.Str );
ShowMessage( ( intval * 3).Str );
end;
procedure TForm1.Button2Click( Sender : TObject);
var itest : Integer = 3;
begin
if BUA.Int( buaReal ) = itest then begin { some Code } end;
ShowMessage( BUA.Str( buaReal ) );
end;
{ TIntegerHelper }
function TIntegerHelper.Str: string;
begin
Result := IntToStr(Self);
end;
function TBuchArtHelper.Int( AEnum : BUA ): Integer;
begin
Result := ord( AEnum );
end;
function TBuchArtHelper.Str( AEnum : BUA ): String;
const description : Array[0..3] of String = ( 'Wertpapier-Kauf', 'Wertpapier-Verkauf', 'Werpapier-Bewertung', 'Wp-Real.Gewinne' );
begin Result := description[ord( AEnum )]; end;
function TBuchArtHelper.Val( AEnum : BUA ): Integer;
const ColumnWidth : Array[0..3] of Integer = ( 120, 120, 80, 80 );
begin Result := ColumnWidth[ord( AEnum )]; end;
end.