How to get dynamically the type of a variable

Discussion forum about all things Gupta, OpenText and the community.
Nicolas D
France
Posts: 100
Joined: 25 Jun 2018, 12:24
Location: St Pierre, France

How to get dynamically the type of a variable

Post by Nicolas D » 03 Mar 2008, 09:54

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

Jeff Luther

Re: How to get dynamically the type of a variable

Post by Jeff Luther » 03 Mar 2008, 17:14

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??

cschubert
Germany
Posts: 867
Joined: 23 May 2018, 11:26
Location: Germany

Re: How to get dynamically the type of a variable

Post by cschubert » 03 Mar 2008, 18:24

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

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3207
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: How to get dynamically the type of a variable

Post by Dave Rabelink » 03 Mar 2008, 18:30

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

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Jeff Luther

Re: How to get dynamically the type of a variable

Post by Jeff Luther » 03 Mar 2008, 18:34

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?

cschubert
Germany
Posts: 867
Joined: 23 May 2018, 11:26
Location: Germany

Re: How to get dynamically the type of a variable

Post by cschubert » 03 Mar 2008, 19:04

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 Anonymous on 04 Mar 2008, 09:49, edited 1 time in total.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3207
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: How to get dynamically the type of a variable

Post by Dave Rabelink » 03 Mar 2008, 21:07

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

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Nicolas D
France
Posts: 100
Joined: 25 Jun 2018, 12:24
Location: St Pierre, France

Re: How to get dynamically the type of a variable

Post by Nicolas D » 05 Mar 2008, 08:49

So ...
Thanks a lot to everybody !!!

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests