• TList


    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

    type
    t1 = class
    a: string;
    b: string;

    end;
    TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    private
    procedure FreeList(List: TList);
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    //释放类List中的对象
    procedure TForm1.FreeList(List: TList);
    var
    I: Integer;
    begin
    for I := 0 to List.Count -1 do
    begin
    if Assigned(TObject(List.Items[I])) then
    TObject(List.Items[I]).Free;
    end;
    List.Clear;
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
    //
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    var
    I: Integer;
    tt: t1;
    List1, List2: TList;
    begin
    List1 := TList.Create;
    List2 := TList.Create;
    try
    for I := 0 to 3 do
    begin
    tt := t1.Create;
    tt.a := 'a ' + IntToStr(I);
    tt.b := 'b ' + IntToStr(I);
    List1.Add(tt);
    end;
    List2.Assign(List1);
    for I := 0 to list2.Count -1 do
    begin
    ShowMessage(t1(list2.Items[I]).a);
    end;
    finally
    FreeList(List1);
    end;
    end;

  • 相关阅读:
    记一个在训练模型过程中自己给自己挖的坑
    Fast R-CNN学习总结
    SPP-net论文总结
    R-CNN学习总结
    3Sum Closest
    3Sum
    整数转为罗马数字
    Container With Most Water
    决策树
    回文数判断
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/3468177.html
Copyright © 2020-2023  润新知