Ignore:
Timestamp:
Oct 28, 2010, 4:52:53 PM (14 years ago)
Author:
george
Message:
  • Added: Generic class TGDictionary and TGPair. Specialized class TDictionaryString.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Demo/UMainForm.pas

    r71 r72  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, ListInteger, ListString;
     9  ComCtrls, ListInteger, ListString, DictionaryString;
    1010
    1111type
     
    1414
    1515  TMainForm = class(TForm)
     16    ButtonDictionaryString: TButton;
    1617    ButtonIntegerList: TButton;
    1718    ButtonStringList: TButton;
    1819    MemoOutput: TMemo;
     20    procedure ButtonDictionaryStringClick(Sender: TObject);
    1921    procedure ButtonIntegerListClick(Sender: TObject);
    2022    procedure ButtonStringListClick(Sender: TObject);
     
    4648begin
    4749  MemoOutput.Clear;
    48   WriteLn('TIntegerList test');
     50  WriteLn('TListInteger test');
    4951  List := TListInteger.Create;
    5052  with List do try
    51     SetArray([10, 20, 30, 40]);
     53    AddArray([10, 20, 30, 40]);
    5254    WriteLn('Implode: ' + Implode(',', IntToStr));
    5355    Clear;
     
    6870end;
    6971
     72function StringPairToStr(Pair: TPairString): string;
     73begin
     74  Result := Pair.Key + ':' + Pair.Value;
     75end;
     76
     77procedure TMainForm.ButtonDictionaryStringClick(Sender: TObject);
     78var
     79  Dictionary: TDictionaryString;
     80begin
     81  MemoOutput.Clear;
     82  WriteLn('TDictionaryString test');
     83  Dictionary := TDictionaryString.Create;
     84  with Dictionary do try
     85    Add('Key1', 'Value1');
     86    Add('Key2', 'Value2');
     87    Add('Key3', 'Value3');
     88    WriteLn('Implode: ' + Implode(',', StringPairToStr));
     89    WriteLn('Values[Key2]: ' + Values['Key2']);
     90    WriteLn('Values[Key2] = None');
     91    Values['Key2'] := 'None';
     92    WriteLn('Values[Key2]: ' + Values['Key2']);
     93    WriteLn('Values[Key0]: ' + Values['Key0']);
     94    WriteLn('Keys[2]: ' + Keys[2]);
     95  finally
     96    Free;
     97  end;
     98end;
     99
    70100function StrToStr(Value: string): string;
    71101begin
     
    78108begin
    79109  MemoOutput.Clear;
    80   WriteLn('TStringList test');
     110  WriteLn('TListString test');
    81111  List := TListString.Create;
    82112  with List do try
    83     SetArray(['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven']);
     113    AddArray(['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven']);
    84114    WriteLn('Count: ' + IntToStr(Count));
    85115    WriteLn('Implode: ' + Implode(',', StrToStr));
Note: See TracChangeset for help on using the changeset viewer.