D6是不是也太多管闲事了,大富们,你说我要听它的吗?(50分)

  • 主题发起人 主题发起人 e518
  • 开始时间 开始时间
E

e518

Unregistered / Unconfirmed
GUEST, unregistred user!
try
LbList:=TstringList.Create;
//
//这里是一些给LbList赋值的语句。
//
except
S:='建立类别索引时错误!';
messagebox(0,pchar(s),pchar(WinCaption),mb_ok+MB_ICONSTOP);
if LbList<>nil then LbList.Free;
exit;
end;

当程序编译到if LbList<>nil then LbList.Free;时总提示 “Variable 'LbList' might not have been initialized;”

如果听它的,就要删除 LbList.Free;这一句呀
 
本来就是你的问题,应该:

LbList:=TstringList.Create;
try
//
//这里是一些给LbList赋值的语句。
//
finally
LbList.Free;
exit;
end;
 
其实要说你的有什么错,我也说不清,但是我觉得按delphi推荐的方法比较好
 
老兄, 我是怕LbList:=TstringList.Create是也会出错呀。
 
那这样
lbList := nil;
try
LbList:=TstringList.Create;
 
我明白你的意思。
刚看了(create)帮助:
Note: If an exception escapes from a constructor,
the object's destructor is called to clean up the failed instance.
也就是说在调用create方法后,如果不成功,那么object会自动释放,就不劳你操心了。
 
if assigned(lbList) then
try
LbList:=TstringList.Create;
......
用assigned来判断比较安全。
 
帮人也就是帮自已。
我原先也想过这个问题,但是没有去查帮助,只是想delphi自已都这么做,肯定不会有
什么问题。看了帮助才知道是这么一回事。
 
同意远帆说的。
 
TO 远兄

真的是这样,帮人也是帮自己。
呵呵,我QQ11602585,有缘可聊聊。
 
同意远帆说的。
 
送分了呀,老大们,接呀》》》》》》》》》
 
后退
顶部