-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmTextBox.pas
297 lines (247 loc) · 7.29 KB
/
mTextBox.pas
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
unit mTextBox;
interface
uses
SysUtils, Classes, Controls, StdCtrls, DB, Graphics, TypInfo, Messages, Forms,
Windows, StrUtils, mTipoFormato, mFormatar, mValidar, mValue, mTipoTecla;
type
TmTextBox = class(TEdit)
private
FAlignment : TAlignment;
FLabel : TObject;
FColorEnter : TColor;
FColorExit : TColor;
FEntidade : TCollectionItem;
FCampo : String;
FMover : Boolean;
FTipo : TTipoValue;
FFormato : TTipoFormato;
procedure Validar();
procedure CMChanged(var Message: TMessage); message CM_CHANGED;
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure SetAlignment(const Value: TAlignment);
procedure SetFormato(const Value: TTipoFormato);
procedure PosicaoLabel();
function GetValue: String;
procedure SetValue(const Value: String);
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure KeyPress(var Key: Char); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
public
constructor create(AOwner : TComponent); overload; override;
constructor create(AOwner : TComponent; AParent : TWinControl); reintroduce; overload;
published
property _Alignment : TAlignment Read FAlignment Write SetAlignment Default taLeftJustify;
property _Label : TObject read FLabel write FLabel;
property _ColorEnter : TColor read FColorEnter write FColorEnter;
property _ColorExit : TColor read FColorExit write FColorExit;
property _Entidade : TCollectionItem read FEntidade write FEntidade;
property _Campo : String read FCampo write FCampo;
property _Value : String read GetValue write SetValue;
property _Mover : Boolean read FMover write FMover;
property _Tipo : TTipoValue read FTipo write FTipo;
property _Formato : TTipoFormato read FFormato write SetFormato;
end;
procedure Register;
implementation
uses
mData, mFloat, mString;
procedure Register;
begin
RegisterComponents('Comps MIGUEL', [TmTextBox]);
end;
{ TmTextBox }
constructor TmTextBox.create(AOwner: TComponent);
begin
inherited;
FColorEnter := clYellow;
FColorExit := clWhite;
FFormato := TTipoFormato(Ord(-1));
AutoSize := False;
Width := 129;
Height := 24;
BorderStyle := bsNone;
Font.Size := 16;
Text := ' ';
end;
constructor TmTextBox.create(AOwner: TComponent; AParent : TWinControl);
begin
create(AOwner);
Parent := AParent;
end;
//--
procedure TmTextBox.Validar();
begin
if (Text = '') then
Exit;
case FFormato of
tfCnpj:
if not TmValidar.Cnpj(Text) then
raise Exception.Create('CNPJ invalido');
tfCpf:
if not TmValidar.Cpf(Text) then
raise Exception.Create('CPF invalido');
tfInscricao:
if not TmValidar.Inscricao(Text) then
raise Exception.Create('Inscricao invalida');
tfData, tfDataHora:
if TmData.GetDataHora(Text) = 0 then
raise Exception.Create('Data invalida');
tfNumero:
if TmFloat.GetNumero(Text) = 0 then
raise Exception.Create('Numero invalido');
tfPercentual, tfQuantidade, tfValor:
if TmFloat.GetValor(Text) = 0 then
raise Exception.Create('Valor invalido');
end;
end;
//--
procedure TmTextBox.CMChanged(var Message: TMessage);
begin
if Parent <> nil then
Parent.WindowProc(Message);
end;
procedure TmTextBox.CMEnter(var Message: TCMEnter);
begin
if TabStop and not ReadOnly then
Color := FColorEnter;
if SysLocale.MiddleEast then
if UseRightToLeftReading then begin
if Application.BiDiKeyboard <> '' then
LoadKeyboardLayout(PChar(Application.BiDiKeyboard), KLF_ACTIVATE);
end else
if Application.NonBiDiKeyboard <> '' then
LoadKeyboardLayout(PChar(Application.NonBiDiKeyboard), KLF_ACTIVATE);
SelectAll;
DoEnter;
end;
procedure TmTextBox.CMExit(var Message: TCMExit);
begin
if TabStop and not ReadOnly then
Color := FColorExit;
if (Text = '') then
Exit;
try
Validar();
case FFormato of
tfDataHora:
Text := DateTimeToStr(TmData.GetDataHora(Text));
tfNumero:
Text := FloatToStr(TmFloat.GetNumero(Text));
tfPercentual, tfQuantidade, tfValor:
Text := FloatToStr(TmFloat.GetValor(Text));
end;
except
on E : Exception do begin
Text := '';
SetFocus;
raise;
end;
end;
DoExit;
end;
procedure TmTextBox.KeyPress(var Key: Char);
var
vLstTecla : Set Of Char;
begin
vLstTecla := [];
case FFormato of
tfEmail:
vLstTecla := TmTipoTecla.GetLstEmail;
tfSenha:
vLstTecla := TmTipoTecla.GetLstSenha;
tfSite:
vLstTecla := TmTipoTecla.GetLstSite;
tfDataHora:
vLstTecla := TmTipoTecla.GetLstData;
tfNumero:
vLstTecla := TmTipoTecla.GetLstInteiro;
tfPercentual, tfQuantidade, tfValor:
vLstTecla := TmTipoTecla.GetLstNumero;
tfDescricao, tfNome:
vLstTecla := TmTipoTecla.GetLstTexto;
end;
if vLstTecla <> [] then
if not (Key in vLstTecla) then
Key := #0;
//DoKeyPress;
end;
procedure TmTextBox.SetValue(const Value: String);
begin
Text := Value;
if (Text = '') then
Exit;
case FFormato of
tfCnpj, tfCpf, tfInscricao:
Text := TmFormatar.Conteudo(FFormato, Value, '');
tfDataHora:
Text := FormatDateTime(TipoFormatoToFmt(FFormato), TmData.GetDataHora(Value));
tfNumero:
Text := FormatFloat(TipoFormatoToFmt(FFormato), TmFloat.GetNumero(Value));
tfPercentual, tfQuantidade, tfValor:
Text := FormatFloat(TipoFormatoToFmt(FFormato), TmFloat.GetValor(Value));
tfDescricao, tfNome:
Text := TmString.AllTrim(Value);
end;
end;
function TmTextBox.GetValue(): String;
begin
Result := Text;
if (Result = '') then
Exit;
case FFormato of
tfCnpj, tfCpf, tfInscricao:
Result := TmFormatar.Remover(Text);
tfDataHora:
Result := FormatDateTime(TipoFormatoToFmt(FFormato), TmData.GetDataHora(Text));
tfNumero:
Result := FormatFloat(TipoFormatoToFmt(FFormato), TmFloat.GetNumero(Text));
tfPercentual, tfQuantidade, tfValor:
Result := FormatFloat(TipoFormatoToFmt(FFormato), TmFloat.GetValor(Text));
tfDescricao, tfNome:
Result := TmString.AllTrim(Text);
end;
end;
procedure TmTextBox.SetAlignment(const Value: TAlignment);
begin
if FAlignment <> Value then begin
FAlignment := Value;
if Handle <> 0 then
Perform(CM_RECREATEWND, 0, 0);
end;
end;
procedure TmTextBox.SetFormato(const Value: TTipoFormato);
begin
FFormato := Value;
case FFormato of
tfDataHora:
_Alignment := taCenter;
tfNumero, tfPercentual, tfQuantidade, tfValor:
_Alignment := taRightJustify;
tfDescricao, tfNome:
_Alignment := taLeftJustify;
end;
end;
procedure TmTextBox.CreateParams(var Params: TCreateParams);
const
Alignments: Array[TAlignment] of Cardinal = (ES_LEFT, ES_RIGHT, ES_CENTER);
begin
inherited CreateParams(Params);
Params.Style := Params.Style and (not 0) or (Alignments[FAlignment]);
end;
procedure TmTextBox.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
SC_MOVE = $F012;
begin
inherited MouseDown(Button, Shift, X, Y);
if not _Mover then
Exit;
ReleaseCapture;
Self.Perform(WM_SYSCOMMAND, SC_MOVE, 0);
PosicaoLabel();
end;
procedure TmTextBox.PosicaoLabel();
begin
end;
end.