Delphi格式日期时间异常
对于 CSV 文件的每一行,我的应用程序需要调用一个方法,该方法读取每个变量并使用 GetDataItem 方法将其中一些变量写入表中。例如,
Var
Item: String;
Tmp: String;
Rdate: String;
TmpDateTime: TDateTime;
begin
Table1.Append'
Tmp := GetDataItem(Data, Item); {Ignore}
Tmp := GetDataItem(Data, Item); {Ignore}
Tmp := GetDataItem(Data, Item); {Members ID}
Table1.FieldByName('Member ID').AsString := UpperCase(Tmp);
TmpDateTime := StrToDateTime(etDataItem(Data, Item));
Table1.FieldByName('Arrival Date').AsString := FormatDateTime('dd/mm/yyyy',TmpDateTime);
Table1.FieldByName('Arrival Time').AsString := FormatDateTime('hh:mm:ss',TmpDateTime);
...
Table1.Post;
这工作正常,但我还需要从 DateTime 时间戳以 yyyymmdd 格式生成 ReverseDate。然而,任何再次使用时间戳变量的尝试似乎都会引发异常,例如
RDate := FormatDateTime('yyyy',TmpDateTime) + FormatDateTime('mm',TmpDateTime) + FormatDateTime('dd',TmpDateTime);
,或者
RDate := FormatDateTime('yyyymmdd',TmpDateTime);
我尝试复制 DateTime 变量并对其进行处理,或者拆分 DateTime 字符串,但就好像任何进一步的操作在运行时都会引发异常。
编辑:抱歉,在我的 XP 机器上,我现在得到例外:
EAccessViolation in the module 'ImpWintacs.exe' at 000749DA. Access violation at address "000749DA" in module 'ImpWintacs.exe'. Read of address 00C1FDF8.
谢谢
For each line of a CSV file, my application needs to call a method which reads in each variables and writes some of them to a table using a GetDataItem method. e.g.
Var
Item: String;
Tmp: String;
Rdate: String;
TmpDateTime: TDateTime;
begin
Table1.Append'
Tmp := GetDataItem(Data, Item); {Ignore}
Tmp := GetDataItem(Data, Item); {Ignore}
Tmp := GetDataItem(Data, Item); {Members ID}
Table1.FieldByName('Member ID').AsString := UpperCase(Tmp);
TmpDateTime := StrToDateTime(etDataItem(Data, Item));
Table1.FieldByName('Arrival Date').AsString := FormatDateTime('dd/mm/yyyy',TmpDateTime);
Table1.FieldByName('Arrival Time').AsString := FormatDateTime('hh:mm:ss',TmpDateTime);
...
Table1.Post;
This works fine except I also need to generate a ReverseDate from the DateTime stamp in the format yyyymmdd. However any attempt to use the timestamp variable again seems to throw an exception e.g.
RDate := FormatDateTime('yyyy',TmpDateTime) + FormatDateTime('mm',TmpDateTime) + FormatDateTime('dd',TmpDateTime);
or
RDate := FormatDateTime('yyyymmdd',TmpDateTime);
I've tried duplicating the DateTime variable and working on that instead, or splitting a DateTime String, but it's as if any further manipulation of throws an exception when run.
EDIT: Apologies, On my XP machine I now get the exception:
EAccessViolation in the module 'ImpWintacs.exe' at 000749DA. Access violation at address "000749DA" in module 'ImpWintacs.exe'. Read of address 00C1FDF8.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用来从 CSV 读取下一个变量的方法是读取字符直到下一个逗号。 CSV 中的最后一个变量后面没有逗号。因为我不需要最后一个变量,所以我只是选择不读取它。
The method I was using to read the next variable from the CSV, read the chars up until the next comma. The last variable in the CSV was not followed by a comma. As I didn't need the last variable anyway I just chose not to read it.