jueves, 23 de junio de 2011

The fifth dimension

Working with dimensions can be a little head scratching at times, but being told to place business logic around them can be a wee bit more frustrating. I needed to deactivate an element of the dimension array - a control on a form. I started off with what I knew, which was of course very wrong, and placed the below in the init method of the form:
    projTable_ds.object(fieldnum(ProjTable, Dimension[5])).enabled(false);
There are two things that spit in my face above. The first is that it doesn't compile. The second is that the fifth dimension is indicated explicitly as a number, the code below will explain better:
    int         dimProject;
    ;
    dimProject  = Dimensions::code2ArrayIdx(SysDimension::Proyecto);
So now we can get the index of our 'Project' dimension. The code is more maintainable than just using the integer index directly.
Finally the end result:
    FieldId     dimFieldId, extFieldId;
    DictField   dictField;
    int         dimProject;
    ;

    dimProject  = Dimensions::code2ArrayIdx(SysDimension::Proyecto);
    
    dimFieldId  = fieldnum(ProjTable, Dimension);
    extFieldId  = fieldId2Ext(dimFieldId, dimProject);
    projTable_ds.object(extFieldId).enabled(false);
So the Global::fieldId2Ext() method is what was missing which returns an extended FieldId - a fieldId that includes the the array index.

Heads up to Palle Agermark on this one.

No hay comentarios:

Publicar un comentario