How to get dynamically the type of a variable

Discussions specific to Team Developer 5.1.

How to get dynamically the type of a variable

Postby Nicolas D on Mon Mar 03, 2008 1:54 am

hi,
In Ctd there is SalGetDataType( Window_Handle ) to get the type of a Window Handle.
How to get the type of a variable ?
thanks
User avatar
Nicolas D
 
Posts: 24
Joined: Mon Jan 14, 2008 10:33 pm

Re: How to get dynamically the type of a variable

Postby Jeff Luther on Mon Mar 03, 2008 9:14 am

You mean during running of the application??? There is no SAL function to do this, and I have never seen this question before because you do not have access to a list of vars. to figure out, so...

My first answer is: Using a var. naming convention should/will let you know the var. type, but again you don't have access to the names of the vars. during runtime, so I'm not sure I understand your question. In any event, the naming I mean is like:

Boolean: bFoo
DateTime: dt
Number: n
Long String: ls
String: s
Window Handle: hWnd
Custom Control: cc
Funct. Class: oSomeClassType

and so on. Practically every sample of code I have seen uses this convention so there is plenty around to learn from. Otherwise, what do you have in mind??
Jeff Luther
Senior Tech. Support Engineer
Unify Corporation
User avatar
Jeff Luther
 
Posts: 1217
Joined: Thu Nov 08, 2007 11:54 am
Location: Palo Alto, California

Re: How to get dynamically the type of a variable

Postby Christian Schubert on Mon Mar 03, 2008 10:24 am

Hi Nicolas,

you can use SalCompileAndEvaluate to accomplish this. Just use the name of the variable as the expression (first param). The return value will be the type of the variable. Have a look at the help file...

HTH

Christian Schubert
User avatar
Christian Schubert
 
Posts: 86
Joined: Mon Nov 05, 2007 3:15 pm
Location: Mainz, Germany

Re: How to get dynamically the type of a variable

Postby Dave Rabelink on Mon Mar 03, 2008 10:30 am

Nicolas D wrote:hi,
In Ctd there is SalGetDataType( Window_Handle ) to get the type of a Window Handle.
How to get the type of a variable ?
thanks


I use SalCompileAndEvaluate.

This function returns the type of the variable when used as the expression parameter.

Code: Select all
Set nType = SalCompileAndEvaluate( sExpression, nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, FALSE, sContext )
   If nType = EVAL_Number
            ! Variable is a Number
   Else If nType = EVAL_String
            ! Variable is a String
   Else if ntype = EVAL_Date
            ! Variable is a DateTime
   Else If nType = EVAL_Handle
            ! Variable is a Handle


So for instance you want to determine the type of the variable nUserID :

Code: Select all
Set nType = SalCompileAndEvaluate( "nUserID", nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, FALSE, sContext )



Dave

PS Oh, Christian has posted just before me ;)
Regards,
Dave Rabelink
Join & participate on TeamDeveloper Tips & Tricks Wiki
User avatar
Dave Rabelink
 
Posts: 358
Joined: Sat Feb 17, 2007 12:01 am
Location: Gouda, Netherlands

Re: How to get dynamically the type of a variable

Postby Jeff Luther on Mon Mar 03, 2008 10:34 am

Well, there you go. Learn something new every day! Thanks you 2 for the hint!

P.S. Dave, I see this, though:
Else If nType = EVAL_Handle
! Variable is a Handle

meaning you can't tell if it's a File, Session, Sql, Window Handle, right?
Jeff Luther
Senior Tech. Support Engineer
Unify Corporation
User avatar
Jeff Luther
 
Posts: 1217
Joined: Thu Nov 08, 2007 11:54 am
Location: Palo Alto, California

Re: How to get dynamically the type of a variable

Postby Christian Schubert on Mon Mar 03, 2008 11:04 am

Jeff Luther wrote:meaning you can't tell if it's a File, Session, Sql, Window Handle, right?


Hi Jeff,

no, you can't tell. All three types are the same. For example "SalWindowHandleToNumber" also converts file and sql handles...

Christian
Last edited by Christian Schubert on Tue Mar 04, 2008 1:49 am, edited 1 time in total.
User avatar
Christian Schubert
 
Posts: 86
Joined: Mon Nov 05, 2007 3:15 pm
Location: Mainz, Germany

Re: How to get dynamically the type of a variable

Postby Dave Rabelink on Mon Mar 03, 2008 1:07 pm

I was just curious to see if SalCompileAndEvaluate could determine an object.

Code: Select all
Set nType = SalCompileAndEvaluate( "udvTest", nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, FALSE, sContext )


In fact, the function returns here nType = 7 !

This is the list of EVAL constants as described in the manual

Code: Select all
EVAL_Number   = 1
EVAL_String   = 2
EVAL_Date     = 3
EVAL_Handle   = 4
EVAL_Template = 5
EVAL_Set      = 99
EVAL_If       = 100


So what is nType = 7 ?

Another addition.

Code: Select all
Set nType = SalCompileAndEvaluate( "cfcTest", nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, FALSE, sContext )


Will return EVAL_Template (5). In this case cfcTest is a class.
Regards,
Dave Rabelink
Join & participate on TeamDeveloper Tips & Tricks Wiki
User avatar
Dave Rabelink
 
Posts: 358
Joined: Sat Feb 17, 2007 12:01 am
Location: Gouda, Netherlands

Re: How to get dynamically the type of a variable

Postby Nicolas D on Wed Mar 05, 2008 12:49 am

So ...
Thanks a lot to everybody !!!
User avatar
Nicolas D
 
Posts: 24
Joined: Mon Jan 14, 2008 10:33 pm


Return to Team Developer 5.1

Previous topic || Next topic

Who is online

Users browsing this forum: No registered users and 1 guest

cron