zoukankan      html  css  js  c++  java
  • 关于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; 

  • 相关阅读:
    C语言I博客作业04
    解决@ResponseBody注解返回的json中文乱码问题
    自定义 Helper Method
    webapi 学习1
    分布式事务TransactionOptions及设置msdtc
    了解websocket是什么
    用postman 来实现post方式返回json数据
    异步 Controller
    asp.net mvc Filter
    asp.net mvc Controller Factory
  • 原文地址:https://www.cnblogs.com/mingdep/p/2313189.html
Copyright © 2011-2022 走看看