View Issue Details

IDProjectCategoryView StatusLast Update
0001485JEDI VCL00 JVCL Componentspublic2004-03-16 23:23
ReporteranonymousAssigned Touser72 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0001485: TJvDateTimePicker and Delphi 5
DescriptionTJvDateTimePicker supports the nice concept of a NullDate displayed with a special NullText. Unfortunately, under Delphi 5, if the NullDate is ever selected the NullText will continue to be displayed even if subsequently a non-Null date is selected. This is because the CheckNullValue routine uses an IFDEF to exclude the code which resets the control to the formal Format.

I see three options here. 1) Exclude NullDate and NullText from the Delphi 5 control, 2) change CheckNullValue so that it resets the format to an empty string when given a non-Null date (this resets the control to the default, at least on my system), or 3) add the Format property to the Delphi 5 control.

I'm attaching a patch to do option 3. It has hardly been tested: it works on my Windows XP system, but who knows what different comctrl dlls might do. I haven't seen the Delphi 6 or 7 source, so I don't know if this is what Borland does.
Additional InformationI also added a setter proc for NullText. Previously, Changing NullText when a NullDate was selected would not update the control; now it will.
TagsNo tags attached.

Activities

2004-03-16 17:28

 

JvDateTimePicker.pas.diff (3,444 bytes)
--- JvDateTimePicker.pas.orig	2004-03-08 09:48:30.000000000 -0800
+++ JvDateTimePicker.pas	2004-03-16 17:23:40.000000000 -0800
@@ -47,41 +47,49 @@
   JvExComCtrls;
 
 type
   {$IFDEF BCB}
   TDate = TDateTime;
   {$ENDIF BCB}
 
   TJvDateTimePicker = class(TJvExDateTimePicker)
   private
     FNullText: string;
     FNullDate: TDateTime;
     FDropDownDate: TDate;
+{$IFNDEF COMPILER6_UP}
+    FFormat: string;
+    procedure SetFormat(const Value: string);
+{$ENDIF}
     procedure CNNotify(var Msg: TWMNotify); message CN_NOTIFY;
     procedure SetNullDate(const Value: TDateTime);
+    procedure SetNullText(const Value: string);
   protected
     function WithinDelta(Val1, Val2: TDateTime): Boolean; virtual;
     // returns True if NullDate matches Date or Frac(NullDate) matches Frac(Time) depending on Kind
     function CheckNullValue: Boolean; virtual;
     procedure Change; override;
     function MsgSetDateTime(Value: TSystemTime): Boolean; override;
   public
     constructor Create(AOwner: TComponent); override;
   published
     // The initial date to display when the drop-down calendar is shown and NullDate = Date/Time
     property DropDownDate: TDate read FDropDownDate write FDropDownDate;
+{$IFNDEF COMPILER6_UP}
+    property Format: string read FFormat write SetFormat;
+{$ENDIF}
     // The Date/Time (depending on the Kind property) that represents an empty "null" value, default is 1899-12-31
     property NullDate: TDateTime read FNullDate write SetNullDate;
     // The text to display when NullDate = Date/Time
-    property NullText: string read FNullText write FNullText;
+    property NullText: string read FNullText write SetNullText;
     property HintColor;
     property OnMouseEnter;
     property OnMouseLeave;
     property OnParentColorChange;
   end;
 
 implementation
 
 uses
   JvJVCLUtils, JvResources;
 
 constructor TJvDateTimePicker.Create(AOwner: TComponent);
@@ -100,37 +108,52 @@
 
 function TJvDateTimePicker.CheckNullValue: Boolean;
 begin
  // Warren added NullText length check so that this feature can be disabled if not used!
    if Length(NullText)=0 then begin
         result := false;
    end else
        Result := ((Kind = dtkDate) and (Trunc(DateTime) = Trunc(NullDate)) or
     ((Kind = dtkTime) and WithinDelta(DateTime, NullDate)));
    
   if Result then
     SendMessage(Handle, DTM_SETFORMAT, 0, Integer(PChar(FNullText)))
-  {$IFDEF COMPILER6_UP}
-  // (p3) the Format property doesn't exist in D5: what to do?
   else
     SendMessage(Handle, DTM_SETFORMAT, 0, Integer(PChar(Format)));
-  {$ENDIF COMPILER6_UP}
 end;
 
 procedure TJvDateTimePicker.SetNullDate(const Value: TDateTime);
 begin
   FNullDate := Trunc(Value);
   CheckNullValue;
 end;
 
+procedure TJvDateTimePicker.SetNullText(const Value: string);
+begin
+  if FNullText <> Value then begin
+    FNullText:= Value;
+    CheckNullValue;
+  end;
+end;
+
+{$IFNDEF COMPILER6_UP}
+procedure TJvDateTimePicker.SetFormat(const Value: string);
+begin
+  if FFormat <> Value then begin
+    FFormat:= Value;
+    CheckNullValue;
+  end;
+end;
+{$ENDIF}
+
 function TJvDateTimePicker.MsgSetDateTime(Value: TSystemTime): Boolean;
 begin
   Result := inherited MsgSetDateTime(Value);
   CheckNullValue;
 end;
 
 procedure TJvDateTimePicker.Change;
 begin
   inherited Change;
   CheckNullValue;
 end;
 

anonymous

2004-03-16 17:29

viewer   ~0003357

> the formal Format.

Oops, that should be: the normal Format.

user72

2004-03-16 23:23

  ~0003359

Looks nice, should work. Updated in CVS. Thanks!

Issue History

Date Modified Username Field Change
2004-03-16 17:28 anonymous New Issue
2004-03-16 17:28 anonymous File Added: JvDateTimePicker.pas.diff
2004-03-16 17:29 anonymous Note Added: 0003357
2004-03-16 23:23 user72 Status new => resolved
2004-03-16 23:23 user72 Resolution open => fixed
2004-03-16 23:23 user72 Assigned To => user72
2004-03-16 23:23 user72 Note Added: 0003359