added TDateTime property to TCalendar

git-svn-id: trunk@5070 -
This commit is contained in:
mattias 2004-01-16 19:04:57 +00:00
parent a4d158b4db
commit 4e4d1726c8
2 changed files with 43 additions and 18 deletions

View File

@ -1194,8 +1194,7 @@ const
type
TDummyClassForPropTypes = class (TPersistent)
private
FDate: TDateProperty;
FDateTime: TDateTimePropertyEditor;
FDateTime: TDateTime;
FList:PPropList;
FCount:integer;
FComponent:TComponent;
@ -1207,7 +1206,6 @@ type
FLines:TStrings;
FColumns: TListColumns;
FModalResult:TModalResult;
FTime: TTimePropertyEditor;
public
function PTypeInfos(const PropName:shortstring):PTypeInfo;
constructor Create;
@ -1223,9 +1221,7 @@ type
property Columns:TListColumns read FColumns;
property ModalResult:TModalResult read FModalResult;
property ShortCut: TShortCut read FShortCut;
property Date: TDateProperty read FDate;
property Time: TTimePropertyEditor read FTime;
property DateTime: TDateTimePropertyEditor read FDateTime;
property DateTime: TDateTime read FDateTime;
end;
//==============================================================================
@ -3746,16 +3742,20 @@ var
DT: TDateTime;
begin
DT := TDateTime(GetFloatValue);
if DT = 0.0 then Result := '' else
Result := DateToStr(DT);
if DT = 0.0 then
Result := ''
else
Result := DateToStr(DT);
end;
procedure TDateProperty.SetValue(const Value: string);
var
DT: TDateTime;
begin
if Value = '' then DT := 0.0
else DT := StrToDate(Value);
if Value = '' then
DT := 0.0
else
DT := StrToDate(Value);
SetFloatValue(DT);
end;
@ -5243,7 +5243,7 @@ begin
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TTime'),
nil,'',TShortCutPropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TDateTime'),
nil,'',TShortCutPropertyEditor);
nil,'',TDateTimePropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TCursor'),
nil,'',TCursorPropertyEditor);
RegisterPropertyEditor(ClassTypeInfo(TComponent),nil

View File

@ -60,7 +60,9 @@ Type
FMonthChanged: TNotifyEvent;
FYearChanged: TNotifyEvent;
FPropsChanged: boolean;
function GetDateTime: TDateTime;
function ReadOnlyIsStored: boolean;
procedure SetDateTime(const AValue: TDateTime);
procedure SetReadOnly(const AValue: Boolean);
Procedure GetProps;
Procedure SetProps;
@ -79,7 +81,8 @@ Type
procedure InitializeWnd; override;
procedure AddControl; override;
published
Property Date: String read GetDate write SetDate;
Property Date: String read GetDate write SetDate stored false;
Property DateTime: TDateTime read GetDateTime write SetDateTime;
property DisplaySettings : TDisplaySettings read GetDisplaySettings write SetDisplaySettings;
property ReadOnly : Boolean read FReadOnly write SetReadOnly stored ReadOnlyIsStored;
property Visible;
@ -149,7 +152,7 @@ begin
if FDateAsString=AValue then exit;
try
{$IFDEF VerboseCalenderSetDate}
writeln('TCalendar.SetDate AValue=',AValue,' FDateAsString=',FDateAsString,' FDate=',FDate,' ShortDateFormat=',ShortDateFormat);
writeln('TCalendar.SetDate A AValue=',AValue,' FDateAsString=',FDateAsString,' FDate=',FDate,' ShortDateFormat=',ShortDateFormat);
{$ENDIF}
NewDate:=StrToDate(AValue); //test to see if date valid ....
// no exception => set valid date
@ -187,15 +190,37 @@ begin
Result:=FReadOnly;
end;
function TCalendar.GetDateTime: TDateTime;
begin
Result:=FDate;
end;
procedure TCalendar.SetDateTime(const AValue: TDateTime);
var
OldDate: TDateTime;
begin
OldDate:=FDate;
FDate:=AValue;
FDateAsString:=FormatDateTime(ShortDateFormat,FDate);
{$IFDEF VerboseCalenderSetDate}
writeln('TCalendar.SetDateTime FDate=',FDate,' FDateAsString=',FDateAsString,' ShortDateFormat=',ShortDateFormat);
{$ENDIF}
if OldDate=FDate then exit;
SetProps;
end;
Procedure TCalendar.GetProps;
var
Temp : TLMCalendar;
begin
if HandleAllocated and (not (csLoading in ComponentState)) then
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then
begin
CNSendMessage(LM_GETVALUE, Self, @temp); // Get the info
FDate := Temp.Date;
FDateAsString := FormatDateTime(ShortDateFormat,FDate);
{$IFDEF VerboseCalenderSetDate}
writeln('TCalendar.GetProps A ',FDate,' ',FDateAsString);
{$ENDIF}
end;
end;
@ -203,15 +228,15 @@ Procedure TCalendar.SetProps;
var
Temp : TLMCalendar;
begin
if HandleAllocated and (not (csLoading in ComponentState)) then
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then
begin
FPropsChanged:=false;
{$IFDEF VerboseCalenderSetDate}
writeln('TCalendar.SetProps FDate=',FDate,' FDateAsString=',FDateAsString,' ShortDateFormat=',ShortDateFormat);
{$ENDIF}
Temp.Date := FDate;
Temp.DisplaySettings := FDisplaySettings;
Temp.ReadOnly := fReadOnly;
{$IFDEF VerboseCalenderSetDate}
writeln('TCalendar.SetProps A ',FDate,' ',FDateAsString);
{$ENDIF}
CNSendMessage(LM_SETVALUE, Self, @temp); // Get the info
End else begin
FPropsChanged:=true;