0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > TDateTime > VarToDateTime()が失敗する > Lプリフィックス付きの VarToDateTime(L"2015/10/05 12:30:45");はダメ / VarToDateTime("2015/10/05 12:30:45");はOK

Last updated at Posted at 2015-10-05
動作確認
C++ Builder XE4

こちらの投稿でVarToDateTime()を使えばいいと投稿したが、今日以下のコードを実行するとエラーがでるようになった。

TDateTime dt2 = VarToDateTime(L"2015/10/05 12:30:45");

エラーとして以下が表示され、CPUというウィンドウが表示される。

デバッグ出力: HEAP[Project1.exe]: プロセス, Project1.exe
デバッグ出力: 
Invalid address specified RtlSizeHeap( 002c0000, 00406230 )
$77B35DCDでユーザ以外によるブレークポイント。プロセスProject1.exe (1348)

VarToDateTime()もダメなのか。

以下では問題がない。

TDateTime dt2 = StrToDateTime(L"2015/10/05 12:30:45");

http://stackoverflow.com/questions/4070105/which-date-format-does-vartodatetimevardatefromstr-use
を見ると、delphi ではStrToDateTime()にフォーマット指定ができるが、C++ BuilderではそういうAPIは用意されていない。

どうしたものか。


## 解決

以下は失敗する。

TDateTime dt2 = VarToDateTime(L"2015/10/05 12:30:45");

以下は問題ない。

TDateTime dt2 = VarToDateTime("2015/10/05 12:30:45");

Lプリフィックスがあると失敗するというのがよくわからない。

いったんString変数に入れる以下は問題ない。

String dtStr = L"2015/10/05 12:30:45";
TDateTime dt3 = VarToDateTime(dtStr);

OutputDebugString(DateTimeToStr(dt3).c_str());

10.2 Tokyoでも発生

(追記 2019-05-10)

動作確認
RAD Studio 10.2 Tokyo Update 3

10.2 Tokyoでもエラーが発生した。下記のエラーが表示される。

> Invalid address specific to RtlSizeHeap( ... )
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?