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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
//=====================================
//Unit:utEditproto.pas definition du Helper "TCustomEditHelper "
//=====================================
....
type
TCustomEditHelper = class helper for TCustomEdit
public
//Setters/Getters
procedure tedit_set_displayformat(vval:TProtoDisplayFormat);
function tedit_get_displayformat:TProtoDisplayFormat;
procedure tedit_set_decimalesplaces(vval:integer);
function tedit_get_decimalesplaces:integer;
procedure tedit_set_DisplaySuffix(vval:string);
function tedit_get_displaySuffix:string;
procedure tedit_set_DisplayPrefix(vval:string);
function tedit_get_displayPrefix:string;
function tedit_get_HasMinValue:boolean;
function tedit_get_HasMaxValue:boolean;
function tedit_get_MinValue:double;
function tedit_get_MaxValue:double;
function tedit_get_AllowEmpty:boolean;
function tedit_get_color:longint;
procedure tedit_set_color(vval:longint);
//Autres fonctions
procedure Clear;
function CurrRangeValue(CheckValue: Currency): Currency;
function FloatRangeValue(CheckValue: Double): Double;
function IntRangeValue(CheckValue: Int64): Int64;
function BcdRangeValue(const CheckValue: TBcd): TBcd;
function BaseToInt(const BaseValue: string; Base: Byte): Int64;
function IntToBase(NewValue: Int64; Base: Byte): string;
procedure SetAsFloat(NewValue: Double);
procedure SetAsInteger(NewValue: Int64);
procedure SetAsBcd(const NewValue: TBcd);
procedure SetValue(NewValue: Variant);
function GetValue: Variant;
//Properties
published
property DisplayFormat:TProtoDisplayFormat read tedit_get_displayformat write tedit_set_displayformat;
property DecimalPlaces:integer read tedit_get_decimalesplaces write tedit_set_decimalesplaces;
property DisplaySuffix:string read tedit_get_displaySuffix write tedit_set_DisplaySuffix;
property Displayprefix:string read tedit_get_displayprefix write tedit_set_Displayprefix;
property Color:longint read tedit_get_color write tedit_set_color;
property Value: Variant read GetValue write SetValue stored False;
end;
....
procedure TCustomEditHelper.tedit_set_displayformat(vval:TProtoDisplayFormat);
var VStyleObject:TFmxObject;vvalstr:string;
begin
ApplyStyleLookup; // without this, FindStyleResource will return nil
VStyleObject := FindStyleResource('proto_displayformat');
if (VStyleObject <> nil)
then begin
vvalstr:=TProtoDisplayFormat_convert_str(vval);
if vvalstr=''
then raise exception.create('tedit_set_displayformat:ERR vvalstr=''')
else TstyleTextObject(VStyleObject).text:=vvalstr;
end
else raise exception.create('tedit_set_displayformat:ERR '+TProtoDisplayFormat_convert_str(vval))
end;
function TCustomEditHelper.tedit_get_displayformat:TProtoDisplayFormat;
var VStyleObject:TFmxObject;vvalstr:string;
inObjFMX:TFmxObject;
VStyleObjectparent:TFmxObject;
begin
result:=dfNone;
//NeedStyleLookup;
ApplyStyleLookup; // without this, FindStyleResource will return nil
VStyleObject := FindStyleResource('proto_displayformat');
if (VStyleObject <> nil)
then begin
vvalstr :=TstyleTextObject(VStyleObject).text;
if vvalstr=''
then raise exception.create('tedit_get_displayformat:ERR tedit="'+name+'" vvalstr=''')
else result :=TProtoDisplayFormat_convertstr_enum(vvalstr);
end
else raise exception.create('tedit_get_displayformat:ERR lecture property')
end;
....
=================================
//Frame prototype de toute frame
//=====================================
type
Tfrm_proto = class(TFrame)
...
procedure Tfrm_proto._TeditInit_DisplayFormat(VtControl:tControl;VTVarData:word;VnbDecimalesouuppercase:integer);
var VTEdit:Tedit;Vvalcharcase:system.uitypes.TEditcharcase;
begin
if VtControl<>nil then
begin
if VtControl is Tedit then
begin
case VTVarData of
varInteger:begin
//Tjvvalidateedit(VtControl).DisplayFormat:=dfInteger
Tedit(VtControl).DisplayFormat:=dfFloat;
Tedit(VtControl).DecimalPlaces:=0; //pour separateur de milliers uniqyement en dfFloat
Tedit(VtControl).Textsettings.HorzAlign := TTextAlign.Trailing;
Tedit(VtControl).Keyboardtype :=TVirtualKeyboardType.NumberPad;
//Tedit(VtControl).text:='0'; //init valeur NON sinon Teditchange declenche et fonction de ctrlsaisie
end;
varDouble:begin
Tedit(VtControl).DisplayFormat:=dfFloat;
Tedit(VtControl).DecimalPlaces:=VnbDecimalesouuppercase;
Tedit(VtControl).Textsettings.HorzAlign := TTextAlign.Trailing;
if VnbDecimalesouuppercase=0
then Tedit(VtControl).Keyboardtype :=TVirtualKeyboardType.NumberPad
else Tedit(VtControl).Keyboardtype :=TVirtualKeyboardType.DecimalNumberPad;
//Tedit(VtControl).text:='0'; //init valeur NON sinon Teditchange declenche et fonction de ctrlsaisie
end;
varString:begin
Tedit(VtControl).DisplayFormat:=dfAlphaNumeric; //Sans Blanc
Vvalcharcase:=TEditcharcase(VnbDecimalesouuppercase);
case Vvalcharcase of
TEditcharcase.ecLowerCase:Tedit(VtControl).charcase:=Vvalcharcase;
TEditcharcase.ecUpperCase:Tedit(VtControl).charcase:=Vvalcharcase;
end;
Tedit(VtControl).Keyboardtype :=TVirtualKeyboardType.Default;
//Tedit(VtControl).text:=''; //init valeur NON sinon Teditchange declenche et fonction de ctrlsaisie
end;
varEmpty:begin
Tedit(VtControl).DisplayFormat:=dfnone;//avec saisie blanc possible dfAlphaNumeric;
Vvalcharcase:=TEditcharcase(VnbDecimalesouuppercase);
case Vvalcharcase of
TEditcharcase.ecLowerCase:Tedit(VtControl).charcase:=Vvalcharcase;
TEditcharcase.ecUpperCase:Tedit(VtControl).charcase:=Vvalcharcase;
end;
Tedit(VtControl).Keyboardtype :=TVirtualKeyboardType.Default;
//Tedit(VtControl).text:=''; //init valeur NON sinon Teditchange declenche et fonction de ctrlsaisie
end;
else
Tedit(VtControl).DisplayFormat:=dfnone
end;
end;
end;
end;
//Init d'un TEdit: Uniquement type Tjvvalidateedit
//Vdata :array= 0:VDisplaySuffix 1:VTVarData 2:VnbDecimales
procedure Tfrm_proto._TeditInit_Display(VtControl:tControl;VData:TabVar;Venabled:boolean);
var VTEdit:Tedit;
begin
if VtControl<>nil then
begin
if length(VData)>0 //VDisplaySuffix
then _TeditInit_DisplaySuffix(VtControl,VData[0]);
//_TeditInit_DisplayFormat
case length(VData) of
2: _TeditInit_DisplayFormat(VtControl,VData[1],0);
3: _TeditInit_DisplayFormat(VtControl,VData[1],VData[2]);
end;
{
if length(VData)>2 //VTVarData,VnbDecimales
then _TeditInit_DisplayFormat(VtControl,VData[1],VData[2]);
}
//...
_TcontrolSet_Enabled(VtControl,Venabled);
end;
end;
//=====================================
//Frame appelante:
//=====================================
type
Tfrm_renveloppe = class(Tfrm_proto)
...
//--------------------------------------------------------------------------
//Initialisation d'un tedit "ed_renveloppe_Surf" de type double,1 decimale
//--------------------------------------------------------------------------
//ed_renveloppe_Surf
_TeditInit_Display(ed_renveloppe_Surf,['',vardouble,1]);
...
//--------------------------------------------------------------------------
//Lecture valeur du Tedit "ed_renveloppe_Surf":
//--------------------------------------------------------------------------
var Vval:double;
Vval:=ed_renveloppe_Surf.value;
//--------------------------------------------------------------------------
//Ecriture valeur du Tedit "ed_renveloppe_Surf":
//--------------------------------------------------------------------------
var Vval:double;
ed_renveloppe_Surf.value:=Vval; |
Partager