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