TDateTimePicker or TRzDateTimePicker date not changing

本文介绍如何在Delphi中解决TRzDateTimePicker控件只能单独设置日期或时间的问题,通过自定义TDTPicker类并利用StrToDateTime函数,实现同时修改日期和时间的功能。

      在使用TRzDateTimePicker的时候。手动设置TRzDateTimePicker的时间后,要么只能设置日期,要么只能设置时间,这个根据该控件的kind属性决定的,且该属性只有dtkTime 和dtkDate两种情况。我们既不想放2个这样的控件,又想同时修改date和time。那么需要做如下处理:

     this problem can be solved by reading the Text property, but in delphi this property is protected. so...

	TDTPicker = class(TControl)
	public
		property Text;
	end;



in DTPicker onChange read the text and convert to DateTime property

	DT1.DateTime := StrToDateTime(TDTPicker(DT1).Text);

   上面的DT1是你的TDateTimePicker or  TRzDateTimePicker。


说明:StrToDateTime 和电脑的本地时间格式有关系,如果设定的格式和电脑的格式不一致就会报错。


我们可以这么做:

var
  FSetting : TFormatSettings;
  DateTime1: tDateTime;
begin
  FSetting := TFormatSettings.Create(LOCALE_USER_DEFAULT);
  try
	  FSetting.ShortDateFormat:='yyyy-MM-dd';
	  FSetting.DateSeparator:='-';
	  FSetting.TimeSeparator:=':';
	  FSetting.LongTimeFormat:='hh:mm:ss';
	  DT1.DateTime := StrToDateTime(TDTPicker(DT1).Text,FSetting);
  finally
  	freeandnil(FSetting);
  end;
end;

也可以这么做:

var
  formatsetting:TFormatSettings;
begin
  GetLocaleFormatSettings(GetUserDefaultLCID,formatsetting);
  formatsetting.DateSeparator:='-';
  formatsetting.TimeSeparator:=':';
  formatsetting.ShortDateFormat:='yyyy-MM-dd';
  formatsetting.ShortTimeFormat:='HH:mm:ss';
  dtp1.DateTime := StrToDateTime(TDTPicker(dtp1).Text,formatsetting);
end;

 

 

参考:https://forums.embarcadero.com/message.jspa?messageID=354510


Raize Components 6.1.12 Modifications The following is a list of all of the modifications that have been made for version 6.1.12 of Raize Components. For a list of all modifications made to previous versions of Raize Components 6, please see the "RC 6 Modifications.txt" file. -------------------------------------------------------------------------------- Build: 6.1.12 Date: 11 Apr 2015 -------------------------------------------------------------------------------- Added support for Embarcadero RAD Studio XE8. Supported IDEs Embarcadero RAD Studio XE8 -- Delphi XE8 & C++Builder XE8 Embarcadero RAD Studio XE7 -- Delphi XE7 & C++Builder XE7 Embarcadero RAD Studio XE6 -- Delphi XE6 & C++Builder XE6 Embarcadero RAD Studio XE5 -- Delphi XE5 & C++Builder XE5 Embarcadero RAD Studio XE4 -- Delphi XE4 & C++Builder XE4 Embarcadero RAD Studio XE3 -- Delphi XE3 & C++Builder XE3 Embarcadero RAD Studio XE2 -- Delphi XE2 & C++Builder XE2 Embarcadero RAD Studio XE -- Delphi XE & C++Builder XE Embarcadero RAD Studio 2010 -- Delphi 2010 & C++Builder 2010 CodeGear RAD Studio 2009 -- Delphi 2009 & C++Builder 2009 RzButton.pas * Fixed issue in TRzToolButton where drop down menu would be displayed on the adjacent monitor under certainly situations. RzDBEdit.pas * Fixed issue in TRzDBEdit and descendants where registered style hook was not correctly unregistered when the hook was no longer needed. * Added UseFormatToParse property to TRzDateTimeEdit. Set this property to True in situations where the Time to be parsed contains more elements than are contained in the LongTimeFormat string. For example, if the Time needed to be entered must have 'hh:nn:ss.zzz' and the LongTimeFormat string is set to 'hh:nn', then set the UseFormatToParse to True and set the Format property to the desired format string. RzDBList.pas * Surface the Sorted property in TRzDBListBox. RzEdit.pas * Fixed issue in TRzEdit and descendants where registered style hook was not correctly unregistered when the hook was no longer needed. * Added UseFormatToParse property to TRzDateTimeEdit. Set this property to True in situations where the Time to be parsed contains more elements than are contained in the LongTimeFormat string. For example, if the Time needed to be entered must have 'hh:nn:ss.zzz' and the LongTimeFormat string is set to 'hh:nn', then set the UseFormatToParse to True and set the Format property to the desired format string. RzGroupBar.pas * Fixed issue in TRzGroupBar where registered style hook was not correctly unregistered when the hook was no longer needed. RzLstBox.pas * Fixed issue in TRzListBox and descendants where text in item hints would get clipped if the TRzBalloonHints component was also being used in the application. RzShellCtrls.pas * When dragging a file from a TRzShellList and dropping it onto a different folder in the associated TRzShellTree, the shell tree no longer scrolls to the source folder represented by the shell list. That is, the shell tree maintains its current view. RzSpnEdt.pas * Fixed issue where ParentColor property in TRzSpinner and TRzDBSpinner was not getting streamed correctly to form files. RzTabs.pas * Fixed issue where drop-down menu in TRzPageControl and TRzTabControl would not be displayed correctly when using a custom VCL Style in XE6 or XE7. * Added LightenUnselectedColoredTabs property to TRzPageControl and TRzTabControl. When this property is True, a non-active colored tab will be displayed with a lightened version of the tab color. When this property is False, the unselected tab is displayed in the same color as the active tab color. --------------------------------------------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值