Delphi中StrToDate()若未使用参数化TFormatSettings,直接调用会否引发AV异常?

2026-04-10 19:452阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计178个文字,预计阅读时间需要1分钟。

Delphi中StrToDate()若未使用参数化TFormatSettings,直接调用会否引发AV异常?

为了简化这段代码,并确保不超过100个字,我们可以删除不必要的注释和空格,并直接指出问题所在。以下是修改后的代码:

pascalprocedure TForm1.Button1Click(Sender: TObject);var fs: TFormatSettings;begin strtodate('2011-01-01', fs);end;

Delphi中StrToDate()若未使用参数化TFormatSettings,直接调用会否引发AV异常?

问题原因:`fs`变量未初始化,导致运行时异常。

只是为了好奇:为什么这段代码给出AV而不是抛出异常?

procedure TForm1.Button1Click(Sender: TObject); var fs: TFormatSettings; begin strtodate('2011-01-01', fs); end; 您的代码引发异常,因为fs未初始化.

uses SysUtis, Windows; procedure TForm1.Button1Click(Sender: TObject); var fs: TFormatSettings; begin GetLocaleFormatSettings(GetSystemDefaultLCID, fs); // what is your short-date format? strtodate('2011-01-01', fs); end;

本文共计178个文字,预计阅读时间需要1分钟。

Delphi中StrToDate()若未使用参数化TFormatSettings,直接调用会否引发AV异常?

为了简化这段代码,并确保不超过100个字,我们可以删除不必要的注释和空格,并直接指出问题所在。以下是修改后的代码:

pascalprocedure TForm1.Button1Click(Sender: TObject);var fs: TFormatSettings;begin strtodate('2011-01-01', fs);end;

Delphi中StrToDate()若未使用参数化TFormatSettings,直接调用会否引发AV异常?

问题原因:`fs`变量未初始化,导致运行时异常。

只是为了好奇:为什么这段代码给出AV而不是抛出异常?

procedure TForm1.Button1Click(Sender: TObject); var fs: TFormatSettings; begin strtodate('2011-01-01', fs); end; 您的代码引发异常,因为fs未初始化.

uses SysUtis, Windows; procedure TForm1.Button1Click(Sender: TObject); var fs: TFormatSettings; begin GetLocaleFormatSettings(GetSystemDefaultLCID, fs); // what is your short-date format? strtodate('2011-01-01', fs); end;