source: trunk/Packages/TEditExtensions/UTimeEdit.pas

Last change on this file was 5, checked in by chronos, 12 years ago
  • Added: Required packages.
File size: 1.4 KB
Line 
1unit UTimeEdit;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, StdCtrls, DateUtils, Controls, ExtCtrls;
9
10type
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
26procedure Register;
27
28implementation
29
30procedure Register;
31begin
32 RegisterComponents('TEditExtensions', [TTimeEdit]);
33end;
34
35{ TTimeEdit }
36
37procedure TTimeEdit.ChangeExecute(Sender: TObject);
38var
39 NewText: string;
40 Temp: TTime;
41begin
42 NewText := Text;
43 Delete(NewText, SelStart + 1, 1);
44 if TryStrToTime(NewText, Temp) then
45 FTime := Temp;
46 SetTime(FTime);
47end;
48
49procedure TTimeEdit.SetTime(const AValue: TTime);
50var
51 LastPos: Integer;
52begin
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;
63end;
64
65constructor TTimeEdit.Create(AOwner: TComponent);
66begin
67 inherited Create(AOwner);
68 OnChange := ChangeExecute;
69end;
70
71destructor TTimeEdit.Destroy;
72begin
73 inherited Destroy;
74end;
75
76end.
77
Note: See TracBrowser for help on using the repository browser.