DateTimePicker3.Date :=inif.ReadDate('Init','StartDate','');
delphi错误提示如下:
[Error] Unit_KWMain.pas(224): Incompatible types: 'TDateTime' and 'String'该如何修该
delphi错误提示如下:
[Error] Unit_KWMain.pas(224): Incompatible types: 'TDateTime' and 'String'该如何修该
with TInifile.Create(FilePath + 'Time.ini') do
begin
WriteString('section','StarDate',datetoStr(now));
free;
end;
读:
with TInifile.Create(FilePath + 'Time.ini') do
begin
DateTimePicker3.Date := StrtoDate(
ReadString('section','StarDate','2003-12-2');
free;
end;
或
Str := readstring('section','StarDate','2003-12-2');
从Str中取年(2003)月(12)日(2)
然后用EncodeDate函数(查帮助)
eg :DateTimePicker3.Date := EncodeDate(...);
//将yyyy年mm月dd日类型的字符串转化成TDateTime类型
function FormatDateSelf(strDate:string):TDateTime; //用来格式化日期
var
strY:string;
strM:string;
strD:string;
tempDate:string;
begin
strY:=Copy(strDate,1,4);//得到年
strM:=Copy(strDate,7,2);//得到月
strD:=Copy(strDate,11,2);
tempDate:=strY+'-'+strM+'-'+strD;
Result:=strToDateTime(tempDate);
end;
//将日期转化为20031011类型的字符串
function FormatDateToStr(DateTime:TDateTime):string;
var
tempDateStr:string;
begin
tempDateStr:=FormatDateTime('yyyy年MM月dd日',DateTime);
Result:=Copy(tempDateStr,1,4)+Copy(tempDateStr,7,2)+Copy(tempDateStr,11,2);
end;
你的只要读取字符串,然后用同样方法转换就好了