datetimepicker使用问题,请大哥大姐帮忙(100分)

  • 主题发起人 主题发起人 cohye
  • 开始时间 开始时间
C

cohye

Unregistered / Unconfirmed
GUEST, unregistred user!
一个datetimepicker控件能不能实现针对日期和时间的修改?<br>开始时间:2008-01-01 3:25:26<br>终止时间:2008-01-31 6:36:56<br>用label测试,不能实现修改的日期和时间的显示。<br>要麽日期修改,要麽时间修改。<br>就是不能实现一起修改的情形。<br>与datetimepicker控件的kind属性设置相同。<br>是这样的吗??<br><br>我已经把这程序调好几天了,希望大哥大姐指点。
 
确实是这样的,这个组件没有办法同时对日期和时间操作。
 
正好看到一个解决方案:<br>http://www.1zwwz.cn/show.php?mod=article&amp;id=2536
 
谢谢楼上两位,[:)][:)]
 
{TDateTimePicker只能要么修改时间,要么修改日期,无法二者同时修改;另外,它也只有日期限制,而无时间限制功能。为了解决这些问题,我自己把它进行了扩展,可以满足这些要求了,希望对大家有用。DSLWORK@ShangHai.2008.03.10 (dslwork[AT]163。com)}<br><br>unit DateTimePickerNew;<br><br>interface<br><br>uses<br>&nbsp; SysUtils, Classes, Controls, ComCtrls, ComStrs, Math;<br><br>type<br>&nbsp; TDateTimePickerNew = class(TDateTimePicker)<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; FMaxDateTime, FMinDateTime: TDateTime;<br>&nbsp; protected<br>&nbsp; &nbsp; { Protected declarations }<br>&nbsp; &nbsp; procedure SetMaxDateTime(AMax: TDateTime);<br>&nbsp; &nbsp; procedure SetMinDateTime(AMin: TDateTime);<br>&nbsp; &nbsp; procedure Change; override;<br>&nbsp; &nbsp; procedure CreateWnd; override;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br><br>&nbsp; &nbsp; constructor Create(AOwner: TComponent); override;<br>&nbsp; &nbsp; procedure OnDateTimeChange(Sender: TObject);<br>&nbsp; published<br>&nbsp; &nbsp; { Published declarations }<br>&nbsp; &nbsp; property MaxDateTime: TDateTime read FMaxDateTime write SetMaxDateTime;<br>&nbsp; &nbsp; property MinDateTime: TDateTime read FMinDateTime write SetMinDateTime;<br>&nbsp; end;<br><br>procedure Register;<br>implementation<br><br>procedure Register;<br>begin<br>&nbsp; RegisterComponents('DSLWORK', [TDateTimePickerNew]);<br>end;<br><br>procedure TDateTimePickerNew.Change;<br>begin<br>&nbsp; OnDateTimeChange(Self);<br>&nbsp; inherited Change;<br>end;<br><br>constructor TDateTimePickerNew.Create(AOwner: TComponent);<br>begin<br>&nbsp; inherited Create(AOwner);<br><br>&nbsp; { //下面的代码已经被移动到 CreateWnd 中,否则会报 Control '' has no parent<br>Format := 'yyyy-MM-dd HH:mm:ss';<br>DateFormat := dfLong;<br>DateMode := dmUpDown;<br>Kind := dtkTime; }<br><br>&nbsp; FMaxDateTime := 0.0;<br>&nbsp; FMinDateTime := 0.0;<br><br>end;<br><br>procedure TDateTimePickerNew.CreateWnd;<br>begin<br>&nbsp; inherited;<br>&nbsp; Format &nbsp; &nbsp; := 'yyyy-MM-dd HH:mm:ss';<br>&nbsp; DateFormat := dfLong;<br>&nbsp; DateMode &nbsp; := dmUpDown;<br>&nbsp; Kind &nbsp; &nbsp; &nbsp; := dtkTime;<br><br>&nbsp; //FMaxDateTime := 0.0;<br>&nbsp; //FMinDateTime := 0.0;<br>end;<br><br>procedure TDateTimePickerNew.OnDateTimeChange(Sender: TObject);<br>var<br>&nbsp; dtMax, dtMin: string;<br>begin<br>&nbsp; dtMax := FormatDateTime(Self.Format, FMaxDateTime);<br>&nbsp; dtMin := FormatDateTime(Self.Format, FMinDateTime);<br>&nbsp; DateTime := StrToDateTime(Self.Caption); //这一行上一次发布时忘了写上了<br>&nbsp; if (FMinDateTime &lt;&gt; 0.0) and (Self.Caption &lt; dtMin) then<br>&nbsp; &nbsp; DateTime := FMinDateTime;<br>&nbsp; if (FMaxDateTime &lt;&gt; 0.0) and (Self.Caption &gt; dtMax) then<br>&nbsp; &nbsp; DateTime := FMaxDateTime;<br>end;<br><br>procedure TDateTimePickerNew.SetMaxDateTime(AMax: TDateTime);<br>begin<br>&nbsp; if (FMinDateTime &lt;&gt; 0.0) and (AMax &lt; FMinDateTime) then<br>&nbsp; &nbsp; raise CalExceptionClass.CreateFmt(SDateTimeMin, [DateToStr(FMinDateTime)]);<br>&nbsp; if FMaxDateTime &lt;&gt; AMax then begin<br>&nbsp; &nbsp; FMaxDateTime := AMax;<br>&nbsp; &nbsp; //MaxDate := Ceil(AMax);<br>&nbsp; end;<br>end;<br><br>procedure TDateTimePickerNew.SetMinDateTime(AMin: TDateTime);<br>begin<br>&nbsp; if (FMaxDateTime &lt;&gt; 0.0) and (AMin &gt; FMaxDateTime) then<br>&nbsp; &nbsp; raise CalExceptionClass.CreateFmt(SDateTimeMax, [DateToStr(FMaxDateTime)]);<br>&nbsp; if FMinDateTime &lt;&gt; AMin then begin<br>&nbsp; &nbsp; FMinDateTime := AMin;<br>&nbsp; &nbsp; //MinDate := Floor(AMin);<br>&nbsp; end;<br>end;<br><br>end.
 
多人接受答案了。
 
后退
顶部