implementation
var
。。
ListMaterial:Tlist;//申明TLIST程序段1:
procedure TForm1.DoKeyPress(StrGrid:TStringGrid;key:integer);
//将记录添加到LIST中
var
Material:^MaterialRec;
begin
if key=13 then
begin
New(Material);
Material^.MaterialDemandDay:=SGPur_BillDeMand.Cells[6,row];
// showmessage(SGPur_BillDeMand.Cells[6,row]);
ListMaterial.Add(Material); //将材料子项填入到某个需求单中
dispose(Material); ??????????注意行?????????
AddStrGridRow(StrGrid,Row); end;
end;
程序段2:
procedure TForm1.Button1Click(Sender: TObject);
//将LIST中的记录显示出来
var c:integer;
y:Word;
kk:String;
Material1:^MaterialRec;
begin
//showmessage('ff');
showmessage(inttostr(ListMaterial.Count));
Y:=10;
// showmessage(inttostr(listmaterial.count)
for c:=0 to ListMaterial.Count-1 do
begin
begin
New(Material1);
Material1:= ListMaterial.Items[c];
//kk:=Inttostr(Material^.MaterialQuanlity) ;
//showmessage(kk);
// Showmessage(inttostr(Material^.MaterialQuanlity ));
//Canvas.TextOut(10, Y, Material^.MaterialDemandDay);
showmessage(Material1^.MaterialDemandDay) ;
Y := Y + 30;
dispose(Material1);
end;
end;
end;问题:当我去掉注意行程序运行正常,当我不去掉,在激发程序段2时程序报错,感觉好像是TLIST的问题。??有没有高手帮帮忙阿????因为指针是必须释放的阿!
var
。。
ListMaterial:Tlist;//申明TLIST程序段1:
procedure TForm1.DoKeyPress(StrGrid:TStringGrid;key:integer);
//将记录添加到LIST中
var
Material:^MaterialRec;
begin
if key=13 then
begin
New(Material);
Material^.MaterialDemandDay:=SGPur_BillDeMand.Cells[6,row];
// showmessage(SGPur_BillDeMand.Cells[6,row]);
ListMaterial.Add(Material); //将材料子项填入到某个需求单中
dispose(Material); ??????????注意行?????????
AddStrGridRow(StrGrid,Row); end;
end;
程序段2:
procedure TForm1.Button1Click(Sender: TObject);
//将LIST中的记录显示出来
var c:integer;
y:Word;
kk:String;
Material1:^MaterialRec;
begin
//showmessage('ff');
showmessage(inttostr(ListMaterial.Count));
Y:=10;
// showmessage(inttostr(listmaterial.count)
for c:=0 to ListMaterial.Count-1 do
begin
begin
New(Material1);
Material1:= ListMaterial.Items[c];
//kk:=Inttostr(Material^.MaterialQuanlity) ;
//showmessage(kk);
// Showmessage(inttostr(Material^.MaterialQuanlity ));
//Canvas.TextOut(10, Y, Material^.MaterialDemandDay);
showmessage(Material1^.MaterialDemandDay) ;
Y := Y + 30;
dispose(Material1);
end;
end;
end;问题:当我去掉注意行程序运行正常,当我不去掉,在激发程序段2时程序报错,感觉好像是TLIST的问题。??有没有高手帮帮忙阿????因为指针是必须释放的阿!
解决方案 »
- 在delphi中如何用TdxTreeList接受TdxDBGrid的值啊
- 单击button1,时可以选择打开硬盘中图片,然后显示在timage中,这样的功能如何实现
- combobox 选中一项
- 求jpg转换成bmp的算法
- 文本框中的光标问题,在线等待......
- 学习delphi时,BDE Administer中遇到的Interbase使用问题
- 不爽..半夜十一点,钥匙没掉...散分!!
- 做一个由server端向client端发送消息的程序
- 关于DbLookupCombobox的问题。
- 谁有F1Book1(在ActiveX页中)与数据库联系使用的范例
- 幫幫菜鳥吧!
- 高分求dxDBGRID,wwDBGRID控件。
2)段2不要new和dispose Material1,new了没用,dispose反而把List中的内容释放了,导致第二次执行肯定要出错。
3)程序释放的时候,记得dispose List中的内容。
即ListMaterial引用了Material;可在ListMaterial列表不用之后Dispose(ListMaterial.Items.[]).
小陈呀。。Dispose不是随便用的.
我跟你说,你应该在show完之后释放。
给你写一个DoClearList;procedure DoClearList;
var
i: Integer;
begin
for i := 0 to ListName.Count - 1 do
begin
Dispose(MaterialRec(ListName.Item[i]));
ListName[i] := nil;
end;
ListName.Pack;
end;注意。ListName要注意创建和释放噢晚上请吃饭。。