本人在做一个上班安排程序,定义了类
TDutyPlan=class{DutyPlan}
DutyDate:TDateTime; //日期
DutyName:string; //班次名称
end;
在程序中取排班信息
var TempDutyPlan:TDutyPlan;
DateList:TList;
begin
TempDutyPlan.DutyDate:= strtodate(formatdatetime('yyyy-m-d',CurrentDate));
s:=TMenuItem(Sender).caption;
TempDutyPlan.DutyName:=s;
DateList.Add(TempDutyPlan);
end;测试保存到DateList中的数据
var
TmpDatePlan:TDutyPlan;
for i:=0 to DateList.Count-1 do
begin
//TmpDatePlan.Create;
TmpDatePlan:=DateList.Items[i];
showmessage(datetostr(TmpDatePlan.DutyDate)+TmpDatePlan.DutyName);
end;如DateList.Count=2,分别增加的是{2007-7-11,早班},{2007-7-12,夜班}
但showmessage()显示的却是{2007-7-12,夜班},{2007-7-12,夜班},加入的是最后一条,
请高手赐教!
TDutyPlan=class{DutyPlan}
DutyDate:TDateTime; //日期
DutyName:string; //班次名称
end;
在程序中取排班信息
var TempDutyPlan:TDutyPlan;
DateList:TList;
begin
TempDutyPlan.DutyDate:= strtodate(formatdatetime('yyyy-m-d',CurrentDate));
s:=TMenuItem(Sender).caption;
TempDutyPlan.DutyName:=s;
DateList.Add(TempDutyPlan);
end;测试保存到DateList中的数据
var
TmpDatePlan:TDutyPlan;
for i:=0 to DateList.Count-1 do
begin
//TmpDatePlan.Create;
TmpDatePlan:=DateList.Items[i];
showmessage(datetostr(TmpDatePlan.DutyDate)+TmpDatePlan.DutyName);
end;如DateList.Count=2,分别增加的是{2007-7-11,早班},{2007-7-12,夜班}
但showmessage()显示的却是{2007-7-12,夜班},{2007-7-12,夜班},加入的是最后一条,
请高手赐教!
TDutyPlan=class{DutyPlan}
DutyDate:TDateTime; //日期
DutyName:string; //班次名称
end;
在程序中取排班信息
var
lpTempDutyPlan: PDutyPlan;
DateList: TList; //最少应该是模块级变量,而不是函数级。
begin
new(lpTmpDutyPlan);
lpTmpDutyPlan^.DutyDate:= StrToDate(formatdatetime( 'yyyy-m-d ',CurrentDate));
s:=TMenuItem(Sender).caption;
lpTempDutyPlan^.DutyName:=s;
DateList.Add(lpTempDutyPlan);
end;测试保存到DateList中的数据
var
TmpDatePlan:TDutyPlan;
for i:=0 to DateList.Count-1 do
begin
TmpDatePlan:=PDutyPlan(DateList.Items[i])^;
showmessage(datetostr(TmpDatePlan.DutyDate)+TmpDatePlan.DutyName);
end;
PDutyPlanList=^AList;
AList=record
DutyDate:TDateTime; //日期
DutyName:string; //班次名称
end;
解决了!