Traversing Uniface component at run-time

Author: roger.wallin@abilita.fi (rogerw)

Hi, Is it possible to include code into a form, that traverse the entities from the outermost entity to the innermost entity getting the value of every field, having no beforehand info about the entities or fields? You should be able to get the name and structure of the entities and the name of all fields. It's not urgent to start with the topmost entity. I think this has been discussed before.....  Regards RogerW. 

2 Comments

  1. Thanks Uli and FiresongKt. The central words seem to be $componentinfo and $entinfo or then ComonentToStruct. I'll test it. Regards RogerW.


    Author: rogerw (roger.wallin@abilita.fi)
  2. I have a global proc called cp_ents_to_str, it calls itself recusrively, so the name is important. It needs to be passed a start entity but I'll put the code to call it for a component below.  I have this as an export, but there no longer seems to be a method for uploading sample to download, so message me if you'd like it emailed to you.  params    string p_ent_name : IN    string p_occs_string : OUT endparams variables    numeric v_hold_occ    string v_string, v_item, v_sub_item, v_inner endvariables v_hold_occ = $curocc(p_ent_name) setocc p_ent_name,1 forentity p_ent_name    putlistitems/occ v_item,p_ent_name    forlist v_inner in $entinfo(p_ent_name,"INNER")       if(v_inner != "")          call cp_ents_to_str(v_inner, v_sub_item)          if(v_sub_item != "")             v_item = $concat(v_item,"·;",v_sub_item)          endif       endif    endfor    putitem v_string,-1,v_item endfor if($entinfo(p_ent_name,"SUPERTYPE") != "")    putitem/id p_occs_string, $entinfo(p_ent_name,"SUPERTYPE"), v_string else    putitem/id p_occs_string, p_ent_name, v_string endif   And to call it for the entire component :- forlist v_entname in $componentinfo("","OUTERENTITIES")    call cp_ents_to_str(v_entname, v_string) endfor   To unpack it again, there's another global proc called cp_str_to_ents params    string p_ent_name : IN    string p_string : IN endparams variables    string v_string, v_inner, v_keys, v_item endvariables   if($entinfo(p_ent_name,"SUPERTYPE") != "")    getitem/id v_string, p_string,$entinfo(p_ent_name,"SUPERTYPE") else    getitem/id v_string, p_string,p_ent_name endif if($status > 0)    while( !$empty(p_ent_name))       remocc p_ent_name    endwhile endif if(v_string != "")    forlist v_item in v_string       creocc p_ent_name,-1       setocc p_ent_name,-1       forlist v_keys in $keyfields(p_ent_name,1)          @v_keys=$item(v_keys,v_item)          delitem/id v_item, v_keys       endfor       retrieve/x p_ent_name       getlistitems/occ v_item,p_ent_name       forlist v_inner in $entinfo(p_ent_name,"INNER")          call cp_str_to_ents(v_inner,v_item)       endfor    endfor endif


    Author: Iain Sharp (i.sharp@pcisystems.co.uk)