-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmComboBox.pas
145 lines (120 loc) · 3.06 KB
/
mComboBox.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
unit mComboBox;
interface
uses
SysUtils, Classes, Controls, StdCtrls,
Windows, Messages, TypInfo,
mKeyValue;
type
TmComboBox = class(TComboBox)
private
FLabel : TObject;
FEntidade : TCollectionItem;
FCampo : String;
FMover : Boolean;
FLista : TmKeyValueList;
procedure ClrLista;
procedure AddLista(const Value: TmKeyValue);
procedure SetLista(const Value: TmKeyValueList);
function GetValue: TmKeyValue;
procedure SetValue(const Value: TmKeyValue);
protected
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure KeyPress(var Key: Char); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
public
constructor create(AOwner: TComponent); overload; override;
constructor create(AOwner : TComponent; AParent : TWinControl); overload;
procedure SetListaArray(const Value: Array Of TmKeyValue);
published
property _Label : TObject read FLabel write FLabel;
property _Entidade : TCollectionItem read FEntidade write FEntidade;
property _Campo : String read FCampo write FCampo;
property _Lista : TmKeyValueList read FLista write SetLista;
property _Mover : Boolean read FMover write FMover;
property _Value : TmKeyValue read GetValue write SetValue;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Comps MIGUEL', [TmComboBox]);
end;
{ TmComboBox }
constructor TmComboBox.create(AOwner: TComponent);
begin
inherited;
Style := csDropDownList;
BevelKind := bkFlat;
Sorted := True;
FLista := TmKeyValueList.Create;
Font.Size := 16;
end;
constructor TmComboBox.create(AOwner: TComponent; AParent : TWinControl);
begin
create(AOwner);
Parent := AParent;
end;
//--
procedure TmComboBox.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 TmComboBox.KeyPress(var Key: Char);
begin
//
end;
procedure TmComboBox.KeyDown(var Key: Word; Shift: TShiftState);
begin
//Por motivo de a tecla F4 é padrão para consulta
//Nesse caso não abrir o DROPDWON
if (Key = VK_F4) then
Key := 0;
//
end;
//--
procedure TmComboBox.ClrLista;
begin
FLista.Clear;
Items.Clear;
end;
procedure TmComboBox.AddLista(const Value: TmKeyValue);
begin
FLista.Add(Value);
Items.AddObject(Value.Display, Value);
end;
//--
procedure TmComboBox.SetLista(const Value: TmKeyValueList);
var
I : Integer;
begin
ClrLista;
with FLista do
for I := 0 to Count - 1 do
AddLista(Items[I]);
end;
procedure TmComboBox.SetListaArray(const Value: Array Of TmKeyValue);
var
I : Integer;
begin
ClrLista;
with FLista do
for I := 0 to High(Value) do
AddLista(Value[I]);
end;
//--
function TmComboBox.GetValue: TmKeyValue;
begin
Result := FLista.Items[ItemIndex];
end;
procedure TmComboBox.SetValue(const Value: TmKeyValue);
begin
ItemIndex := FLista.IndexOf(Value);
end;
end.