Tony Pelton wrote:
>> Classes with indexed properties work and look like associative arrays.
> 
> how do index'ed properties help you store objects by a key ?

Something like:

type
  THash = class(TObject)
  protected
    function GetItem(AKey: string): string;
    procedure SetItem(AKey, NewValue): string;
  public
    property Items[AKey: string]: string read GetItem
        write SetItem default;
  end;

The 'default' keyword makes the array usable "on the instance":

var
  Hash: THash;
begin
  Hash := ...
  Hash['sun'] := 'yellow';
  Hash['sky'] := 'blue';
  { etc ... }
end.

Micha

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to