起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 265|回复: 5

【结贴】日期函数的问题

[复制链接]
发表于 2009-11-24 11:39:04 | 显示全部楼层 |阅读模式
下面这个代码有什么问题?为什么会报错呢?

type
  TReportParam = class(Object)
  private
  public
      strReportType : string;
      strYear : string;
      iQuarter : Integer;
      iMonth : Integer;
      iWeekOfMonth : Integer;
      iWeekOfYear: Integer;
  end;

type
  TCT_ZTB_DBZBSBFLTJMXBB_MAINFORM = class(TForm)
.
.
.
某函数中
begin
//下面的语句报错
myReportParam.strYear := DateUtils.YearOf(myDateTimePicker.Date).ToString;
end;

end;

end.

qq截图未命名4.jpg

22.41 KB, 下载次数: 194

回复

使用道具 举报

发表于 2009-11-24 11:45:16 | 显示全部楼层
是不是有对象没有创建,代码贴全些。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-11-24 12:25:58 | 显示全部楼层

不会啊。我把出问题的代码注释,换成常量就没事了

procedure TCT_ZTB_DBZBSBFLTJMXBB_MAINFORM.BizFormShow(Sender: TObject);
begin
    Init;
end;

procedure TCT_ZTB_DBZBSBFLTJMXBB_MAINFORM.Init;
begin
    myReportParam := TReportParam.Create;
    myReportParam.strReportType := '1';
    //myReportParam.strYear := DateUtils.YearOf(myDateTimePicker.Date).ToString;
    myReportParam.strYear := '2009';
end;
回复 支持 反对

使用道具 举报

发表于 2009-11-24 13:51:30 | 显示全部楼层
你不要用tostring
使用:SysUtils.formatdatetime来格式化日期。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-11-24 14:41:14 | 显示全部楼层
找到方法了
IntToStr(DateUtils.YearOf(myDateTimePicker.Date))
这样写就ok了
回复 支持 反对

使用道具 举报

发表于 2009-11-24 14:50:59 | 显示全部楼层
不管用哪种方法,就不要使用tostring就ok了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-14 06:33 , Processed in 0.045867 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表