动态引用PowerBuilder结构值

时间:2011-04-20 18:39:11

标签: powerbuilder

在PowerBuilder 12 Classic中,我试图动态访问/设置结构的属性/元素。知道怎么做吗?

我正在尝试构建一个开发人员实用程序,它将检查任意结构(在编译时未知的结构)以查找其元素。我可以通过访问结构VariableList的{​​{1}}属性来获取元素的名称和类型。但是知道元素的名称和类型对我没有帮助,因为我知道无法按名称访问元素。

例如,假设我的结构ClassDefinition包含两个字符串元素:st_personfirst_name。有没有办法表达价值?像这样远程:

last_name

我真的希望我不会错过一些明显的东西。

2 个答案:

答案 0 :(得分:2)

不,你没有遗漏任何东西,除非你在PBNI中编程。从我所听说过的PBNI,您应该能够做到这一点,但我不是关于PBNI的可靠信息来源。

你有没有理由使用结构?听起来你想要的是接近哈希表或命名项集。我在PFC的一个链表上建立了我自己的命名项集,其中每个节点中的键是名称,数据是......好吧,数据。非常粗略,我有一个of_get(字符串as_name)返回any,和of_set(字符串as_name,任何aa_value)。那样,我可以

myList = CREATE n_cst_NamedItemSet
myList.of_Set ("first_name", "John")
myList.of_Set ("last_name", "Smith")

并且在另一端收到此信息(这对于OpenWithParm以及其他期望一个参数的事情非常有用)

is_FirstName = of_Get ("first_name")
is_LastName = of_Get ("last_name")

更进一步,我有of_Defined(字符串as_name)来测试是否存在,而of_Get(字符串as_name,ref任何aa_value)返回返回成功的整数(如果找到),以启用对象之间的可选参数和松散契约等内容。

还有更多,但这应该让你去。如果你没有使用PFC,并且你不想从中雕刻出链接列表,那么你可能没有理由不能在一对并行的无界数组上构建它:一个用于键的字符串和一个用于键的字符串。数据。或者,使用String键列替换DataStore(DataStore使得更快地搜索键)和Number列作为无界Any阵列的索引。

祝你好运,

特里。

答案 1 :(得分:1)

我正在添加另一个答案来回应Hugh的新目标(他在2011年5月20日的评论)将字符串转换为枚举值。我有代码生成代码,将字符串转换为枚举和枚举为字符串,以PFC样式(如n_cst_conversion)完成。在构造函数中,为了适应 版本的PowerBuilder,您唯一需要做的就是更新枚举分类列表。 (我通常从PB的对象浏览器的报告中得到这个,通过一些常规的文本搜索和替换。)它并不完美,但它会让你到下一次进行重大升级。

祝你好运,

特里。


<强> n_cst_enumscripts

InstanceVariables

string is_EnumTypes[]

事件构造函数返回long

is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "accessiblerole"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "alignment"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "argcallingconvention"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "arrangeopen"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "arrangetypes"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "band"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "border"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "borderstyle"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "button"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "charset"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "clipboardformat"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "connectprivilege"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "converttype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "cputypes"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "datetimeformat"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "dbnotification"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "direction"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "displaysizemode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "dragmodes"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "dwbuffer"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "dwconflictresolution"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "dwitemstatus"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "encoding"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "errorreturn"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "exceptionaction"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "fileaccess"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "filelock"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "filemode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "filetype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "fillpattern"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "fontcharset"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "fontfamily"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "fontpitch"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "graxisdatatype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grcolortype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grdatatype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grgraphtype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grlegendtype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grobjecttype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grresettype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grroundtotype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grscaletype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grscalevalue"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grsorttype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grsymboltype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "grtictype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "helpcommand"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "htickmarks"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "icon"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "inkcollectionmode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "inkcompressionmode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "inkeditstatus"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "inkmode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "inkpentip"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "inkpersistenceformat"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "inkpiceditmode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "inkpicstatus"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "keycode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "languageid"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "languagesortid"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "libdirtype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "libexporttype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "libimporttype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "linestyle"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "listviewview"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "location"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "mailfiletype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "maillogonoption"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "mailreadoption"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "mailrecipienttype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "mailreturncode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "maskdatatype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "menuitemtype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "menumergeoption"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "menustyle"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "metadatatype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "moncaldisplaystate"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "moncalrepeattype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "object"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "olefunctioncalltype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "omactivatetype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "omactivation"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "omcontentsallowed"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "omdisplaytype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "omlinkupdateoptions"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "orientationtype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "ostypes"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "paragraphsetting"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "parmtype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "pbtypes"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "pdfmethod"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "pointer"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "profileroutinekind"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "registryvaluetype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "richtexttoolbaractivation"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "rowfocusind"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "saveastype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "savemetadata"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "scriptkind"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "seektype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "setpostype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "sizemode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "spacing"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "sqlfunction"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "sqlpreviewfunction"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "sqlpreviewtype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "stgreadmode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "stgsharemode"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "syncprocesstype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "tabposition"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "textcase"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "textstyle"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "timerkind"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "toolbaralignment"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "toolbarstyle"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "traceactivity"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "tracecategory"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "treenavigation"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "trigevent"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "typecategory"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "userobjects"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "valschemetype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "varaccess"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "variablecardinalitytype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "variablekind"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "vtextalign"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "vtickmarks"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "webpagingmethod"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "weekday"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "windowanimationstyle"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "windowstate"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "windowtype"
is_EnumTypes[UpperBound (is_EnumTypes) + 1] = "writemode"

* function of_enumprototypes()返回字符串*

integer li_EnumCount, li_Enum
string ls_Prototypes
TypeDefinition ltd_Enum
EnumerationDefinition led_Enum

ls_Prototypes = "Add this list to the forward prototypes section of pfc_n_cst_conversion~r~n~r~n"

li_EnumCount = UpperBound (is_EnumTypes)
FOR li_Enum = 1 TO li_EnumCount
    ls_Prototypes += "public function string of_string (" + is_EnumTypes[li_Enum] + " aenum_Value)~r~n"
NEXT
FOR li_Enum = 1 TO li_EnumCount
    ls_Prototypes += "public function integer of_" + is_EnumTypes[li_Enum] + " (string as_Value, " + is_EnumTypes[li_Enum] + " ae_Value)~r~n"
NEXT
ls_Prototypes += "~r~n~r~n"

RETURN ls_Prototypes

* function of_enumscripts()返回字符串*

integer li_EnumCount, li_Enum, li_ValueCount, li_Value
string ls_Scripts, ls_Name
TypeDefinition ltd_Enum
EnumerationDefinition led_Enum

li_EnumCount = UpperBound (is_EnumTypes)
FOR li_Enum = 1 TO li_EnumCount
    ltd_Enum = FindTypeDefinition (is_EnumTypes[li_Enum])
    led_Enum = ltd_Enum

    ls_Scripts += "public function string of_string (" + is_EnumTypes[li_Enum] + &
        " aenum_Value);//////////////////////////////////////////////////////////////////////////////~r~n" + &
        "//~r~n" + &
        "//~tFunction:~t~tof_String~r~n" + &
        "//~r~n" + &
        "//~tAccess:~t~t~tpublic~r~n" + &
        "//~r~n" + &
        "//~tArguments:~r~n" + &
        "//~tae_icon~t~t~tThe " + is_EnumTypes[li_Enum] +" value to be converted to a string.~r~n" + &
        "//~r~n" + &
        "//~tReturns:  ~t~tstring~r~n" + &
        "//~t~t~t~t~t~tA string representation of the " + is_EnumTypes[li_Enum] + " value.~r~n" + &
        "//~t~t~t~t~t~tIf aenum_Value is NULL, the function returns NULL.~r~n" + &
        "//~t~t~t~t~t~tIf aenum_Value is Invalid, the function returns '!'.~r~n" + &
        "//~r~n" + &
        "//~tDescription:~tConverts the " + is_EnumTypes[li_Enum] + " enumerated datatype to a~r~n" + &
        "//~t~t~t~t~t~treadable string representation.~r~n" + &
        "//~r~n" + &
        "//////////////////////////////////////////////////////////////////////////////~r~n" + &
        "string ls_Null~r~n~r~n// Check parameter~r~nIF IsNull (aenum_Value) THEN~r~n~tSetNull (ls_Null)~r~n~tRETURN ls_Null~r~nEND IF~r~n~r~n"
    ls_Scripts += "CHOOSE CASE aenum_Value~r~n"
    li_ValueCount = UpperBound (led_Enum.Enumeration)
    FOR li_Value = 1 TO li_ValueCount
        ls_Name = led_Enum.Enumeration[li_Value].Name
        ls_Scripts += "~r~n~tCASE " + ls_Name + "!;RETURN ~"" + ls_Name + "~"~r~n"
    NEXT
    ls_Scripts += "~r~nEND CHOOSE~r~n~r~n// Invalid parameter~r~nRETURN ~"!~"~r~nend function~r~n~r~n"
NEXT

FOR li_Enum = 1 TO li_EnumCount
    ltd_Enum = FindTypeDefinition (is_EnumTypes[li_Enum])
    led_Enum = ltd_Enum

    ls_Scripts += "public function integer of_" + is_EnumTypes[li_Enum] + &
                " (string as_Value, " + is_EnumTypes[li_Enum] + " ae_Value);//////////////////////////////////////////////////////////////////////////////~r~n" + &
                "//~r~n" + &
                "//~tFunction:  ~t~tof_" + is_EnumTypes[li_Enum] + "~r~n" + &
                "//~r~n" + &
                "//~tAccess:  ~t~tpublic~r~n" + &
                "//~r~n" + &
                "//~tArguments:~r~n" + &
                "//~tas_Value~t~t~tThe string value to be converted to " + is_EnumTypes[li_Enum] + " datatype value.~r~n" + &
                "//~tae_Value~t~t~tA " + is_EnumTypes[li_Enum] + " variable passed by reference which will~r~n" + &
                "//~t~t~t~t~t~t~thold the " + is_EnumTypes[li_Enum] + " value that the string value was~r~n" + &
                "//~t~t~t~t~t~t~tconverted to.~r~n" + &
                "//~r~n" + &
                "//~tReturns: ~t~tinteger~r~n" + &
                "//~t~t~t~t~t~t1 if a successful conversion was made.~r~n" + &
                "//~t~t~t~t~t~tIf as_Value value is NULL, function returns -1~r~n" + &
                "//~t~t~t~t~t~tIf as_Value value is Invalid, function returns -1~r~n" + &
                "//~r~n" + &
                "//~tDescription:  Converts a string value to a " + is_EnumTypes[li_Enum] + " data type value.~r~n" + &
                "//~r~n" + &
                "//////////////////////////////////////////////////////////////////////////////~r~n" + &
                "//~r~n" + &
                "//~tRevision History~r~n" + &
                "//~r~n" + &
                "//~tPFC OS Issues~r~n" + &
                "//~t6~tAuto-generated intial version~r~n" + &
                "//~t~tTerry Voth: http://www.techno-kitten.com~r~n" + &
                "//~r~n" + &
                "//////////////////////////////////////////////////////////////////////////////~r~n" + &
                "//~r~n" + &
                "//~tCopyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.~r~n" + &
                "//~tAny distribution of the PowerBuilder Foundation Classes (PFC)~r~n" + &
                "//~tsource code by other than Sybase, Inc. and its subsidiaries is prohibited.~r~n" + &
                "//~r~n" + &
                "//////////////////////////////////////////////////////////////////////////////~r~n" + &
                "as_Value = Lower (as_Value)~r~n~r~n// Check parameter~r~nIF IsNull (as_Value) THEN~r~n~tRETURN -1~r~nEND IF~r~n~r~n"
    ls_Scripts += "CHOOSE CASE as_Value~r~n"
    li_ValueCount = UpperBound (led_Enum.Enumeration)
    FOR li_Value = 1 TO li_ValueCount
        ls_Name = led_Enum.Enumeration[li_Value].Name
        ls_Scripts += "~r~n~tCASE ~"" + ls_Name + "~", ~"" + ls_Name + "!~"~r~n~t~tae_Value = " + ls_Name + "!~r~n~t~tRETURN 1~r~n"
    NEXT
    ls_Scripts += "~r~nEND CHOOSE~r~n~r~n// Invalid parameter~r~nRETURN -1~r~nend function~r~n~r~n"
NEXT

RETURN ls_Scripts