Changeset 37 for Generics/UMainForm.pas


Ignore:
Timestamp:
Aug 4, 2010, 1:49:55 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Vylepšena obecná třída seznamu.
  • Přidáno: Soubory jednotek pro další obecné třídy.
Location:
Generics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Generics

    • Property svn:ignore
      •  

        old new  
        11lib
        22project1.exe
         3heaptrclog.trc
         4Test.exe
  • Generics/UMainForm.pas

    r36 r37  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   GenericList;
     9  GenericList, GenericSet;
    1010
    1111type
     12
     13  { TMyObject }
     14
     15  TMyObject = class
     16    Name: string;
     17    constructor Create(AName: string);
     18  end;
     19
     20  TMyObjectList = specialize TGList<Integer, TMyObject>;
     21
    1222  { TMainForm }
    1323
     
    1525    Memo1: TMemo;
    1626    procedure FormCreate(Sender: TObject);
     27    procedure FormDestroy(Sender: TObject);
    1728    procedure FormShow(Sender: TObject);
    1829  private
    1930    { private declarations }
    2031  public
    21     IntegerList: TIntegerList;
    22     StringList: TStringList;
     32    IntegerList: TIntegerGList;
     33    StringList: TStringGList;
     34    MyObjectList: TMyObjectList;
    2335  end;
    2436
     
    3446procedure TMainForm.FormCreate(Sender: TObject);
    3547begin
    36   IntegerList := TIntegerList.Create;
    37   StringList := TStringList.Create;
     48  IntegerList := TIntegerGList.Create;
     49  StringList := TStringGList.Create;
     50  MyObjectList := TMyObjectList.Create;
     51end;
     52
     53procedure TMainForm.FormDestroy(Sender: TObject);
     54begin
     55  IntegerList.Destroy;
     56  StringList.Destroy;
     57  MyObjectList.Destroy;
    3858end;
    3959
     
    5373  IntegerList.Add(12121);
    5474  IntegerList.Add(5);
     75
     76  for I := 0 to StringList.Count - 1 do
     77    Memo1.Lines.Add(StringList[I]);
     78
    5579  StringList.Add('One');
    5680  StringList.Add('Two');
    5781  StringList.Add('Three');
    5882
    59   for I := 0 to StringList.Count - 1 do
    60     Memo1.Lines.Add(StringList[I]);
    61 
    6283  IntegerList.Sort(@IntegerListCompare);
    6384  for I := 0 to IntegerList.Count - 1 do
    6485    Memo1.Lines.Add(IntToStr(IntegerList[I]));
     86
     87  MyObjectList.Add(TMyObject.Create('Object 1'));
     88  MyObjectList.Add(TMyObject.Create('Object 2'));
     89  MyObjectList.Add(TMyObject.Create('Object 3'));
     90
     91  for I := 0 to MyObjectList.Count - 1 do
     92    Memo1.Lines.Add(MyObjectList[I].Name);
     93end;
     94
     95{ TObjectItem }
     96
     97constructor TMyObject.Create(AName: string);
     98begin
     99  Name := AName;
    65100end;
    66101
Note: See TracChangeset for help on using the changeset viewer.