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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
unit UMonComposant;
interface
uses
SysUtils, Classes,DesignEditors,DesignIntf;
Type
TJour=1..7;
Type TJourProperty=class(TIntegerProperty)
public
function GetAttributes: TPropertyAttributes;override;
Function GetValue: String;override;
Procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(Const Value: String);override;
end;
type
TMonComposant = class(TComponent)
private
{ Déclarations privées }
MJour:TJour;
protected
{ Déclarations protégées }
public
{ Déclarations publiques }
Constructor Create(AOwner:TComponent);override;
destructor destroy;override;
published
{ Déclarations publiées }
property Fonction:TJour Read MJour Write MJour;
end;
{Fonction de conversion TJour <-> String.}
Function JourToIdent(Jour: Longint; Var Ident: String): Boolean;
{Fonction de conversion String <-> TJour.}
Function IdentToJour(Const Ident: String; Var Jour: Longint): Boolean;
procedure Register;
implementation
Const
Jours: Array[1..7] Of TIdentMapEntry = (
(Value:1;Name:'Lundi'),
(Value:2;Name:'Mardi'),
(Value:3;Name:'Mercredi'),
(Value:4;Name:'Jeudi'),
(Value:5;Name:'Vendredi'),
(Value:6;Name:'Samedi'),
(Value:7;Name:'Dimanche'));
//*****************************************************************************
//*****************************************************************************
Function JourToIdent(Jour: Longint; Var Ident: String): Boolean;
Begin
Result := IntToIdent(Jour, Ident, Jours);
End;
Function IdentToJour(Const Ident: String; Var Jour: Longint): Boolean;
Begin
Result := IdentToInt(Ident, Jour, Jours);
End;
//*****************************************************************************
//*****************************************************************************
function TJourProperty.GetAttributes;
begin
result := [PaValueList];
end;
Function TJourProperty.GetValue: String;
Begin
If Not JourToIdent(TJour(GetOrdValue), Result) Then Result:=IntToStr(GetOrdValue);
End;
Procedure TJourProperty.GetValues(Proc: TGetStrProc);
Var i:Integer;
Begin
For I := Low(Jours) To High(Jours) Do Proc(Jours[I].Name);
End;
Procedure TJourProperty.SetValue(Const Value: String);
Var
NewValue: Longint;
Begin
If IdentToJour(Value, NewValue) Then
SetOrdValue(NewValue)
Else
Inherited SetValue(Value);
End;
//*****************************************************************************
//*****************************************************************************
constructor TTest.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
end;
destructor TTest.destroy;
begin
inherited Destroy;
end;
//*****************************************************************************
//*****************************************************************************
procedure Register;
begin
RegisterComponents('Perso', [TMonComposant]);
RegisterPropertyEditor(TypeInfo(TJour), Nil, '', TJourProperty);
end;
Initialization
RegisterIntegerConsts(TypeInfo(TJour), IdentToJour, JourToIdent);
end. |
Partager