类 / 下标(索引器方法)

uses System.Generics.Collections;

type
  TSettings = class
  private
    class var FValues:
      TDictionary<stringstring>;
    class function GetItem(
      const Name: string): stringstatic;
    class procedure SetItem(const Name,
      Value: string); static;
  public
    class constructor Create;
    //class-level indexed property
    class property Items[const Name: string]:
      string read GetItem write SetItem;
  end;

class constructor TSettings.Create;
begin
  FValues := TDictionary<string, string>.Create;
end;

class function TSettings.GetItem(
  const Name: string): string;
begin
  if not FValues.TryGetValue(Name, Resultthen
    Result := '';
end;

class procedure TSettings.SetItem(
  const Name, Value: string);
begin
  WriteLn('Adding ', Name, ': ', Value);
  FValues.AddOrSetValue(Name, Value);
end;

begin
  TSettings.Items['host'] := '192.168.100.1';
  TSettings.Items['port'] := '3306';

  WriteLn('host is ',
    TSettings.Items['host']);
end.