1 | unit ORDtTm;
|
---|
2 |
|
---|
3 | {$O-}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons,
|
---|
9 | Grids, Calendar, ExtCtrls, ORFn, ORNet, ORDtTmCal, Mask, ComCtrls, ORCtrls;
|
---|
10 |
|
---|
11 | type
|
---|
12 | TORfrmDtTm = class(TForm)
|
---|
13 | bvlFrame: TBevel;
|
---|
14 | lblDate: TPanel;
|
---|
15 | txtTime: TEdit;
|
---|
16 | lstHour: TListBox;
|
---|
17 | lstMinute: TListBox;
|
---|
18 | cmdOK: TButton;
|
---|
19 | cmdCancel: TButton;
|
---|
20 | calSelect: TORCalendar;
|
---|
21 | pnlPrevMonth: TPanel;
|
---|
22 | pnlNextMonth: TPanel;
|
---|
23 | imgPrevMonth: TImage;
|
---|
24 | imgNextMonth: TImage;
|
---|
25 | bvlRButton: TBevel;
|
---|
26 | cmdToday: TButton;
|
---|
27 | cmdNow: TButton;
|
---|
28 | cmdMidnight: TButton;
|
---|
29 | procedure FormCreate(Sender: TObject);
|
---|
30 | procedure calSelectChange(Sender: TObject);
|
---|
31 | procedure cmdTodayClick(Sender: TObject);
|
---|
32 | procedure txtTimeChange(Sender: TObject);
|
---|
33 | procedure lstHourClick(Sender: TObject);
|
---|
34 | procedure lstMinuteClick(Sender: TObject);
|
---|
35 | procedure cmdNowClick(Sender: TObject);
|
---|
36 | procedure cmdOKClick(Sender: TObject);
|
---|
37 | procedure cmdCancelClick(Sender: TObject);
|
---|
38 | procedure imgPrevMonthClick(Sender: TObject);
|
---|
39 | procedure imgNextMonthClick(Sender: TObject);
|
---|
40 | procedure imgPrevMonthMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
41 | Shift: TShiftState; X, Y: Integer);
|
---|
42 | procedure imgNextMonthMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
43 | Shift: TShiftState; X, Y: Integer);
|
---|
44 | procedure imgPrevMonthMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
45 | Shift: TShiftState; X, Y: Integer);
|
---|
46 | procedure imgNextMonthMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
47 | Shift: TShiftState; X, Y: Integer);
|
---|
48 | procedure cmdMidnightClick(Sender: TObject);
|
---|
49 | private
|
---|
50 | FFromSelf: Boolean;
|
---|
51 | FNowPressed: Boolean;
|
---|
52 | TimeIsRequired: Boolean;
|
---|
53 | end;
|
---|
54 |
|
---|
55 | { TORDateTimeDlg }
|
---|
56 |
|
---|
57 | TORDateTimeDlg = class(TComponent)
|
---|
58 | private
|
---|
59 | FDateTime: TDateTime;
|
---|
60 | FDateOnly: Boolean;
|
---|
61 | FRequireTime: Boolean;
|
---|
62 | FRelativeTime: string;
|
---|
63 | function GetFMDateTime: TFMDateTime;
|
---|
64 | procedure SetDateOnly(Value: Boolean);
|
---|
65 | procedure SetFMDateTime(Value: TFMDateTime);
|
---|
66 | procedure SetRequireTime(Value: Boolean);
|
---|
67 | public
|
---|
68 | constructor Create(AOwner: TComponent); override;
|
---|
69 | function Execute: Boolean;
|
---|
70 | property RelativeTime: string read FRelativeTime;
|
---|
71 | published
|
---|
72 | property FMDateTime: TFMDateTime read GetFMDateTime write SetFMDateTime;
|
---|
73 | property DateOnly: Boolean read FDateOnly write SetDateOnly;
|
---|
74 | property RequireTime: Boolean read FRequireTime write SetRequireTime;
|
---|
75 | end;
|
---|
76 |
|
---|
77 | { TORDateBox }
|
---|
78 |
|
---|
79 | TORDateEdit = class(TEdit)
|
---|
80 | protected
|
---|
81 | procedure CreateParams(var Params: TCreateParams); override;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | TORDateBox = class(TORDateEdit)
|
---|
85 | private
|
---|
86 | FFMDateTime: TFMDateTime;
|
---|
87 | FDateOnly: Boolean;
|
---|
88 | FRequireTime: Boolean;
|
---|
89 | FButton: TBitBtn;
|
---|
90 | FFormat: string;
|
---|
91 | FTimeIsNow: Boolean;
|
---|
92 | FTemplateField: boolean;
|
---|
93 | FCaption: TStaticText;
|
---|
94 | procedure ButtonClick(Sender: TObject);
|
---|
95 | function GetFMDateTime: TFMDateTime;
|
---|
96 | function GetRelativeTime: string;
|
---|
97 | procedure SetDateOnly(Value: Boolean);
|
---|
98 | procedure SetFMDateTime(Value: TFMDateTime);
|
---|
99 | procedure SetEditRect;
|
---|
100 | procedure SetRequireTime(Value: Boolean);
|
---|
101 | procedure UpdateText;
|
---|
102 | procedure WMSize(var Message: TWMSize); message WM_SIZE;
|
---|
103 | procedure SetTemplateField(const Value: boolean);
|
---|
104 | procedure SetCaption(const Value: string);
|
---|
105 | function GetCaption(): string;
|
---|
106 |
|
---|
107 | protected
|
---|
108 | procedure Change; override;
|
---|
109 | procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
---|
110 | public
|
---|
111 | constructor Create(AOwner: TComponent); override;
|
---|
112 | function IsValid: Boolean;
|
---|
113 | procedure Validate(var ErrMsg: string);
|
---|
114 | property Format: string read FFormat write FFormat;
|
---|
115 | property RelativeTime: string read GetRelativeTime;
|
---|
116 | property TemplateField: boolean read FTemplateField write SetTemplateField;
|
---|
117 | published
|
---|
118 | property FMDateTime: TFMDateTime read GetFMDateTime write SetFMDateTime;
|
---|
119 | property DateOnly: Boolean read FDateOnly write SetDateOnly;
|
---|
120 | property RequireTime: Boolean read FRequireTime write SetRequireTime;
|
---|
121 | property Caption: string read GetCaption write SetCaption;
|
---|
122 | end;
|
---|
123 |
|
---|
124 | TORDateCombo = class(TCustomPanel)
|
---|
125 | private
|
---|
126 | FYearChanging: boolean;
|
---|
127 | FMonthCombo: TORComboBox;
|
---|
128 | FDayCombo: TORComboBox;
|
---|
129 | FYearEdit: TMaskEdit;
|
---|
130 | FYearUD: TUpDown;
|
---|
131 | FCalBtn: TSpeedButton;
|
---|
132 | FIncludeMonth: boolean;
|
---|
133 | FIncludeDay: boolean;
|
---|
134 | FIncludeBtn: boolean;
|
---|
135 | FLongMonths: boolean;
|
---|
136 | FMonth: integer;
|
---|
137 | FDay: integer;
|
---|
138 | FYear: integer;
|
---|
139 | FCtrlsCreated: boolean;
|
---|
140 | FOnChange: TNotifyEvent;
|
---|
141 | FRebuilding: boolean;
|
---|
142 | FTemplateField: boolean;
|
---|
143 | procedure SetIncludeBtn(const Value: boolean);
|
---|
144 | procedure SetIncludeDay(Value: boolean);
|
---|
145 | procedure SetIncludeMonth(const Value: boolean);
|
---|
146 | procedure SetLongMonths(const Value: boolean);
|
---|
147 | procedure SetDay(Value: integer);
|
---|
148 | procedure SetMonth(Value: integer);
|
---|
149 | procedure SetYear(const Value: integer);
|
---|
150 | function GetFMDate: TFMDateTime;
|
---|
151 | procedure SetFMDate(const Value: TFMDateTime);
|
---|
152 | procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
|
---|
153 | procedure SetTemplateField(const Value: boolean);
|
---|
154 | protected
|
---|
155 | procedure Rebuild;
|
---|
156 | function InitDays(GetSize: boolean): integer;
|
---|
157 | function InitMonths(GetSize: boolean): integer;
|
---|
158 | function GetYearSize: integer;
|
---|
159 | procedure DoChange;
|
---|
160 | procedure MonthChanged(Sender: TObject);
|
---|
161 | procedure DayChanged(Sender: TObject);
|
---|
162 | procedure YearChanged(Sender: TObject);
|
---|
163 | procedure BtnClicked(Sender: TObject);
|
---|
164 | procedure YearUDChange(Sender: TObject; var AllowChange: Boolean;
|
---|
165 | NewValue: Smallint; Direction: TUpDownDirection);
|
---|
166 | procedure YearKeyPress(Sender: TObject; var Key: Char);
|
---|
167 | procedure CheckDays;
|
---|
168 | procedure Loaded; override;
|
---|
169 | procedure Paint; override;
|
---|
170 | procedure Resized(Sender: TObject);
|
---|
171 | public
|
---|
172 | constructor Create(AOwner: TComponent); override;
|
---|
173 | destructor Destroy; override;
|
---|
174 | function DateText: string;
|
---|
175 | property TemplateField: boolean read FTemplateField write SetTemplateField;
|
---|
176 | property FMDate: TFMDateTime read GetFMDate write SetFMDate;
|
---|
177 | published
|
---|
178 | function Text: string;
|
---|
179 | property IncludeBtn: boolean read FIncludeBtn write SetIncludeBtn;
|
---|
180 | property IncludeDay: boolean read FIncludeDay write SetIncludeDay;
|
---|
181 | property IncludeMonth: boolean read FIncludeMonth write SetIncludeMonth;
|
---|
182 | property LongMonths: boolean read FLongMonths write SetLongMonths default FALSE;
|
---|
183 | property Month: integer read FMonth write SetMonth;
|
---|
184 | property Day: integer read FDay write SetDay;
|
---|
185 | property Year: integer read FYear write SetYear;
|
---|
186 | property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
---|
187 | property Anchors;
|
---|
188 | property Enabled;
|
---|
189 | property Font;
|
---|
190 | property ParentColor;
|
---|
191 | property ParentFont;
|
---|
192 | property TabOrder;
|
---|
193 | property TabStop;
|
---|
194 | property Visible;
|
---|
195 | end;
|
---|
196 |
|
---|
197 | function IsLeapYear(AYear: Integer): Boolean;
|
---|
198 | function DaysPerMonth(AYear, AMonth: Integer): Integer;
|
---|
199 |
|
---|
200 | procedure Register;
|
---|
201 |
|
---|
202 | implementation
|
---|
203 |
|
---|
204 | {$R *.DFM}
|
---|
205 | {$R ORDtTm}
|
---|
206 |
|
---|
207 | const
|
---|
208 | FMT_DATETIME = 'mmm d,yyyy@hh:nn';
|
---|
209 | FMT_DATEONLY = 'mmm d,yyyy';
|
---|
210 | (*
|
---|
211 | HOURS_AMPM: array[0..23] of string[3] =
|
---|
212 | ('12a',' 1',' 2',' 3',' 4',' 5',' 6',' 7',' 8',' 9','10 ','11 ',
|
---|
213 | '12p',' 1',' 2',' 3',' 4',' 5',' 6',' 7',' 8',' 9','10 ','11 ');
|
---|
214 | HOURS_MIL: array[0..23] of string[2] =
|
---|
215 | ('00','01','02','03','04','05','06','07','08','09','10','11',
|
---|
216 | '12','13','14','15','16','17','18','19','20','21','22','23');
|
---|
217 | *)
|
---|
218 | AdjVertSize = 8;
|
---|
219 | FontHeightText = 'BEFHILMSTVWXZfgjmpqtyk';
|
---|
220 |
|
---|
221 | var
|
---|
222 | uServerToday: TFMDateTime;
|
---|
223 |
|
---|
224 | { Server-dependent functions ---------------------------------------------------------------- }
|
---|
225 |
|
---|
226 | function ActiveBroker: Boolean;
|
---|
227 | begin
|
---|
228 | Result := False;
|
---|
229 | if (RPCBrokerV <> nil) and RPCBrokerV.Connected then Result := True;
|
---|
230 | end;
|
---|
231 |
|
---|
232 | function ServerFMNow: TFMDateTime;
|
---|
233 | begin
|
---|
234 | if ActiveBroker
|
---|
235 | then Result := StrToFloat(sCallV('ORWU DT', ['NOW']))
|
---|
236 | else Result := DateTimeToFMDateTime(Now);
|
---|
237 | end;
|
---|
238 |
|
---|
239 | function ServerNow: TDateTime;
|
---|
240 | begin
|
---|
241 | if ActiveBroker
|
---|
242 | then Result := FMDateTimeToDateTime(ServerFMNow)
|
---|
243 | else Result := Now;
|
---|
244 | end;
|
---|
245 |
|
---|
246 | function ServerToday: TDateTime;
|
---|
247 | begin
|
---|
248 | if uServerToday = 0 then uServerToday := Int(ServerFMNow);
|
---|
249 | Result := FMDateTimeToDateTime(uServerToday);
|
---|
250 | end;
|
---|
251 |
|
---|
252 | (*
|
---|
253 | function ServerFMToday: TFMDateTime; // never referenced in this unit
|
---|
254 | begin
|
---|
255 | if uServerToday = 0 then uServerToday := Int(ServerFMNow);
|
---|
256 | Result := uServerToday;
|
---|
257 | end;
|
---|
258 | *)
|
---|
259 |
|
---|
260 | function ServerParseFMDate(const AString: string): TFMDateTime;
|
---|
261 | begin
|
---|
262 | if ActiveBroker
|
---|
263 | then Result := StrToFloat(sCallV('ORWU DT', [AString, 'TSX']))
|
---|
264 | else Result := 0;
|
---|
265 | end;
|
---|
266 |
|
---|
267 | function RelativeDateTime(ADateTime: TDateTime): string;
|
---|
268 | var
|
---|
269 | Offset: Integer;
|
---|
270 | h,n,s,l: Word;
|
---|
271 | ATime: string;
|
---|
272 | begin
|
---|
273 | Offset := Trunc(Int(ADateTime) - Int(ServerToday));
|
---|
274 | if Offset < 0 then Result := 'T' + IntToStr(Offset)
|
---|
275 | else if Offset = 0 then Result := 'T'
|
---|
276 | else Result := 'T+' + IntToStr(Offset);
|
---|
277 | DecodeTime(ADateTime, h, n, s, l);
|
---|
278 | ATime := Format('@%.2d:%.2d', [h, n]);
|
---|
279 | if ATime <> '@00:00' then Result := Result + ATime;
|
---|
280 | end;
|
---|
281 |
|
---|
282 | { TfrmORDtTm -------------------------------------------------------------------------------- }
|
---|
283 |
|
---|
284 | procedure TORfrmDtTm.FormCreate(Sender: TObject);
|
---|
285 | begin
|
---|
286 | ResizeAnchoredFormToFont(self);
|
---|
287 | //FormStyle := fsStayOnTop;
|
---|
288 | lstHour.TopIndex := 6;
|
---|
289 | FFromSelf := False;
|
---|
290 | calSelectChange(Self);
|
---|
291 | end;
|
---|
292 |
|
---|
293 | procedure TORfrmDtTm.calSelectChange(Sender: TObject);
|
---|
294 | begin
|
---|
295 | lblDate.Caption := FormatDateTime('mmmm d, yyyy', calSelect.CalendarDate);
|
---|
296 | FNowPressed := False;
|
---|
297 | end;
|
---|
298 |
|
---|
299 | procedure TORfrmDtTm.imgPrevMonthMouseDown(Sender: TObject;
|
---|
300 | Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
---|
301 | begin
|
---|
302 | pnlPrevMonth.BevelOuter := bvLowered;
|
---|
303 | end;
|
---|
304 |
|
---|
305 | procedure TORfrmDtTm.imgNextMonthMouseDown(Sender: TObject;
|
---|
306 | Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
---|
307 | begin
|
---|
308 | pnlNextMonth.BevelOuter := bvLowered;
|
---|
309 | end;
|
---|
310 |
|
---|
311 | procedure TORfrmDtTm.imgPrevMonthClick(Sender: TObject);
|
---|
312 | begin
|
---|
313 | calSelect.PrevMonth;
|
---|
314 | end;
|
---|
315 |
|
---|
316 | procedure TORfrmDtTm.imgNextMonthClick(Sender: TObject);
|
---|
317 | begin
|
---|
318 | calSelect.NextMonth;
|
---|
319 | end;
|
---|
320 |
|
---|
321 | procedure TORfrmDtTm.imgPrevMonthMouseUp(Sender: TObject;
|
---|
322 | Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
---|
323 | begin
|
---|
324 | pnlPrevMonth.BevelOuter := bvRaised;
|
---|
325 | end;
|
---|
326 |
|
---|
327 | procedure TORfrmDtTm.imgNextMonthMouseUp(Sender: TObject;
|
---|
328 | Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
---|
329 | begin
|
---|
330 | pnlNextMonth.BevelOuter := bvRaised;
|
---|
331 | end;
|
---|
332 |
|
---|
333 | procedure TORfrmDtTm.cmdTodayClick(Sender: TObject);
|
---|
334 | begin
|
---|
335 | calSelect.CalendarDate := ServerToday;
|
---|
336 | lstHour.ItemIndex := -1;
|
---|
337 | lstMinute.ItemIndex := -1;
|
---|
338 | txtTime.Text := '';
|
---|
339 | end;
|
---|
340 |
|
---|
341 | procedure TORfrmDtTm.txtTimeChange(Sender: TObject);
|
---|
342 | begin
|
---|
343 | if not FFromSelf then
|
---|
344 | begin
|
---|
345 | lstHour.ItemIndex := -1;
|
---|
346 | lstMinute.ItemIndex := -1;
|
---|
347 | end;
|
---|
348 | FNowPressed := False;
|
---|
349 | end;
|
---|
350 |
|
---|
351 | procedure TORfrmDtTm.lstHourClick(Sender: TObject);
|
---|
352 | begin
|
---|
353 | if lstMinute.ItemIndex < 0 then lstMinute.ItemIndex := 0;
|
---|
354 | lstMinuteClick(Self);
|
---|
355 | end;
|
---|
356 |
|
---|
357 | procedure TORfrmDtTm.lstMinuteClick(Sender: TObject);
|
---|
358 | var
|
---|
359 | AnHour, AMinute: Integer;
|
---|
360 | // AmPm: string;
|
---|
361 | begin
|
---|
362 | if lstHour.ItemIndex < 0 then Exit;
|
---|
363 |
|
---|
364 | // if ampm time -
|
---|
365 | //case lstHour.ItemIndex of
|
---|
366 | // 0: AnHour := 12;
|
---|
367 | //1..12: AnHour := lstHour.ItemIndex;
|
---|
368 | //else AnHour := lstHour.ItemIndex - 12;
|
---|
369 | //end;
|
---|
370 | //if lstHour.ItemIndex > 11 then AmPm := 'PM' else AmPm := 'AM';
|
---|
371 |
|
---|
372 | // if military time
|
---|
373 | AnHour := lstHour.ItemIndex;
|
---|
374 |
|
---|
375 | AMinute := lstMinute.ItemIndex * 5;
|
---|
376 | FFromSelf := True;
|
---|
377 | // if ampm time -
|
---|
378 | //txtTime.Text := Format('%d:%.2d ' + AmPm, [AnHour, AMinute]);
|
---|
379 |
|
---|
380 | // if military time
|
---|
381 | txtTime.Text := Format('%.2d:%.2d ', [AnHour, AMinute]);
|
---|
382 |
|
---|
383 | FFromSelf := False;
|
---|
384 | end;
|
---|
385 |
|
---|
386 | procedure TORfrmDtTm.cmdNowClick(Sender: TObject);
|
---|
387 | begin
|
---|
388 | calSelect.CalendarDate := ServerToday;
|
---|
389 | //txtTime.Text := FormatDateTime('h:nn ampm', ServerNow); // if ampm time
|
---|
390 | txtTime.Text := FormatDateTime('hh:nn', ServerNow); // if ampm time
|
---|
391 | FNowPressed := True;
|
---|
392 | end;
|
---|
393 |
|
---|
394 | procedure TORfrmDtTm.cmdMidnightClick(Sender: TObject);
|
---|
395 | begin
|
---|
396 | //txtTime.Text := '11:59 PM'; // if ampm time
|
---|
397 | txtTime.Text := '23:59'; // if military time
|
---|
398 | end;
|
---|
399 |
|
---|
400 | procedure TORfrmDtTm.cmdOKClick(Sender: TObject);
|
---|
401 | var
|
---|
402 | x: string;
|
---|
403 | begin
|
---|
404 | if TimeIsRequired and (Length(txtTime.Text) = 0) then
|
---|
405 | begin
|
---|
406 | InfoBox('An entry for time is required.', 'Missing Time', MB_OK);
|
---|
407 | Exit;
|
---|
408 | end;
|
---|
409 | if Length(txtTime.Text) > 0 then
|
---|
410 | begin
|
---|
411 | x := Trim(txtTime.Text);
|
---|
412 | if (x='00:00') or (x='0:00') or (x='00:00:00') or (x='0:00:00') then x := '00:00:01';
|
---|
413 | StrToTime(x);
|
---|
414 | txtTime.Text := x;
|
---|
415 | end;
|
---|
416 | ModalResult := mrOK;
|
---|
417 | end;
|
---|
418 |
|
---|
419 | procedure TORfrmDtTm.cmdCancelClick(Sender: TObject);
|
---|
420 | begin
|
---|
421 | ModalResult := mrCancel;
|
---|
422 | end;
|
---|
423 |
|
---|
424 | { TORDateTimeDlg }
|
---|
425 |
|
---|
426 | constructor TORDateTimeDlg.Create(AOwner: TComponent);
|
---|
427 | begin
|
---|
428 | inherited Create(AOwner);
|
---|
429 | if not (csDesigning in ComponentState)
|
---|
430 | then FDateTime := ServerToday
|
---|
431 | else FDateTime := SysUtils.Date;
|
---|
432 | end;
|
---|
433 |
|
---|
434 | function TORDateTimeDlg.Execute: Boolean;
|
---|
435 | const
|
---|
436 | HORZ_SPACING = 8;
|
---|
437 | var
|
---|
438 | frmDtTm: TORfrmDtTm;
|
---|
439 | begin
|
---|
440 | frmDtTm := TORfrmDtTm.Create(Application);
|
---|
441 | try
|
---|
442 | with frmDtTm do
|
---|
443 | begin
|
---|
444 | calSelect.CalendarDate := Int(FDateTime);
|
---|
445 | if Frac(FDateTime) > 0
|
---|
446 | //then txtTime.Text := FormatDateTime('h:nn ampm', FDateTime); // if ampm time
|
---|
447 | then txtTime.Text := FormatDateTime('hh:nn', FDateTime); // if military time
|
---|
448 | if RequireTime then TimeIsRequired := True;
|
---|
449 | if DateOnly then
|
---|
450 | begin
|
---|
451 | txtTime.Visible := False;
|
---|
452 | lstHour.Visible := False;
|
---|
453 | lstMinute.Visible := False;
|
---|
454 | cmdNow.Visible := False;
|
---|
455 | cmdMidnight.Visible := False;
|
---|
456 | bvlFrame.Width := bvlFrame.Width - txtTime.Width - HORZ_SPACING;
|
---|
457 | cmdOK.Left := cmdOK.Left - txtTime.Width - HORZ_SPACING;
|
---|
458 | cmdCancel.Left := cmdOK.Left;
|
---|
459 | ClientWidth := ClientWidth - txtTime.Width - HORZ_SPACING;
|
---|
460 | end;
|
---|
461 | Result := (ShowModal = IDOK);
|
---|
462 | if Result then
|
---|
463 | begin
|
---|
464 | FDateTime := Int(calSelect.CalendarDate);
|
---|
465 | if Length(txtTime.Text) > 0 then FDateTime := FDateTime + StrToTime(txtTime.Text);
|
---|
466 | if FNowPressed
|
---|
467 | then FRelativeTime := 'NOW'
|
---|
468 | else FRelativeTime := RelativeDateTime(FDateTime);
|
---|
469 | end;
|
---|
470 | end;
|
---|
471 | finally
|
---|
472 | frmDtTm.Free;
|
---|
473 | end;
|
---|
474 | end;
|
---|
475 |
|
---|
476 | function TORDateTimeDlg.GetFMDateTime: TFMDateTime;
|
---|
477 | begin
|
---|
478 | Result := DateTimeToFMDateTime(FDateTime);
|
---|
479 | end;
|
---|
480 |
|
---|
481 | procedure TORDateTimeDlg.SetDateOnly(Value: Boolean);
|
---|
482 | begin
|
---|
483 | FDateOnly := Value;
|
---|
484 | if FDateOnly then
|
---|
485 | begin
|
---|
486 | FRequireTime := False;
|
---|
487 | FDateTime := Int(FDateTime);
|
---|
488 | end;
|
---|
489 | end;
|
---|
490 |
|
---|
491 | procedure TORDateTimeDlg.SetFMDateTime(Value: TFMDateTime);
|
---|
492 | begin
|
---|
493 | if Value > 0 then FDateTime := FMDateTimeToDateTime(Value);
|
---|
494 | end;
|
---|
495 |
|
---|
496 | procedure TORDateTimeDlg.SetRequireTime(Value: Boolean);
|
---|
497 | begin
|
---|
498 | FRequireTime := Value;
|
---|
499 | if FRequireTime then FDateOnly := False;
|
---|
500 | end;
|
---|
501 |
|
---|
502 | { TORDateEdit ----------------------------------------------------------------------------- }
|
---|
503 |
|
---|
504 | procedure TORDateEdit.CreateParams(var Params: TCreateParams);
|
---|
505 | { sets a one line edit box to multiline style so the editing rectangle can be changed }
|
---|
506 | begin
|
---|
507 | inherited CreateParams(Params);
|
---|
508 | Params.Style := Params.Style or ES_MULTILINE or WS_CLIPCHILDREN;
|
---|
509 | end;
|
---|
510 |
|
---|
511 |
|
---|
512 | { TORDateBox -------------------------------------------------------------------------------- }
|
---|
513 |
|
---|
514 | constructor TORDateBox.Create(AOwner: TComponent);
|
---|
515 | begin
|
---|
516 | inherited Create(AOwner);
|
---|
517 | FButton := TBitBtn.Create(Self);
|
---|
518 | FButton.Parent := Self;
|
---|
519 | FButton.Width := 18;
|
---|
520 | FButton.Height := 17;
|
---|
521 | FButton.OnClick := ButtonClick;
|
---|
522 | FButton.TabStop := False;
|
---|
523 | FButton.Glyph.LoadFromResourceName(hInstance, 'BMP_ELLIPSIS');
|
---|
524 | FButton.Visible := True;
|
---|
525 | FFormat := FMT_DATETIME;
|
---|
526 | end;
|
---|
527 |
|
---|
528 | procedure TORDateBox.WMSize(var Message: TWMSize);
|
---|
529 | var
|
---|
530 | ofs: integer;
|
---|
531 |
|
---|
532 | begin
|
---|
533 | inherited;
|
---|
534 | if assigned(FButton) then
|
---|
535 | begin
|
---|
536 | if BorderStyle = bsNone then
|
---|
537 | ofs := 0
|
---|
538 | else
|
---|
539 | ofs := 4;
|
---|
540 | FButton.SetBounds(Width - FButton.Width - ofs, 0, FButton.Width, Height - ofs);
|
---|
541 | end;
|
---|
542 | SetEditRect;
|
---|
543 | end;
|
---|
544 |
|
---|
545 | procedure TORDateBox.SetTemplateField(const Value: boolean);
|
---|
546 | var
|
---|
547 | Y: integer;
|
---|
548 |
|
---|
549 | begin
|
---|
550 | if(FTemplateField <> Value) then
|
---|
551 | begin
|
---|
552 | FTemplateField := Value;
|
---|
553 | Y := TextHeightByFont(Font.Handle, FontHeightText);
|
---|
554 | if Value then
|
---|
555 | begin
|
---|
556 | FButton.Width := Y+2;
|
---|
557 | Height := Y;
|
---|
558 | BorderStyle := bsNone;
|
---|
559 | end
|
---|
560 | else
|
---|
561 | begin
|
---|
562 | FButton.Width := 18;
|
---|
563 | Height := y + AdjVertSize;
|
---|
564 | BorderStyle := bsSingle;
|
---|
565 | end;
|
---|
566 | end;
|
---|
567 | end;
|
---|
568 |
|
---|
569 | procedure TORDateBox.ButtonClick(Sender: TObject);
|
---|
570 | var
|
---|
571 | DateDialog: TORDateTimeDlg;
|
---|
572 | ParsedDate: TFMDateTime;
|
---|
573 | begin
|
---|
574 | DateDialog := TORDateTimeDlg.Create(Application);
|
---|
575 | if Length(Text) > 0 then
|
---|
576 | begin
|
---|
577 | ParsedDate := ServerParseFMDate(Text);
|
---|
578 | if ParsedDate > -1 then FFMDateTime := ParsedDate else FFMDateTime := 0;
|
---|
579 | end;
|
---|
580 | DateDialog.DateOnly := FDateOnly;
|
---|
581 | DateDialog.FMDateTime := FFMDateTime;
|
---|
582 | DateDialog.RequireTime := FRequireTime;
|
---|
583 | if DateDialog.Execute then
|
---|
584 | begin
|
---|
585 | FFMDateTime := DateDialog.FMDateTime;
|
---|
586 | UpdateText;
|
---|
587 | FTimeIsNow := DateDialog.RelativeTime = 'NOW';
|
---|
588 | end;
|
---|
589 | DateDialog.Free;
|
---|
590 | if Visible and Enabled then //Some events may hide the component
|
---|
591 | SetFocus;
|
---|
592 | end;
|
---|
593 |
|
---|
594 | procedure TORDateBox.Change;
|
---|
595 | begin
|
---|
596 | inherited Change;
|
---|
597 | FTimeIsNow := False;
|
---|
598 | end;
|
---|
599 |
|
---|
600 | procedure TORDateBox.KeyDown(var Key: Word; Shift: TShiftState);
|
---|
601 | begin
|
---|
602 | inherited KeyDown(Key, Shift);
|
---|
603 | if (Key = VK_RETURN) then begin
|
---|
604 | FButton.Click;
|
---|
605 | Key := 0;
|
---|
606 | end;
|
---|
607 | end;
|
---|
608 |
|
---|
609 | function TORDateBox.GetFMDateTime: TFMDateTime;
|
---|
610 | begin
|
---|
611 | Result := 0;
|
---|
612 | if Length(Text) > 0 then Result := ServerParseFMDate(Text);
|
---|
613 | FFMDateTime := Result;
|
---|
614 | end;
|
---|
615 |
|
---|
616 | function TORDateBox.GetRelativeTime: string;
|
---|
617 | begin
|
---|
618 | Result := '';
|
---|
619 | if FTimeIsNow then Result := 'NOW'
|
---|
620 | else if UpperCase(Text) = 'NOW' then Result := 'NOW'
|
---|
621 | else if Length(Text) > 0 then
|
---|
622 | begin
|
---|
623 | FFMDateTime := ServerParseFMDate(Text);
|
---|
624 | if FFMDateTime > 0 then Result := RelativeDateTime(FMDateTimeToDateTime(FFMDateTime));
|
---|
625 | end;
|
---|
626 | end;
|
---|
627 |
|
---|
628 | procedure TORDateBox.SetDateOnly(Value: Boolean);
|
---|
629 | begin
|
---|
630 | FDateOnly := Value;
|
---|
631 | if FDateOnly then
|
---|
632 | begin
|
---|
633 | FRequireTime := False;
|
---|
634 | FFMDateTime := Int(FFMDateTime);
|
---|
635 | if FFormat = FMT_DATETIME then FFormat := FMT_DATEONLY;
|
---|
636 | end;
|
---|
637 | UpdateText;
|
---|
638 | end;
|
---|
639 |
|
---|
640 | procedure TORDateBox.SetFMDateTime(Value: TFMDateTime);
|
---|
641 | begin
|
---|
642 | FFMDateTime := Value;
|
---|
643 | UpdateText;
|
---|
644 | end;
|
---|
645 |
|
---|
646 | procedure TORDateBox.SetRequireTime(Value: Boolean);
|
---|
647 | begin
|
---|
648 | FRequireTime := Value;
|
---|
649 | if FRequireTime then
|
---|
650 | begin
|
---|
651 | if FFormat = FMT_DATEONLY then FFormat := FMT_DATETIME;
|
---|
652 | SetDateOnly(False);
|
---|
653 | end;
|
---|
654 | end;
|
---|
655 |
|
---|
656 | procedure TORDateBox.SetEditRect;
|
---|
657 | { change the edit rectangle to not hide the calendar button - taken from SPIN.PAS sample }
|
---|
658 | var
|
---|
659 | Loc: TRect;
|
---|
660 | begin
|
---|
661 | SendMessage(Handle, EM_GETRECT, 0, LongInt(@Loc));
|
---|
662 | Loc.Bottom := ClientHeight + 1; // +1 is workaround for windows paint bug
|
---|
663 | Loc.Right := FButton.Left - 2;
|
---|
664 | Loc.Top := 0;
|
---|
665 | Loc.Left := 0;
|
---|
666 | SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@Loc));
|
---|
667 | end;
|
---|
668 |
|
---|
669 | procedure TORDateBox.UpdateText;
|
---|
670 | begin
|
---|
671 | if FFMDateTime > 0 then
|
---|
672 | begin
|
---|
673 | if (FFormat =FMT_DATETIME) and (Frac(FFMDateTime) = 0)
|
---|
674 | then Text := FormatFMDateTime(FMT_DATEONLY, FFMDateTime)
|
---|
675 | else Text := FormatFMDateTime(FFormat, FFMDateTime);
|
---|
676 | end;
|
---|
677 | end;
|
---|
678 |
|
---|
679 | procedure TORDateBox.Validate(var ErrMsg: string);
|
---|
680 | begin
|
---|
681 | ErrMsg := '';
|
---|
682 | if Length(Text) > 0 then
|
---|
683 | begin
|
---|
684 | FFMDateTime := ServerParseFMDate(Text);
|
---|
685 | if FFMDateTime <= 0 then Errmsg := 'Invalid Date/Time';
|
---|
686 | if FRequireTime and (Frac(FFMDateTime) = 0) then ErrMsg := 'Time Required';
|
---|
687 | if FDateOnly and (Frac(FFMDateTime) > 0) then ErrMsg := 'Time not Required';
|
---|
688 | end;
|
---|
689 | end;
|
---|
690 |
|
---|
691 | function TORDateBox.IsValid: Boolean;
|
---|
692 | var
|
---|
693 | x: string;
|
---|
694 | begin
|
---|
695 | Validate(x);
|
---|
696 | if Length(x) = 0 then Result := True else Result := False;
|
---|
697 | if Length(Text) = 0 then Result := False;
|
---|
698 | end;
|
---|
699 |
|
---|
700 | procedure TORDateBox.SetCaption(const Value: string);
|
---|
701 | begin
|
---|
702 | if not Assigned(FCaption) then begin
|
---|
703 | FCaption := TStaticText.Create(self);
|
---|
704 | FCaption.AutoSize := False;
|
---|
705 | FCaption.Height := 0;
|
---|
706 | FCaption.Width := 0;
|
---|
707 | FCaption.Visible := True;
|
---|
708 | FCaption.Parent := Parent;
|
---|
709 | FCaption.BringtoFront;
|
---|
710 | end;
|
---|
711 | FCaption.Caption := Value;
|
---|
712 | end;
|
---|
713 |
|
---|
714 | function TORDateBox.GetCaption(): string;
|
---|
715 | begin
|
---|
716 | result := FCaption.Caption;
|
---|
717 | end;
|
---|
718 |
|
---|
719 | function IsLeapYear(AYear: Integer): Boolean;
|
---|
720 | begin
|
---|
721 | Result := (AYear mod 4 = 0) and ((AYear mod 100 <> 0) or (AYear mod 400 = 0));
|
---|
722 | end;
|
---|
723 |
|
---|
724 | function DaysPerMonth(AYear, AMonth: Integer): Integer;
|
---|
725 | const
|
---|
726 | DaysInMonth: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
|
---|
727 |
|
---|
728 | begin
|
---|
729 | if(AYear < 1) or (AMonth < 1) then
|
---|
730 | Result := 0
|
---|
731 | else
|
---|
732 | begin
|
---|
733 | Result := DaysInMonth[AMonth];
|
---|
734 | if (AMonth = 2) and IsLeapYear(AYear) then Inc(Result); { leap-year Feb is special }
|
---|
735 | end;
|
---|
736 | end;
|
---|
737 |
|
---|
738 | { TORDateCombo ------------------------------------------------------------------------- }
|
---|
739 |
|
---|
740 | const
|
---|
741 | ComboBoxAdjSize = 24;
|
---|
742 | EditAdjHorzSize = 8;
|
---|
743 | DateComboCtrlGap = 2;
|
---|
744 | FirstYear = 1800;
|
---|
745 | LastYear = 2200;
|
---|
746 |
|
---|
747 | type
|
---|
748 | TORDateComboEdit = class(TMaskEdit)
|
---|
749 | private
|
---|
750 | FTemplateField: boolean;
|
---|
751 | procedure SetTemplateField(const Value: boolean);
|
---|
752 | protected
|
---|
753 | property TemplateField: boolean read FTemplateField write SetTemplateField;
|
---|
754 | end;
|
---|
755 |
|
---|
756 | { TORDateComboEdit }
|
---|
757 |
|
---|
758 | procedure TORDateComboEdit.SetTemplateField(const Value: boolean);
|
---|
759 | begin
|
---|
760 | if(FTemplateField <> Value) then
|
---|
761 | begin
|
---|
762 | FTemplateField := Value;
|
---|
763 | if Value then
|
---|
764 | BorderStyle := bsNone
|
---|
765 | else
|
---|
766 | BorderStyle := bsSingle;
|
---|
767 | end;
|
---|
768 | end;
|
---|
769 |
|
---|
770 | { TORDateCombo }
|
---|
771 |
|
---|
772 | constructor TORDateCombo.Create(AOwner: TComponent);
|
---|
773 | begin
|
---|
774 | inherited;
|
---|
775 | ControlStyle := ControlStyle - [csSetCaption, csAcceptsControls];
|
---|
776 | BevelOuter := bvNone;
|
---|
777 | FIncludeMonth := TRUE;
|
---|
778 | FIncludeDay := TRUE;
|
---|
779 | FIncludeBtn := TRUE;
|
---|
780 | OnResize := Resized;
|
---|
781 | end;
|
---|
782 |
|
---|
783 | destructor TORDateCombo.Destroy;
|
---|
784 | begin
|
---|
785 | KillObj(@FMonthCombo);
|
---|
786 | KillObj(@FDayCombo);
|
---|
787 | KillObj(@FYearEdit);
|
---|
788 | KillObj(@FYearUD);
|
---|
789 | KillObj(@FCalBtn);
|
---|
790 | inherited;
|
---|
791 | end;
|
---|
792 |
|
---|
793 | function TORDateCombo.GetYearSize: integer;
|
---|
794 | begin
|
---|
795 | Result := TextWidthByFont(Font.Handle, '8888') + EditAdjHorzSize;
|
---|
796 | end;
|
---|
797 |
|
---|
798 | function TORDateCombo.InitDays(GetSize: boolean): integer;
|
---|
799 | var
|
---|
800 | dy: integer;
|
---|
801 |
|
---|
802 | begin
|
---|
803 | Result := 0;
|
---|
804 | if(assigned(FDayCombo)) then
|
---|
805 | begin
|
---|
806 | dy := DaysPerMonth(FYear, FMonth) + 1;
|
---|
807 | while (FDayCombo.Items.Count < dy) do
|
---|
808 | begin
|
---|
809 | if(FDayCombo.Items.Count = 0) then
|
---|
810 | FDayCombo.Items.Add(' ')
|
---|
811 | else
|
---|
812 | FDayCombo.Items.Add(inttostr(FDayCombo.Items.Count));
|
---|
813 | end;
|
---|
814 | while (FDayCombo.Items.Count > dy) do
|
---|
815 | FDayCombo.Items.Delete(FDayCombo.Items.Count-1);
|
---|
816 | if(GetSize) then
|
---|
817 | Result := TextWidthByFont(Font.Handle, '88') + ComboBoxAdjSize;
|
---|
818 | if(FDay > (dy-1)) then
|
---|
819 | SetDay(dy-1);
|
---|
820 | end;
|
---|
821 | end;
|
---|
822 |
|
---|
823 | function TORDateCombo.InitMonths(GetSize: boolean): integer;
|
---|
824 | var
|
---|
825 | i, Size: integer;
|
---|
826 |
|
---|
827 | begin
|
---|
828 | Result := 0;
|
---|
829 | if(assigned(FMonthCombo)) then
|
---|
830 | begin
|
---|
831 | FMonthCombo.Items.Clear;
|
---|
832 | FMonthCombo.Items.Add(' ');
|
---|
833 | for i := 1 to 12 do
|
---|
834 | begin
|
---|
835 | if FLongMonths then
|
---|
836 | FMonthCombo.Items.Add(LongMonthNames[i])
|
---|
837 | else
|
---|
838 | FMonthCombo.Items.Add(ShortMonthNames[i]);
|
---|
839 | if(GetSize) then
|
---|
840 | begin
|
---|
841 | Size := TextWidthByFont(Font.Handle, FMonthCombo.Items[i]);
|
---|
842 | if(Result < Size) then
|
---|
843 | Result := Size;
|
---|
844 | end;
|
---|
845 | end;
|
---|
846 | if(GetSize) then
|
---|
847 | inc(Result, ComboBoxAdjSize);
|
---|
848 | end;
|
---|
849 | end;
|
---|
850 |
|
---|
851 | procedure TORDateCombo.Rebuild;
|
---|
852 | var
|
---|
853 | Wide, X, Y: integer;
|
---|
854 |
|
---|
855 | begin
|
---|
856 | if(not FRebuilding) then
|
---|
857 | begin
|
---|
858 | FRebuilding := TRUE;
|
---|
859 | try
|
---|
860 | ControlStyle := ControlStyle + [csAcceptsControls];
|
---|
861 | try
|
---|
862 | Y := TextHeightByFont(Font.Handle, FontHeightText);
|
---|
863 | if not FTemplateField then
|
---|
864 | inc(Y,AdjVertSize);
|
---|
865 | X := 0;
|
---|
866 | if(FIncludeMonth) then
|
---|
867 | begin
|
---|
868 | if(not assigned(FMonthCombo)) then
|
---|
869 | begin
|
---|
870 | FMonthCombo := TORComboBox.Create(Self);
|
---|
871 | FMonthCombo.Parent := Self;
|
---|
872 | FMonthCombo.Top := 0;
|
---|
873 | FMonthCombo.Left := 0;
|
---|
874 | FMonthCombo.Style := orcsDropDown;
|
---|
875 | FMonthCombo.DropDownCount := 13;
|
---|
876 | FMonthCombo.OnChange := MonthChanged;
|
---|
877 | end;
|
---|
878 | FMonthCombo.Font := Font;
|
---|
879 | FMonthCombo.TemplateField := FTemplateField;
|
---|
880 | Wide := InitMonths(TRUE);
|
---|
881 | FMonthCombo.Width := Wide;
|
---|
882 | FMonthCombo.Height := Y;
|
---|
883 | FMonthCombo.ItemIndex := FMonth;
|
---|
884 | inc(X, Wide + DateComboCtrlGap);
|
---|
885 |
|
---|
886 | if(FIncludeDay) then
|
---|
887 | begin
|
---|
888 | if(not assigned(FDayCombo)) then
|
---|
889 | begin
|
---|
890 | FDayCombo := TORComboBox.Create(Self);
|
---|
891 | FDayCombo.Parent := Self;
|
---|
892 | FDayCombo.Top := 0;
|
---|
893 | FDayCombo.Style := orcsDropDown;
|
---|
894 | FDayCombo.OnChange := DayChanged;
|
---|
895 | FDayCombo.DropDownCount := 11;
|
---|
896 | end;
|
---|
897 | FDayCombo.Font := Font;
|
---|
898 | FDayCombo.TemplateField := FTemplateField;
|
---|
899 | Wide := InitDays(TRUE);
|
---|
900 | FDayCombo.Width := Wide;
|
---|
901 | FDayCombo.Height := Y;
|
---|
902 | FDayCombo.Left := X;
|
---|
903 | FDayCombo.ItemIndex := FDay;
|
---|
904 | inc(X, Wide + DateComboCtrlGap);
|
---|
905 | end
|
---|
906 | else
|
---|
907 | KillObj(@FDayCombo);
|
---|
908 | end
|
---|
909 | else
|
---|
910 | begin
|
---|
911 | KillObj(@FDayCombo);
|
---|
912 | KillObj(@FMonthCombo);
|
---|
913 | end;
|
---|
914 | if(not assigned(FYearEdit)) then
|
---|
915 | begin
|
---|
916 | FYearEdit := TORDateComboEdit.Create(Self);
|
---|
917 | FYearEdit.Parent := Self;
|
---|
918 | FYearEdit.Top := 0;
|
---|
919 | FYearEdit.EditMask := '9999;1; ';
|
---|
920 | FYearEdit.OnKeyPress := YearKeyPress;
|
---|
921 | FYearEdit.OnChange := YearChanged;
|
---|
922 | end;
|
---|
923 | FYearEdit.Font := Font;
|
---|
924 | TORDateComboEdit(FYearEdit).TemplateField := FTemplateField;
|
---|
925 | Wide := GetYearSize;
|
---|
926 | FYearEdit.Width := Wide;
|
---|
927 | FYearEdit.Height := Y;
|
---|
928 | FYearEdit.Left := X;
|
---|
929 | inc(X, Wide);
|
---|
930 | if(not assigned(FYearUD)) then
|
---|
931 | begin
|
---|
932 | FYearUD := TUpDown.Create(Self);
|
---|
933 | FYearUD.Parent := Self;
|
---|
934 | FYearUD.Thousands := FALSE;
|
---|
935 | FYearUD.Min := FirstYear-1;
|
---|
936 | FYearUD.Max := LastYear;
|
---|
937 | FYearUD.OnChangingEx := YearUDChange;
|
---|
938 | end;
|
---|
939 | FYearEdit.TabOrder := 0;
|
---|
940 | FYearUD.Top := 0;
|
---|
941 | FYearUD.Left := X;
|
---|
942 | FYearUD.Height := Y;
|
---|
943 | FYearUD.Position := FYear;
|
---|
944 | inc(X, FYearUD.Width + DateComboCtrlGap);
|
---|
945 | if(FIncludeBtn) then
|
---|
946 | begin
|
---|
947 | if(not assigned(FCalBtn)) then
|
---|
948 | begin
|
---|
949 | FCalBtn := TSpeedButton.Create(Self);
|
---|
950 | FCalBtn.Parent := Self;
|
---|
951 | FCalBtn.Top := 0;
|
---|
952 | FCalBtn.Glyph.LoadFromResourceName(hInstance, 'BMP_ELLIPSIS');
|
---|
953 | FCalBtn.OnClick := BtnClicked;
|
---|
954 | end;
|
---|
955 | Wide := FYearEdit.Height;
|
---|
956 | if(Wide > Y) then Wide := Y;
|
---|
957 | FCalBtn.Width := Wide;
|
---|
958 | FCalBtn.Height := Wide;
|
---|
959 | FCalBtn.Left := X;
|
---|
960 | inc(X, Wide + DateComboCtrlGap);
|
---|
961 | end
|
---|
962 | else
|
---|
963 | KillObj(@FCalBtn);
|
---|
964 | Self.Width := X - DateComboCtrlGap;
|
---|
965 | Self.Height := Y;
|
---|
966 | CheckDays;
|
---|
967 | FCtrlsCreated := TRUE;
|
---|
968 | DoChange;
|
---|
969 | finally
|
---|
970 | ControlStyle := ControlStyle - [csAcceptsControls];
|
---|
971 | end;
|
---|
972 | finally
|
---|
973 | FRebuilding := FALSE;
|
---|
974 | end;
|
---|
975 | end;
|
---|
976 | end;
|
---|
977 |
|
---|
978 | procedure TORDateCombo.SetDay(Value: integer);
|
---|
979 | begin
|
---|
980 | if(not assigned(FDayCombo)) and (not (csLoading in ComponentState)) then
|
---|
981 | Value := 0;
|
---|
982 | if(Value > DaysPerMonth(FYear, FMonth)) then
|
---|
983 | Value := 0;
|
---|
984 | if(FDay <> Value) then
|
---|
985 | begin
|
---|
986 | FDay := Value;
|
---|
987 | if(assigned(FDayCombo)) then
|
---|
988 | begin
|
---|
989 | if(FDayCombo.Items.Count <= FDay) then
|
---|
990 | InitDays(FALSE);
|
---|
991 | FDayCombo.ItemIndex := FDay;
|
---|
992 | end;
|
---|
993 | DoChange;
|
---|
994 | end;
|
---|
995 | end;
|
---|
996 |
|
---|
997 | procedure TORDateCombo.SetIncludeBtn(const Value: boolean);
|
---|
998 | begin
|
---|
999 | if(FIncludeBtn <> Value) then
|
---|
1000 | begin
|
---|
1001 | FIncludeBtn := Value;
|
---|
1002 | Rebuild;
|
---|
1003 | end;
|
---|
1004 | end;
|
---|
1005 |
|
---|
1006 | procedure TORDateCombo.SetIncludeDay(Value: boolean);
|
---|
1007 | begin
|
---|
1008 | if(Value) and (not FIncludeMonth) then
|
---|
1009 | Value := FALSE;
|
---|
1010 | if(FIncludeDay <> Value) then
|
---|
1011 | begin
|
---|
1012 | FIncludeDay := Value;
|
---|
1013 | if(not Value) then FDay := 0;
|
---|
1014 | Rebuild;
|
---|
1015 | end;
|
---|
1016 | end;
|
---|
1017 |
|
---|
1018 | procedure TORDateCombo.SetIncludeMonth(const Value: boolean);
|
---|
1019 | begin
|
---|
1020 | if(FIncludeMonth <> Value) then
|
---|
1021 | begin
|
---|
1022 | FIncludeMonth := Value;
|
---|
1023 | if(not Value) then
|
---|
1024 | begin
|
---|
1025 | FIncludeDay := FALSE;
|
---|
1026 | FMonth := 0;
|
---|
1027 | FDay := 0;
|
---|
1028 | end;
|
---|
1029 | Rebuild;
|
---|
1030 | end;
|
---|
1031 | end;
|
---|
1032 |
|
---|
1033 | procedure TORDateCombo.SetMonth(Value: integer);
|
---|
1034 | begin
|
---|
1035 | if(not assigned(FMonthCombo)) and (not (csLoading in ComponentState)) then
|
---|
1036 | Value := 0;
|
---|
1037 | if(Value <0) or (Value > 12) then
|
---|
1038 | Value := 0;
|
---|
1039 | if(FMonth <> Value) then
|
---|
1040 | begin
|
---|
1041 | FMonth := Value;
|
---|
1042 | if(assigned(FMonthCombo)) then
|
---|
1043 | FMonthCombo.ItemIndex := FMonth;
|
---|
1044 | CheckDays;
|
---|
1045 | DoChange;
|
---|
1046 | end;
|
---|
1047 | end;
|
---|
1048 |
|
---|
1049 | procedure TORDateCombo.SetLongMonths(const Value: boolean);
|
---|
1050 | begin
|
---|
1051 | if(FLongMonths <> Value) then
|
---|
1052 | begin
|
---|
1053 | FLongMonths := Value;
|
---|
1054 | Rebuild;
|
---|
1055 | end;
|
---|
1056 | end;
|
---|
1057 |
|
---|
1058 | procedure TORDateCombo.SetYear(const Value: integer);
|
---|
1059 | begin
|
---|
1060 | if(FYear <> Value) then
|
---|
1061 | begin
|
---|
1062 | FYear := Value;
|
---|
1063 | if(FYear < FirstYear) or (FYear > LastYear) then
|
---|
1064 | FYear := 0;
|
---|
1065 | if(not FYearChanging) and (assigned(FYearEdit)) and (assigned(FYearUD)) then
|
---|
1066 | begin
|
---|
1067 | FYearChanging := TRUE;
|
---|
1068 | try
|
---|
1069 | if(FYear = 0) then
|
---|
1070 | begin
|
---|
1071 | FYearEdit.Text := ' ';
|
---|
1072 | FYearUD.Position := FirstYear-1
|
---|
1073 | end
|
---|
1074 | else
|
---|
1075 | begin
|
---|
1076 | FYearEdit.Text := IntToStr(FYear);
|
---|
1077 | FYearUD.Position := FYear;
|
---|
1078 | end;
|
---|
1079 | finally
|
---|
1080 | FYearChanging := FALSE;
|
---|
1081 | end;
|
---|
1082 | end;
|
---|
1083 | if(FMonth = 2) then
|
---|
1084 | InitDays(FALSE);
|
---|
1085 | CheckDays;
|
---|
1086 | DoChange;
|
---|
1087 | end;
|
---|
1088 | end;
|
---|
1089 |
|
---|
1090 | procedure TORDateCombo.DayChanged(Sender: TObject);
|
---|
1091 | begin
|
---|
1092 | FDay := FDayCombo.ItemIndex;
|
---|
1093 | if(FDay < 0) then
|
---|
1094 | FDay := 0;
|
---|
1095 | CheckDays;
|
---|
1096 | DoChange;
|
---|
1097 | end;
|
---|
1098 |
|
---|
1099 | procedure TORDateCombo.MonthChanged(Sender: TObject);
|
---|
1100 | begin
|
---|
1101 | FMonth := FMonthCombo.ItemIndex;
|
---|
1102 | if(FMonth < 0) then
|
---|
1103 | FMonth := 0;
|
---|
1104 | InitDays(FALSE);
|
---|
1105 | CheckDays;
|
---|
1106 | DoChange;
|
---|
1107 | end;
|
---|
1108 |
|
---|
1109 | procedure TORDateCombo.YearChanged(Sender: TObject);
|
---|
1110 | begin
|
---|
1111 | if FYearChanging then exit;
|
---|
1112 | FYearChanging := TRUE;
|
---|
1113 | try
|
---|
1114 | FYear := StrToIntDef(FYearEdit.Text, 0);
|
---|
1115 | if(FYear < FirstYear) or (FYear > LastYear) then
|
---|
1116 | FYear := 0;
|
---|
1117 | if(FYear = 0) then
|
---|
1118 | FYearUD.Position := FirstYear-1
|
---|
1119 | else
|
---|
1120 | FYearUD.Position := FYear;
|
---|
1121 | if(FMonth = 2) then
|
---|
1122 | InitDays(FALSE);
|
---|
1123 | CheckDays;
|
---|
1124 | DoChange;
|
---|
1125 | finally
|
---|
1126 | FYearChanging := FALSE;
|
---|
1127 | end;
|
---|
1128 | end;
|
---|
1129 |
|
---|
1130 | procedure TORDateCombo.CheckDays;
|
---|
1131 | var
|
---|
1132 | MaxDays: integer;
|
---|
1133 |
|
---|
1134 | begin
|
---|
1135 | if(FIncludeMonth and assigned(FMonthCombo)) then
|
---|
1136 | begin
|
---|
1137 | FMonthCombo.Enabled := (FYear > 0);
|
---|
1138 | if (FYear = 0) then
|
---|
1139 | SetMonth(0);
|
---|
1140 | if(FIncludeMonth and FIncludeDay and assigned(FDayCombo)) then
|
---|
1141 | begin
|
---|
1142 | FDayCombo.Enabled := ((FYear > 0) and (FMonth > 0));
|
---|
1143 | MaxDays := DaysPerMonth(FYear, FMonth);
|
---|
1144 | if(FDay > MaxDays) then
|
---|
1145 | SetDay(MaxDays);
|
---|
1146 | end;
|
---|
1147 | end;
|
---|
1148 | end;
|
---|
1149 |
|
---|
1150 | procedure TORDateCombo.Loaded;
|
---|
1151 | begin
|
---|
1152 | inherited;
|
---|
1153 | if(not FCtrlsCreated) then
|
---|
1154 | Rebuild;
|
---|
1155 | end;
|
---|
1156 |
|
---|
1157 | procedure TORDateCombo.Paint;
|
---|
1158 | begin
|
---|
1159 | if(not FCtrlsCreated) then
|
---|
1160 | Rebuild;
|
---|
1161 | inherited;
|
---|
1162 | end;
|
---|
1163 |
|
---|
1164 | procedure TORDateCombo.BtnClicked(Sender: TObject);
|
---|
1165 | var
|
---|
1166 | mm, dd, yy: integer;
|
---|
1167 | m, d, y: word;
|
---|
1168 | DateDialog: TORDateTimeDlg;
|
---|
1169 |
|
---|
1170 | begin
|
---|
1171 | DateDialog := TORDateTimeDlg.Create(self);
|
---|
1172 | try
|
---|
1173 | mm := FMonth;
|
---|
1174 | dd := FDay;
|
---|
1175 | yy := FYear;
|
---|
1176 | DecodeDate(Now, y, m, d);
|
---|
1177 | if(FYear = 0) then FYear := y;
|
---|
1178 | if(FYear = y) then
|
---|
1179 | begin
|
---|
1180 | if((FMonth = 0) or (FMonth = m)) and (FDay = 0) then
|
---|
1181 | begin
|
---|
1182 | FMonth := m;
|
---|
1183 | FDay := d;
|
---|
1184 | end;
|
---|
1185 | end;
|
---|
1186 | if(FMonth = 0) then
|
---|
1187 | FMonth := 1;
|
---|
1188 | if(FDay = 0) then
|
---|
1189 | FDay := 1;
|
---|
1190 | DateDialog.FMDateTime := GetFMDate;
|
---|
1191 | DateDialog.DateOnly := TRUE;
|
---|
1192 | DateDialog.RequireTime := FALSE;
|
---|
1193 | if DateDialog.Execute then
|
---|
1194 | begin
|
---|
1195 | FYear := 0;
|
---|
1196 | FMonth := 0;
|
---|
1197 | FDay := 0;
|
---|
1198 | SetFMDate(DateDialog.FMDateTime);
|
---|
1199 | end
|
---|
1200 | else
|
---|
1201 | begin
|
---|
1202 | SetYear(yy);
|
---|
1203 | SetMonth(mm);
|
---|
1204 | SetDay(dd);
|
---|
1205 | end;
|
---|
1206 | finally
|
---|
1207 | DateDialog.Free;
|
---|
1208 | end;
|
---|
1209 | end;
|
---|
1210 |
|
---|
1211 | procedure TORDateCombo.YearUDChange(Sender: TObject; var AllowChange: Boolean;
|
---|
1212 | NewValue: Smallint; Direction: TUpDownDirection);
|
---|
1213 | var
|
---|
1214 | y, m, d: word;
|
---|
1215 |
|
---|
1216 | begin
|
---|
1217 | if FYearChanging then exit;
|
---|
1218 | FYearChanging := TRUE;
|
---|
1219 | try
|
---|
1220 | if FYearUD.Position = (FirstYear-1) then
|
---|
1221 | begin
|
---|
1222 | DecodeDate(Now, y, m, d);
|
---|
1223 | FYear := y;
|
---|
1224 | FYearUD.Position := y;
|
---|
1225 | AllowChange := FALSE;
|
---|
1226 | end
|
---|
1227 | else
|
---|
1228 | FYear := NewValue;
|
---|
1229 | if(FYear < FirstYear) or (FYear > LastYear) then
|
---|
1230 | FYear := 0;
|
---|
1231 | if(FYear = 0) then
|
---|
1232 | FYearEdit.Text := ' '
|
---|
1233 | else
|
---|
1234 | FYearEdit.Text := IntToStr(FYear);
|
---|
1235 | if(FMonth = 2) then
|
---|
1236 | InitDays(FALSE);
|
---|
1237 | CheckDays;
|
---|
1238 | DoChange;
|
---|
1239 | finally
|
---|
1240 | FYearChanging := FALSE;
|
---|
1241 | end;
|
---|
1242 | end;
|
---|
1243 |
|
---|
1244 | procedure TORDateCombo.YearKeyPress(Sender: TObject; var Key: Char);
|
---|
1245 | begin
|
---|
1246 | if(Key in ['0'..'9']) and (FYearEdit.Text = ' ') then
|
---|
1247 | begin
|
---|
1248 | FYearEdit.Text := Key + ' ';
|
---|
1249 | Key := #0;
|
---|
1250 | FYearEdit.SelStart := 1;
|
---|
1251 | FYearEdit.SelText := '';
|
---|
1252 | end;
|
---|
1253 | end;
|
---|
1254 |
|
---|
1255 | function TORDateCombo.GetFMDate: TFMDateTime;
|
---|
1256 | begin
|
---|
1257 | if(FYear < FirstYear) then
|
---|
1258 | Result := 0
|
---|
1259 | else
|
---|
1260 | Result := ((FYear - 1700) * 10000 + FMonth * 100 + FDay);
|
---|
1261 | end;
|
---|
1262 |
|
---|
1263 | procedure TORDateCombo.SetFMDate(const Value: TFMDateTime);
|
---|
1264 | var
|
---|
1265 | ival, mo, dy: integer;
|
---|
1266 |
|
---|
1267 | begin
|
---|
1268 | if(Value = 0) then
|
---|
1269 | begin
|
---|
1270 | SetYear(0);
|
---|
1271 | SetMonth(0);
|
---|
1272 | end
|
---|
1273 | else
|
---|
1274 | begin
|
---|
1275 | ival := trunc(Value);
|
---|
1276 | if(length(inttostr(ival)) <> 7) then
|
---|
1277 | exit;
|
---|
1278 | dy := (ival mod 100);
|
---|
1279 | ival := ival div 100;
|
---|
1280 | mo := ival mod 100;
|
---|
1281 | ival := ival div 100;
|
---|
1282 | SetYear(ival + 1700);
|
---|
1283 | SetMonth(mo);
|
---|
1284 | InitDays(FALSE);
|
---|
1285 | SetDay(dy);
|
---|
1286 | end;
|
---|
1287 | end;
|
---|
1288 |
|
---|
1289 | function TORDateCombo.DateText: string;
|
---|
1290 | begin
|
---|
1291 | Result := '';
|
---|
1292 | if(FYear > 0) then
|
---|
1293 | begin
|
---|
1294 | if(FMonth > 0) then
|
---|
1295 | begin
|
---|
1296 | if FLongMonths then
|
---|
1297 | Result := LongMonthNames[FMonth]
|
---|
1298 | else
|
---|
1299 | Result := ShortMonthNames[FMonth];
|
---|
1300 | if(FDay > 0) then
|
---|
1301 | Result := Result + ' ' + IntToStr(FDay);
|
---|
1302 | Result := Result + ', ';
|
---|
1303 | end;
|
---|
1304 | Result := Result + IntToStr(FYear);
|
---|
1305 | end;
|
---|
1306 | end;
|
---|
1307 |
|
---|
1308 | procedure TORDateCombo.DoChange;
|
---|
1309 | begin
|
---|
1310 | if assigned(FOnChange) then
|
---|
1311 | FOnChange(Self);
|
---|
1312 | end;
|
---|
1313 |
|
---|
1314 | procedure TORDateCombo.Resized(Sender: TObject);
|
---|
1315 | begin
|
---|
1316 | Rebuild;
|
---|
1317 | end;
|
---|
1318 |
|
---|
1319 | procedure TORDateCombo.CMFontChanged(var Message: TMessage);
|
---|
1320 | begin
|
---|
1321 | inherited;
|
---|
1322 | Rebuild;
|
---|
1323 | end;
|
---|
1324 |
|
---|
1325 | function TORDateCombo.Text: string;
|
---|
1326 | var
|
---|
1327 | tmp, fmt, m: string;
|
---|
1328 |
|
---|
1329 | begin
|
---|
1330 | Result := '';
|
---|
1331 | tmp := FloatToStr(FMDate);
|
---|
1332 | if(tmp <> '') and (tmp <> '0') and (length(Tmp) >= 7) then
|
---|
1333 | begin
|
---|
1334 | if FLongMonths then
|
---|
1335 | m := 'mmmm'
|
---|
1336 | else
|
---|
1337 | m := 'mmm';
|
---|
1338 | if(copy(tmp,4,4) = '0000') then
|
---|
1339 | fmt := 'yyyy'
|
---|
1340 | else
|
---|
1341 | if(copy(tmp,6,2) = '00') then
|
---|
1342 | fmt := m + ', YYYY'
|
---|
1343 | else
|
---|
1344 | fmt := m + ' D, YYYY';
|
---|
1345 | Result := FormatFMDateTimeStr(fmt, tmp)
|
---|
1346 | end;
|
---|
1347 | end;
|
---|
1348 |
|
---|
1349 |
|
---|
1350 | procedure Register;
|
---|
1351 | { used by Delphi to put components on the Palette }
|
---|
1352 | begin
|
---|
1353 | RegisterComponents('CPRS', [TORDateTimeDlg, TORDateBox, TORDateCombo]);
|
---|
1354 | end;
|
---|
1355 |
|
---|
1356 | procedure TORDateCombo.SetTemplateField(const Value: boolean);
|
---|
1357 | begin
|
---|
1358 | if FTemplateField <> Value then
|
---|
1359 | begin
|
---|
1360 | FTemplateField := Value;
|
---|
1361 | Rebuild;
|
---|
1362 | end;
|
---|
1363 | end;
|
---|
1364 |
|
---|
1365 | initialization
|
---|
1366 | uServerToday := 0;
|
---|
1367 |
|
---|
1368 | end.
|
---|