关于ListView指针Data介绍
赋值:
type
PAllHidenDate = ^AllHidenDate;
AllHidenDate = record
PriceID: Integer;
OrderNumber: string;
State: Integer;
PriceData: WideString;
end;
var
HidenData: PAllHidenDate;
begin
with lvDataViewAll.Items.Add do
begin
HidenData := New(PAllHidenDate);
HidenData.PriceID := StrToIntDef(Node.Attributes['PriceID'], 0);
HidenData.State := StrToIntDef(Node.Attributes['State'], 1);
HidenData.OrderNumber := Node.Attributes['PriceNumber'];
HidenData.PriceData := Node.XML;
Data := HidenData;
end;
end;
释放Data:
procedure TOrderQuotation.lvDataViewAllDeletion(Sender: TObject; Item:
TListItem);
var
HidenData : PAllHidenDate;
begin
if Item.Data = nil then Exit;
HidenData := Item.Data ;
Dispose(HidenData);
end;
释放内存时需要和赋值时的指针类型相同,不然会出错内存泄漏
PViewItemState = ^TViewItemState;
TViewItemState = Record
ViewItemid: Integer;
end;
var
nLoop: integer;
li: TListItem;
pp: PViewItemState;
begin
for nLoop:=0 to 10 do
begin
li:=ListView1.items.add;
li.caption:=IntToStr(nLoop);
new(pp);
li.Data:=pp;
end;
end;
需释放内存
var
I : integer;
begin
for I := 0 to TreeView.Items.Count - 1 do
begin
Dispose(TreeView.Items[I].Data);
TreeView.Items[I].Data := nil;
end;
end;