Uniface User Forum

 View Only
  Thread closed by the administrator, not accepting new replies.
  • 1.  Uniface 9: Uniface Structs: hurdle 2

    ROCKETEER
    Posted 11-19-2018 11:40
    No replies, thread closed.

    Uniface Structs: hurdle 2

    Author: gianni.sandigliano@unifacesolutions.com (gianni)

    Hi Unifacers, In a struct member names can have repetitions on same level so the only way to refer for sure to a specific member on a certain level is by its $index. Extending this concept through levels the only unique identification of each struct member in a struct it is through its "path of $index(es)" starting from the root of the struct...something like: putmess vStruct->*{1}->*{3}->*{2}->whatever This instruction is a complex and fixed one: it refers to a specific number of levels. Uniface variables can be used instead of hardcoded positional numbers like in: putmess vStruct->*{vPosLevel1}->*{vPosLevel2}->*{vPosLevel3}->whatever on each level but number of tree levels are 'de facto' hardcoded into code. It is unclear to me: is it possible to refer to a specific member of a struct using a single Uniface variable or (better) a single Uniface list, whatever is the number of levels? Something like: putmess vStruct->UnifaceList->whatever where UnifaceList could be: "1Gold;3Gold;2" or "1=*Gold;3=*Gold;2=*". I've looked into documentation and digged many examples without finding any hint. Levels can only be hardcoded? An example from the field: I need to search a specific name (tag) in my struct but this name could be positioned on level 3 or 4 depending from how the original XML was generated. Trying to implement a generic search into a struct I would like to pass the member name I am looking for and have it back a reference to first instance of that name in the struct, travelling the struct in one of the two possible ways: - sequentially: from top to bottom or backward - by levels: all level 1 then all level 2 ecc. or backward (this should be probably better in my current case) Let's imagine I give back a Uniface list like the one I've mentioned before ("1Gold;3Gold;2"); how could be used to reach and manipulate the required member through its "path of $index(es)"? Thanks in advance for any answer / suggestion / hint. Gianni



  • 2.  RE: Uniface 9: Uniface Structs: hurdle 2

    ROCKETEER
    Posted 11-19-2018 11:40
    No replies, thread closed.

    Hi Gianni, Not sure that I can follow you completely here. One way to search a Struct is by using a recursive loop. There's an example in the Uniface Library: > Programming in Uniface > Proc Language > Structs > Example: Looping Over Structs Please note that the params and variables block of the entry PRINT_STRUCT are missing. The sample is correct here: > Programming in Uniface > Proc Language > Structs > Struct Code Examples

    params<br /> struct pStruct: in ; A reference can refer one or more structs <br /> string pMargin: in ; Initial margin + indenting for deeper levels <br /> endparams <br /> variables <br /> numeric i, N <br /> endvariables <br />

    I'm using this loop usually as a starting point when I want to manipulate or process a Struct. In your case you just have to add a parameter for the element name you are looking for. You then can search for the element on each level. And once you've found the element you can process or manipulate it. But your idea with the Uniface list will not really work. And I don't really understand what you would like to achieve with this. Sorry. As said, I would use a recursive loop to search and access a member with (e.g.) a specific name. Hope this helps. Daniel


    Author: diseli (daniel.iseli@uniface.com)