![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Type coercion (dereferenc?) and enumerates Topic Summary: Created On: 17-Aug-2004 18:07 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: Try translating "no avail" into something tangible, such as "illegal if DXL error" or "it fails the if check". o."Enum" is not a string, its an internal attrRef type. Convert ..err.. coerce it to a string using o."Enum" "": if (o."Enum" "" == "A") - Louie Little snippetts of code are OK in the message. Longer ones should be attached via the [Attach Code] button, sibling to [Reply to Thread]. | |
![]() |
|
Greetings!
I am cutting my teeth on DXL. I have a strong background in many other languages, but I seem to be having trouble figuring out some basic programming things. First of all enumerates. When I'm using a non mulit-select enumerate, I can assign it to a string, which results in coercion from some internal type to a string. Then I can do stuff with it like compare it. However, if I simply try to use it, it doens't goet coerced as I expect. Let's assume I have an enum of {A, B, C}. I want to do this: (BTW: I can't find the markup tag for code, so bear with me...) Object o = my object if (o."Enum" == "A") { // Do somehting cool. } Now, I've tried reversing the o."Enum" and the "A" equality operator, but to no avail. I've tried coercing with 'string', parenthesis, etc. Again, to no avail. How does one get this thing to be a string without the manual assignment? Thanks for any help. |
|
![]() |
|
![]() |
|
Try translating "no avail" into something tangible, such as "illegal if DXL error" or "it fails the if check".
o."Enum" is not a string, its an internal attrRef type. Convert ..err.. coerce it to a string using o."Enum" "": if (o."Enum" "" == "A") - Louie Little snippetts of code are OK in the message. Longer ones should be attached via the [Attach Code] button, sibling to [Reply to Thread]. |
|
![]() |
|
![]() |
|
<< Try translating "no avail" into something tangible, such as "illegal if DXL error" or "it fails the if check". o."Enum" is not a string, its an internal attrRef type. Convert ..err.. coerce it to a string using o."Enum" "": if (o."Enum" "" == "A") - Louie >> Louie, Thanks for the quick response! You're right, I apologize for not being specific with my description. For the sake of clarity, my script was generating an error. The error was "-E- DXL: <Line:8> incorrect arguments for (==)". I tried appending the empty quotes to coerce it (i.e. o."Enum" "") and it works. Is there another syntax that is cleaner or more standard? Like: string(o."Enum") or o."Enum".string or *o."Enum" or something like that? That extra set of quotes is certainly not intuitive. -Andrew |
|
![]() |
|
![]() |
|
There are no C like casts in DXL. So you are stuck with appending the empty string.
You will soon get the hang of adding empty strings all over the place! This works for strings, but for comparing other typed attribute values you will need to assign them to a variable before comparison. if (o."Approved") // illegal bool app = o."Approved" if (app) // okay There I go again, mouthing off before my first coffee of the day. Ignore this reply and read Paul's, which makes more sense;. ------------------------- Tony Goodman http://www.smartdxl.com Edited: 18-Aug-2004 at 08:36 by Tony Goodman |
|
![]() |
|
![]() |
|
Type conversion:
stringOf, intOf, realOf can convert one type to another. If you want to cast, use (string otherType), not string(otherType), for instance when doing a get from an array, always cast the return to ensure you use the correct (overloaded) function (see p135 of the 7.0sp1 DXL manual): string a = (string get(ary, idx_x, idx_y)) ------------------------- Paul dot Tiplady at TRW dot com TRW Automotive |
|
![]() |
|
![]() |
|
I don't know and cannot find the internal type of "attrRef", but if it exists it would look something like "attributeRef_". If you found it, you could write a function:
string stringOf(attributeReference_ ar) { return(ar "") } You can now write a function: string stringOf(Object obj, string NameAttr) { return(obj.NameAttr "") } and also write: bool boolOf(Object obj, string NameAttr) { bool Value = obj.NameAttr return(Value) } These functions could also check to insure that NameAttr has the correct "type". - Louie |
|
![]() |
|
![]() |
|
I'll try this, it certainly would make it more readable.
Thanks! |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Type coercion (dereferenc?) and enumerates
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.