Actually i want to pass a variable (that may be any type) to a function. depanding on the data-type I want to perform a task.
Since you have to define the input/output types in a function, you can only really pass a handle to the function using that.
You could define your variables as fields in a temp-table, as stated above, and pass a handle into the function.
Alternatively, if the variable is displayed in a frame, then passing the handle into a function will work, using SELF:HANDLE or variable:handle.
function f_test returns char (inp_handle as widget-handle):
def var testreturn as char no-undo.
def var datatypelist as char initial
"Buffer-field,Combo-box,Editor,Fill-in,Radio-set,Rectangle,Selection-list,Slider,Text,Toggle-box".
if lookup(inp_handle:type,datatypelist) > 0 then
case inp_handle:data-type:
when "integer" then testreturn = "integer".
when "decimal" then testreturn = "decimal".
otherwise testreturn = inp_handle:data-type + " is not a number".
end case.
return testreturn.
end function.
def var a as char.
form a with frame f1.
display f_test (a:handle in frame f1) form "x(30)".
But, you could pass the variable as a string with another parameter stating type.
def var a as char.
def var b as int.
def var c as dec.
function f_test returns char (inp_value as char, inp_type as char):
case inp_type:
when "integer" then .
when "decimal" then .
end case.
end function.
message
f_test (a,"character")
f_test (string (b),"integer")
f_test (string (c),"decimal")
view-as alert-box.