ImageEn, unit hyieutils

TIEDictionary.Insert

TIEDictionary.Insert


Declaration

procedure Insert(key: WideString; value: TObject); overload;
procedure Insert(key: WideString; value: WideString); overload;
procedure Insert(key: WideString; value: integer); overload;
procedure Insert(key: WideString; value: double); overload;
procedure Insert(key: WideString; value: boolean); overload;
procedure Insert(key: WideString; value: TIEDictionary); overload;
procedure Insert(key: WideString; value: TObjectList); overload;


Description

Maps the specified key to the specified object or value in this dictionary.

Parameter Description
key A string key
value Object/value to store. Do NOT free it. The dictionary owns the object: it will be automatically disposed


Examples

// Dump dictionary content as XML
var
  dict: TIEDictionary;
begin
  dict := TIEDictionary.Create();
  dict.Insert('doublekey', 10.1);
  dict.Insert('integerkey', 100);
  dict.Insert('stringkey', 'hello');
  dict.Insert('bool_true', true);
  dict.Insert('bool_false', false);
  dict.Insert('dict', TIEDictionary.Create());
    dict.GetDictionary('dict').Insert('one', 1);
    dict.GetDictionary('dict').Insert('two', 'two');
  dict.Insert('list', TObjectList.Create());
    dict.GetList('list').Add( TIEDictionaryValueWideString.Create('mike') );
    dict.GetList('list').Add( TIEDictionaryValueWideString.Create('robert') );
    dict.GetList('list').Add( TIEDictionaryValueWideString.Create('john') );
    dict.GetList('list').Add( TIEDictionaryValueInteger.Create(2013) );

  memo1.Text := dict.Dump(ieplXML);

  dict.free;
end;


// Save a PNG file as a lossless WebP with lossless compression (using ImageMagick plug-in)
var
  imDict: TIEDictionary
begin
  ImageEnView1.IO.LoadFromFile( 'D:\Image.png' );
  imDict := TIEDictionary.Create();
  imDict.Insert( 'webp:lossless', true );
  imDict.Insert( 'webp:method', 0 );
  imDict.Insert( 'webp:auto-filter', true );
  ImageEnView1.IO.Params.Dict.Insert( 'ImageMagick', imDict );
  ImageEnView1.IO.SaveToFile( 'D:\Image_out.webp' );
  // Note: Do NOT free imDict. It is now owned by ImageEnView1.IO.Params.Dict, who will dispose of it
end;

// List items in "ImageMagick" dictionary
var
  dict: TIEDictionary;
  curr: TIEStrStrEnumerator;
  key, val: String;
begin
  dict := TIEDictionary( ImageEnView1.IO.Params.Dict.Get( 'ImageMagick', True, False ));
  if dict = nil then
    exit;

  curr := TIEStrStrEnumerator.Create();
  try
    while dict.GetNext( curr ) do
    begin
      key := curr.item.key;
      val := IEDictValueToStr( curr.item.value );
      Memo1.Lines.Add( key + '=' + val );
    end;
  finally
    curr.Free();
  end;
end;
{
Result:
webp:method=0
webp:lossless=true
webp:auto-filter=true
}