A
abea
Unregistered / Unconfirmed
GUEST, unregistred user!
我在类中的成员函数返回一个TList,如下所示,然后再外面把它释放,可是释放时,老出错。请各位帮我看看。谢谢!
type
PMesItems = ^TMesItems
TMesItems = record
strItem : string
//²âÁ¿ÏîµÄ±êÌ&acirc
strID : Integer
//²¡È˵ÄID
strDateTime :string
//²âÁ¿Ê±¼&auml
end
//类中的内容
function TMesContrast.GetMuscleQuantityData: TList
var
tmpList:TList
tmpMesItems MesItems
begin
try
tmpList := TList.Create
if(NOt(dmMesContrast.qryFiveTee.Eof) and not(dmMesContrast.qryFiveTee.Bof )) then
begin
dmMesContrast.qryFiveTee.First
while(not(dmMesContrast.qryFiveTee.Eof)) do
begin
tmpMesItems := new(PMesItems)
tmpMesItems.strItemTitle := 'MuscleQuantity'
tmpMesItems.strLData := dmMesContrast.qryFiveTee.FieldByName('Lmf').AsString
tmpMesItems.strRData := dmMesContrast.qryFiveTee.FieldByName('Rmf').AsString
tmpMesItems.strID := dmMesContrast.qryFiveTee.FieldByName('CaseID').AsString
tmpMesItems.strDateTime := dmMesContrast.qryFiveTee.FieldByName('MeasureTime').AsString
tmpList.Add(tmpMesItems)
dmMesContrast.qryFiveTee.Next
end
dmMesContrast.qryFiveTee.First
end
result := tmpList
except
Result := nil
end
end
//外面的内容,去掉里面分配的内存。
procedure TMainForm.Button1Click(Sender: TObject)
var
objMes :TIMesContrast
tmpList:TList
tmpItemsMesItems
integer
strTmp:string
begin
strTmp := '1'
tmpList := Tlist.Create
objMes := TObjMesContrast.Create
objMes.SetPatientID(strTmp)
objMes.SetSQL('select * from mesc30 ')
tmpList := objMes.GetLegMuscleForceData
for i := 0 to tmplist.Count -1 do
begin
tmpItems := tmpList.items
dispose(tmpItems)
end
showmessage(IntToStr(tmpList.Count))
objMes.Free
tmpList.Free
end
//说明,我对c++比较在行,c++中可以用new分配内存,在外面释放没有问题。因为new是在堆中分配内存,只要指针存在,就可以释放。在delphi中可以么?如果我想把返回的tlist释放掉,应该怎么做?谢谢。
type
PMesItems = ^TMesItems
TMesItems = record
strItem : string
//²âÁ¿ÏîµÄ±êÌ&acirc
strID : Integer
//²¡È˵ÄID
strDateTime :string
//²âÁ¿Ê±¼&auml
end
//类中的内容
function TMesContrast.GetMuscleQuantityData: TList
var
tmpList:TList
tmpMesItems MesItems
begin
try
tmpList := TList.Create
if(NOt(dmMesContrast.qryFiveTee.Eof) and not(dmMesContrast.qryFiveTee.Bof )) then
begin
dmMesContrast.qryFiveTee.First
while(not(dmMesContrast.qryFiveTee.Eof)) do
begin
tmpMesItems := new(PMesItems)
tmpMesItems.strItemTitle := 'MuscleQuantity'
tmpMesItems.strLData := dmMesContrast.qryFiveTee.FieldByName('Lmf').AsString
tmpMesItems.strRData := dmMesContrast.qryFiveTee.FieldByName('Rmf').AsString
tmpMesItems.strID := dmMesContrast.qryFiveTee.FieldByName('CaseID').AsString
tmpMesItems.strDateTime := dmMesContrast.qryFiveTee.FieldByName('MeasureTime').AsString
tmpList.Add(tmpMesItems)
dmMesContrast.qryFiveTee.Next
end
dmMesContrast.qryFiveTee.First
end
result := tmpList
except
Result := nil
end
end
//外面的内容,去掉里面分配的内存。
procedure TMainForm.Button1Click(Sender: TObject)
var
objMes :TIMesContrast
tmpList:TList
tmpItemsMesItems
integer
strTmp:string
begin
strTmp := '1'
tmpList := Tlist.Create
objMes := TObjMesContrast.Create
objMes.SetPatientID(strTmp)
objMes.SetSQL('select * from mesc30 ')
tmpList := objMes.GetLegMuscleForceData
for i := 0 to tmplist.Count -1 do
begin
tmpItems := tmpList.items
dispose(tmpItems)
end
showmessage(IntToStr(tmpList.Count))
objMes.Free
tmpList.Free
end
//说明,我对c++比较在行,c++中可以用new分配内存,在外面释放没有问题。因为new是在堆中分配内存,只要指针存在,就可以释放。在delphi中可以么?如果我想把返回的tlist释放掉,应该怎么做?谢谢。