gpt4 book ai didi

Delphi TDateTimePicker 问题, "failed to set min/max range"

转载 作者:行者123 更新时间:2023-12-03 18:18:40 24 4
gpt4 key购买 nike

我的一个应用程序的一些用户遇到了一个奇怪的问题,在启动时他们得到了 datitimepickers 的异常,其预定的最小/最大日期设置为 1950 年 1 月 1 日 - 2050 年 12 月 31 日。

应用抛出的默认错误信息是

"Error reading time1.Max: Failed to set calendar min/max range."

嵌入调试器(madshi 的 madExcept)后,我在报告中看到:

"Error reading time1.MaxDate: '23:59:59' is not a valid date and time."

窗体上的对象具有这些属性:

            Date = 39773.494141041670000000
Format = 'MMM yyyy'
Time = 39773.494141041670000000
MaxDate = 55153.999988425920000000
MinDate = 18264.000000000000000000

知道可能是什么问题吗?

崩溃数据:

主线程($2b08):

> 0051501b +0a7 app.exe System.Classes 10430   +5 HandleException
> 00515255 +1f5 app.exe System.Classes 10487 +48 TReader.ReadProperty
> 00514a65 +015 app.exe System.Classes 10233 +1 TReader.ReadDataInner
> 00514a47 +067 app.exe System.Classes 10226 +11 TReader.ReadData
> 0051de05 +001 app.exe System.Classes 15947 +0 TComponent.ReadState
> 0057d017 +02f app.exe Vcl.Controls 5567 +3 TControl.ReadState
> 00581481 +025 app.exe Vcl.Controls 8434 +3 TWinControl.ReadState
> 005148bf +11f app.exe System.Classes 10187 +23 TReader.ReadComponent
> 00514ad9 +089 app.exe System.Classes 10241 +9 TReader.ReadDataInner
> 00514a47 +067 app.exe System.Classes 10226 +11 TReader.ReadData
> 0051de05 +001 app.exe System.Classes 15947 +0 TComponent.ReadState
> 0057d017 +02f app.exe Vcl.Controls 5567 +3 TControl.ReadState
> 00581481 +025 app.exe Vcl.Controls 8434 +3 TWinControl.ReadState
> 00604c4c +028 app.exe Vcl.ExtCtrls 10464 +3
> TCustomCategoryPanel.ReadState 005148bf +11f app.exe System.Classes
> 10187 +23 TReader.ReadComponent 00514ad9 +089 app.exe System.Classes
> 10241 +9 TReader.ReadDataInner 00514a47 +067 app.exe System.Classes
> 10226 +11 TReader.ReadData 0051de05 +001 app.exe System.Classes 15947
> +0 TComponent.ReadState 0057d017 +02f app.exe Vcl.Controls 5567 +3 TControl.ReadState 00581481 +025 app.exe Vcl.Controls 8434 +3 TWinControl.ReadState 005c8523 +00b app.exe Vcl.ComCtrls 6207 +1
> TTabSheet.ReadState 005148bf +11f app.exe System.Classes 10187 +23
> TReader.ReadComponent 00514ad9 +089 app.exe System.Classes 10241 +9
> TReader.ReadDataInner 00514a47 +067 app.exe System.Classes 10226 +11
> TReader.ReadData 0051de05 +001 app.exe System.Classes 15947 +0
> TComponent.ReadState 0057d017 +02f app.exe Vcl.Controls 5567 +3
> TControl.ReadState 00581481 +025 app.exe Vcl.Controls 8434 +3
> TWinControl.ReadState 005148bf +11f app.exe System.Classes 10187 +23
> TReader.ReadComponent 00514ad9 +089 app.exe System.Classes 10241 +9
> TReader.ReadDataInner 00514a18 +038 app.exe System.Classes 10220 +5
> TReader.ReadData 0051de05 +001 app.exe System.Classes 15947 +0
> TComponent.ReadState 0057d017 +02f app.exe Vcl.Controls 5567 +3
> TControl.ReadState 00581481 +025 app.exe Vcl.Controls 8434 +3
> TWinControl.ReadState 0064f15d +06d app.exe Vcl.Forms 3836 +11
> TCustomForm.ReadState 005159d7 +1d7 app.exe System.Classes 10667 +37
> TReader.ReadRootComponent 005109c6 +032 app.exe System.Classes 8269
> +3 TStream.ReadComponent 0050a37f +057 app.exe System.Classes 3834 +7 InternalReadComponentRes 0050bcbb +05f app.exe System.Classes 3891 +4 InitComponent 0050bd49 +061 app.exe System.Classes 3903 +6 InitInheritedComponent 0064e982 +0c6 app.exe Vcl.Forms 3592 +17
> TCustomForm.Create 006593da +076 app.exe Vcl.Forms 10407 +13
> TApplication.CreateForm 008e146e +cce app.exe app 342 +211
> initialization 74e9919d +00c KERNEL32.DLL
> BaseThreadInitThunk
>
> main thread ($2b08), inner exception level 1:
> >> EConvertError, '23:59:59' is not a valid date and time 0044d219 +019 app.exe System.SysUtils 5387 +1 ConvertErrorFmt 00453b74 +02c app.exe System.SysUtils 19596 +2 StrToDateTime 005dd4e1 +0f5 app.exe
> Vcl.ComCtrls 27328 +6 TCommonCalendar.SetMaxDate 004e873d +06d
> app.exe System.TypInfo 2238 +8
> {System.TypInfo}TPropSet<System.Double>.SetProc 004e729a +066 app.exe
> System.TypInfo 3185 +3 SetFloatProp 005155ff +18b app.exe
> System.Classes 10567 +25 TReader.ReadPropValue 005151f6 +196 app.exe
> System.Classes 10476 +37 TReader.ReadProperty 00514a65 +015 app.exe
> System.Classes 10233 +1 TReader.ReadDataInner 00514a47 +067 app.exe
> System.Classes 10226 +11 TReader.ReadData 0051de05 +001 app.exe
> System.Classes 15947 +0 TComponent.ReadState 0057d017 +02f app.exe
> Vcl.Controls 5567 +3 TControl.ReadState 00581481 +025 app.exe
> Vcl.Controls 8434 +3 TWinControl.ReadState 005148bf +11f app.exe
> System.Classes 10187 +23 TReader.ReadComponent 00514ad9 +089 app.exe
> System.Classes 10241 +9 TReader.ReadDataInner 00514a47 +067 app.exe
> System.Classes 10226 +11 TReader.ReadData 0051de05 +001 app.exe
> System.Classes 15947 +0 TComponent.ReadState 0057d017 +02f app.exe
> Vcl.Controls 5567 +3 TControl.ReadState 00581481 +025 app.exe
> Vcl.Controls 8434 +3 TWinControl.ReadState 00604c4c +028 app.exe
> Vcl.ExtCtrls 10464 +3 TCustomCategoryPanel.ReadState 005148bf
> +11f app.exe System.Classes 10187 +23 TReader.ReadComponent 00514ad9 +089 app.exe System.Classes 10241 +9 TReader.ReadDataInner 00514a47 +067 app.exe System.Classes 10226 +11 TReader.ReadData 0051de05 +001 app.exe System.Classes 15947 +0 TComponent.ReadState 0057d017 +02f
> app.exe Vcl.Controls 5567 +3 TControl.ReadState 00581481 +025
> app.exe Vcl.Controls 8434 +3 TWinControl.ReadState 005c8523 +00b
> app.exe Vcl.ComCtrls 6207 +1 TTabSheet.ReadState 005148bf +11f
> app.exe System.Classes 10187 +23 TReader.ReadComponent 00514ad9 +089
> app.exe System.Classes 10241 +9 TReader.ReadDataInner 00514a47 +067
> app.exe System.Classes 10226 +11 TReader.ReadData 0051de05 +001
> app.exe System.Classes 15947 +0 TComponent.ReadState 0057d017 +02f
> app.exe Vcl.Controls 5567 +3 TControl.ReadState 00581481 +025
> app.exe Vcl.Controls 8434 +3 TWinControl.ReadState 005148bf +11f
> app.exe System.Classes 10187 +23 TReader.ReadComponent 00514ad9 +089
> app.exe System.Classes 10241 +9 TReader.ReadDataInner 00514a18 +038
> app.exe System.Classes 10220 +5 TReader.ReadData 0051de05 +001
> app.exe System.Classes 15947 +0 TComponent.ReadState 0057d017 +02f
> app.exe Vcl.Controls 5567 +3 TControl.ReadState 00581481 +025
> app.exe Vcl.Controls 8434 +3 TWinControl.ReadState 0064f15d +06d
> app.exe Vcl.Forms 3836 +11 TCustomForm.ReadState 005159d7 +1d7
> app.exe System.Classes 10667 +37 TReader.ReadRootComponent 005109c6
> +032 app.exe System.Classes 8269 +3 TStream.ReadComponent 0050a37f +057 app.exe System.Classes 3834 +7 InternalReadComponentRes 0050bcbb +05f app.exe System.Classes 3891 +4 InitComponent
> 0050bd49 +061 app.exe System.Classes 3903 +6
> InitInheritedComponent 0064e982 +0c6 app.exe Vcl.Forms 3592
> +17 TCustomForm.Create 006593da +076 app.exe Vcl.Forms 10407 +13 TApplication.CreateForm 008e146e +cce app.exe app 342 +211 initialization 74e9919d +00c KERNEL32.DLL
> BaseThreadInitThunk

最佳答案

“无法设置日历最小/最大范围” 错误意味着 DateTime_SetRange()失败的。它可能被赋予了一组无效的 SYSTEMTIME 值,这只是 MaxDate 属性未能从 DFM 正确加载其值的副作用。

“不是有效的日期和时间” 错误来自 StrToDateTime()。根据您的调用堆栈,

>> EConvertError, '23:59:59' is not a valid date and time 0044d219 +019 app.exe
System.SysUtils 5387 +1 ConvertErrorFmt 00453b74 +02c app.exe
System.SysUtils 19596 +2 StrToDateTime 005dd4e1 +0f5 app.exe
Vcl.ComCtrls 27328 +6 TCommonCalendar.SetMaxDate 004e873d +06d app.exe

SetMaxDate() 正在调用 StrToDateTime()。我以前从未见过 TDateTimePicker 这样做,所以我检查了 VCL 源,发现该调用是在 XE5 中添加的(并且在最近发布的 XE6 中仍然存在):

procedure TCommonCalendar.SetMaxDate(Value: TDate);
begin
if (FMinDate <> 0.0) and (Value < FMinDate) then
raise CalExceptionClass.CreateFmt(SDateTimeMin, [DateToStr(FMinDate)]);
if FMaxDate <> Value then
begin
Value := Trunc(Value);
Value := Value + StrToDateTime('23:59:59'); // <-- HERE
SetRange(FMinDate, Value);
FMaxDate := Value;
end;
end;

在 XE5 之前,SetMaxDate() 看起来像这样:

procedure TCommonCalendar.SetMaxDate(Value: TDate);
begin
if (FMinDate <> 0.0) and (Value < FMinDate) then
raise CalExceptionClass.CreateFmt(SDateTimeMin, [DateToStr(FMinDate)]);
if FMaxDate <> Value then
begin
SetRange(FMinDate, Value);
FMaxDate := Value;
end;
end;

这对 Embarcadero 来说简直是愚蠢,因为 StrToDateTime() 受用户区域设置的影响。显然,故障机器上的时间格式与 Embarcadero 使用的硬编码值不匹配。 EncodeTime() 应该改用:

Value := Value + EncodeTime(23, 59, 59, 0);

事实上,我认为 Embarcadero 也应该使用 ReplaceTime():

ReplaceTime(Value, EncodeTime(23, 59, 59, 0));

我已经在 QC 中提交了错误报告:

#124326 MaxDate: '23:59:59' is not a valid date and time

在 Embarcadero 修复它之前,您有两个选择:

  1. 手动修补您的 VCL 以修复错误。如果您没有在启用运行时包的情况下编译您的应用程序,您可以制作 Vcl.ComCtrls.pas 的副本,根据需要对其进行编辑,然后将副本添加到您的项目中。如果您想要一个更永久的补丁,您可以编译编辑后的 ​​Vcl.ComCtrls.pas 并将新的 DCU 文件放在 IDE 的 lib 文件夹中。

  2. 在设计时将 MaxDate 设置为 0.0 设置 SetMaxDate() 将不会在 DFM 加载时调用,然后设置 MaxDate 在启动时手动在您的代码中,因为在表单的 OnCreate 事件中。您必须临时更改全局 SysUtils.FormatSettings 变量(很可能只是 FormatSettings.TimeSeparator)以匹配 SetMaxDate() 的格式使用,然后将 MaxDate 赋值给想要的值,然后将变量改回原来的值:

    var
    TS: Char;

    TS := FormatSettings.TimeSeparator;
    FormatSettings.TimeSeparator := ':';
    try
    DateTimePicker1.MaxDate := ...;
    finally
    FormatSettings.TimeSeparator := TS;
    end;

.

关于Delphi TDateTimePicker 问题, "failed to set min/max range",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23283283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com