DynaDictionary Objects

The DynaDictionary class enables you to access entries in member key dictionary subclasses but to defer the specification of the membership and keys until run time.

Dynamic dictionaries are useful in applications with requirements for:

As with any collection, the size of a dynamic dictionary is limited by the maximum entries for a collection (2^32) or the available disk space provided for the transient database.

Dynamic dictionaries do not offer a facility to sort objects not entirely based on a comparison of embedded attribute values; for example, the ability for you to provide your own sort compare routine is not supported.

In the following example, a dynamic dictionary performs an object sort based on member attributes. The publications property is a collection of Publications. This example shows the use of the reimplemented Dictionary class startKeyGeq method to start the iteration at a specific point and demonstrates passing a variable list of key parameters where the keys are not known at compile‑time.

vars
    dynaDict : DynaDictionary;
    pub      : Publication;
    iter     : Iterator;
begin
    create dynaDict transient;
    // set the membership of our dynamic dictionary
    dynaDict.setMembership(Publication);
    // specify the ytdSales, royalty, and descending pubDate dictionary keys
    dynaDict.addMemberKey("ytdSales", false, false);
    dynaDict.addMemberKey("royalty", false, false);
    // specify descending key so that most recent titles appear first
    dynaDict.addMemberKey("pubdate", true, false);
    // complete key definition
    dynaDict.endKeys(false);
    // copy publication instances into the dynamic dictionary
    publications.copy(dynaDict);
    // display all publications with more than 1000
    // sales (ytd) in sorted order
    iter := dynaDict.createIterator;
    // start the iteration where ytdSales >= 1000
    // since the dynadict has 3 keys we must pass
    // keys to the startKeyGeq method
    dynaDict.startKeyGeq(1000, null, null, iter);
    while iter.next(pub) do
        write pub.name & " " & pub.ytdSales.String &
                   pub.royalty.String & " " & pub.pubdate.String;
    endwhile;
epilog
    // ensure we delete transients
    delete iter;
    delete dynaDict;
end;

For details about the methods defined in the DynaDictionary class, see "DynaDictionary Methods", in Volume 1 of the JADE Encyclopaedia of Classes. For details about passing variable parameters to methods, see "Passing Variable Parameters to Methods", in Chapter 1 of the JADE Developer’s Reference.