Home AMX User Forum AMX General Discussion

Unicode?

I was about to implement unicode capability into a module I'm working on so I went to the iPort module v_3_21 which I know uses it and since it's already in my system I figured I'd use it for reference.
DEFINE_CONSTANT

WC_FORMAT_UTF8          = 3 	 //Unicode format type
WC_FORMAT_TP            = 100	//Unicode format type for panels

DEFINE_FUNCTION fnSEND_VTEXT (DEV iTP,nCHAN,CHAR strMSG[]) //All variable text to panel is sent thru this function
     
     {
     STACK_VAR WIDECHAR strSTRING1[600]
     STACK_VAR CHAR strSTRING2[600]
     STACK_VAR INTEGER iTEXT
       
     strSTRING1 = WC_DECODE(strMSG,WC_FORMAT_UTF8,1) ; // Used to Decode 
     strSTRING2 = WC_ENCODE(strSTRING1,WC_FORMAT_TP,1) ;//WC_TP_ENCODE (strSTRING1) should be the same
        
     //SEND_STRING 0,"'R4 Device_ID = ',ITOA(DEVICE_ID(dvTPArry[3]))" //R4 Device is 322
     IF(DEVICE_ID(iTP) < 256) //Is it a G3 Panel in the array?
	  {....................

I first went to the function that uses it and noticed the constants so I went to the constants to see what values they held. I then went to the help section of NS to read about them and found this:
Format:

1 Unicode Encode the data as a Unicode formatted stream. The constant WC_FORMAT_UNICODE is defined as a value of 1 for specifying this format.

2 Unicode BE Encode the data as a Unicode BE (Big Endian) formatted stream. The constant WC_FORMAT_UNICODE_BE is defined as a value of 2 for specifying this format.

3 UTF-8 Encode the data as a UTF-8 formatted stream. The constant WC_FORMAT_UTF8 is defined as a value of 3 for specifying this format.

4 TP Encode the data for use with the UNI TP command. The constant WC_FORMAT_TP is defined as a value of 4 for specifying this format.
So why if the instruction says WC_FORMAT_TP is defined as a value of 4 does the module define WC_FORMAT_TP in the constant section as 100?

Anybody got a clue? Is this just an error in the module? I don't recall ever noticing any problems with displayed text but.....

Comments

  • viningvining Posts: 4,368
    Looking at the Unicode.axi in the AMXShare folder I find:
    WC_FORMAT_ASCII         = 0
    WC_FORMAT_UNICODE       = 1
    WC_FORMAT_UNICODE_BE    = 2
    WC_FORMAT_UTF8          = 3
    WC_FORMAT_TP            = 100
    
    again the WC_FORMAT_TP constant is defined with a value of 100 and not 4 like the help file says. Ok the help files have been wrong before so I guess everyone should make a mental note of that.

    You also need an #include to untilize the Unicode.axi in your modules but I haven't checked to see if it's pulled in automatically to the main code.
    #INCLUDE 'UnicodeLib.axi'
    
    I would have thought the unicode functions would be system functions but they're not. In the 2 modules that have the Unicode I have:
    WC_FORMAT_UTF8          = 3 ;
    WC_FORMAT_TP            = 100 ;
    
    defined in my modules and they are also defined in the #inlcuded Unicode.axi but the iPod module compiles w/o errors but the module I'm working on now has:
    ERROR: C:\Documents and Settings\VAV\My Documents\AMX\Programs\Griffith\UnicodeLib.axi(34): C10220: Symbol [WC_FORMAT_TP] already defined in current scope
    I then noticed that in my module I had:
    WC_FORMAT_TP            = 4 ;
    
    to match the help file, the iPod module still had:
    WC_FORMAT_TP            = 100 ;
    
    So my module through an error because this constant was defined more than once with different values while the iPod module was defined more than once with the same value.

    I guess that means you can defined a constant as many times as you want as long as the value is "constant" or the same?
  • DHawthorneDHawthorne Posts: 4,584
    Definitions inside a module get the instance name tagged on to them internally at run time, so you can duplicate a symbol from your main code in the module without generating an error. Otherwise, you couldn't have muiltiple instances running in the same program ... all the variables, constants, functions, timelines would collide with each other. I just wish the debug tokens did the same ...
  • viningvining Posts: 4,368
    These duplicates are in the same module. 1st defined in the constant section of the module and then pulled in from the #include which is called in the module.

    I think who ever wrote the iPod module defined these 2 constants in the constant secton because the include was added in define start and the functon which used the constants got compiled before the include was pulled in and that through an error saying they weren't defined. As long as the constants have the same value the compiler doesn't seem to care but as soon as you change one value the compiler will throw an"already defined err".
  • viningvining Posts: 4,368
    Ok, back to the constant value for WC_FORMAT_TP being set to 100 in the unicode.axi and not 4 as specified in the help files really makes no sense. The value is only used as a function parameter to select which select active to use for encoding/decoding the string in the function. So this number can be what ever you want it to be since it's not a value used in any calculations or anything. So why go 0, 1, 2, 3, 100 when 4 would be the logical next choice and the one specified in the help file,
    WC_FORMAT_ASCII         = 0
    WC_FORMAT_UNICODE       = 1
    WC_FORMAT_UNICODE_BE    = 2
    WC_FORMAT_UTF8          = 3
    WC_FORMAT_TP            = 100
    

    Makes ya go Hmmm?
Sign In or Register to comment.