gpt4 book ai didi

listview - Delphi Tlistview 最后一行的问题

转载 作者:行者123 更新时间:2023-12-02 16:55:21 25 4
gpt4 key购买 nike

我有一个包含一些数据的 ListView,它工作正常,除非我尝试从最后一行获取数据,在这种情况下它会返回随机数据。

我有一个函数,可以将对象(类中的对象列表)添加到 ListView 中,然后在另一个函数之后从数据库中删除数据并再次填充 ListView 。

//这里我填充 ListView

procedure TFrameEinExpression.Fill_Rows;
var
itm : TFormulaFeatures;
i : integer;
begin
lvModels.Clear;
EinExpression.LoadFeatureList;

if (not Assigned(EinExpression)) or (EinExpression.FeatureList.Count = 0) then
Exit;
lvModels.Items.BeginUpdate;

try
for i := 0 to EinExpression.FeatureList.Count - 1 do
with lvModels.Items.Add do
begin
itm := TFormulaFeatures(EinExpression.FeatureList.Items[i]);
Data := TFormulaFeatures(EinExpression.FeatureList.Items[i]);
Caption := IntToStr(itm.Posicion);
SubItems.Add(BoolToStr(itm.Presencia, True));
SubItems.Add(itm.Descripcion);
SubItems.Add(IntToStr(itm.Idcaract1));
end;
finally
lvModels.Items.EndUpdate;
if Assigned(itm) then
itm.Free;
end;
end;



//Here I perform the action (it works fine except for the last row)


if (Assigned (lvModels.Selected)) and (Assigned (lvModels.Selected.Data)) then

//This already doesn't have anything inside
showmessage('Desc :'+ TFormulaFeatures(lvModels.Selected.Data).Descripcion);

begin
BDMultiEP.SQLExecute('DELETE from [EXPRESSION] WHERE (idcaract=:Z) AND
(idcaract1=:Y)', [EinExpression.IDCARACT,
TFormulaFeatures(lvModels.Selected.Data).IDCARACT1]);
end;


//after this i take the values from the DB to the class and populate the List View again.
LoadFeatureList;
Fill_Rows;

在显示消息(用于测试)中,我有字段描述,但最后一个是什么时候我没有任何内容。

最佳答案

这一行if Assigned(itm) then itm.Free; 释放EinExpression.FeatureList 的最后一项。

由于 itm 不对该对象的生命周期负责,因此这是最后一个列表项中丢失数据的最可能原因。

删除该行。

关于listview - Delphi Tlistview 最后一行的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55626414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com