Line | |
---|
1 | unit UTimeEdit;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, StdCtrls, DateUtils, Controls, ExtCtrls;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TTimeEdit }
|
---|
13 |
|
---|
14 | TTimeEdit = class(TEdit)
|
---|
15 | private
|
---|
16 | FTime: TTime;
|
---|
17 | procedure SetTime(const AValue: TTime);
|
---|
18 | procedure ChangeExecute(Sender: TObject);
|
---|
19 | public
|
---|
20 | constructor Create(AOwner: TComponent); override;
|
---|
21 | destructor Destroy; override;
|
---|
22 | published
|
---|
23 | property Time: TTime read FTime write SetTime;
|
---|
24 | end;
|
---|
25 |
|
---|
26 | procedure Register;
|
---|
27 |
|
---|
28 | implementation
|
---|
29 |
|
---|
30 | procedure Register;
|
---|
31 | begin
|
---|
32 | RegisterComponents('TEditExtensions', [TTimeEdit]);
|
---|
33 | end;
|
---|
34 |
|
---|
35 | { TTimeEdit }
|
---|
36 |
|
---|
37 | procedure TTimeEdit.ChangeExecute(Sender: TObject);
|
---|
38 | var
|
---|
39 | NewText: string;
|
---|
40 | Temp: TTime;
|
---|
41 | begin
|
---|
42 | NewText := Text;
|
---|
43 | Delete(NewText, SelStart + 1, 1);
|
---|
44 | if TryStrToTime(NewText, Temp) then
|
---|
45 | FTime := Temp;
|
---|
46 | SetTime(FTime);
|
---|
47 | end;
|
---|
48 |
|
---|
49 | procedure TTimeEdit.SetTime(const AValue: TTime);
|
---|
50 | var
|
---|
51 | LastPos: Integer;
|
---|
52 | begin
|
---|
53 | FTime := AValue;
|
---|
54 |
|
---|
55 | LastPos := SelStart;
|
---|
56 | OnChange := nil;
|
---|
57 | Text := TimeToStr(FTime);
|
---|
58 | if HourOf(FTime) < 10 then Text := '0' + Text;
|
---|
59 | OnChange := ChangeExecute;
|
---|
60 | if LastPos = 2 then Inc(LastPos);
|
---|
61 | if LastPos = 5 then Inc(LastPos);
|
---|
62 | SelStart := LastPos;
|
---|
63 | end;
|
---|
64 |
|
---|
65 | constructor TTimeEdit.Create(AOwner: TComponent);
|
---|
66 | begin
|
---|
67 | inherited Create(AOwner);
|
---|
68 | OnChange := ChangeExecute;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | destructor TTimeEdit.Destroy;
|
---|
72 | begin
|
---|
73 | inherited Destroy;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | end.
|
---|
77 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.