Page 1 of 2

A function that runs a command specified as a parameter

Posted: Wed Feb 09, 2022 10:29 pm
by Eugene Lutsenko
hi, all!
Is it possible to create a function that will execute a command specified as a parameter? It is possible to use a block of code in this function.

Re: A function that runs a command specified as a parameter

Posted: Thu Feb 10, 2022 12:56 am
by skiman
Hi,

I suppose this is what you want.

Code: Select all

Function startfunction(cFunction,cPara1,cPara2)
Local  bBlock := "{|| "+cFunction +"('"+cPara1+"','"+cPara2+"')}"
Local uResult
bBlock := &(bBlock)
uResult := eval(bBlock)
return uResult
or

Code: Select all

Function startfunction(cFunction,cPara1,cPara2)
Local bBlock := "{|cPara1,cPara2| " + cFunction+"(cPara1,cPara2) }"
Local bFunction
    if IsFunction(cFunction)    
  	bBlock := &(bBlock)
	eval(bBlock,cPara1,cPara2)
    else
        msgbox("Function not available")
    endif
    return nil

Re: A function that runs a command specified as a parameter

Posted: Thu Feb 10, 2022 10:19 am
by Eugene Lutsenko
hi, skiman !

Let's say I need to run an indexing command, but with a SPECIFIC field name specified directly by text, and not as a variable value and without using operators like FIELDGET, etc. How to do this using this function?
https://www.xbaseforum.de/viewtopic.php?f=42&t=12208

Re: A function that runs a command specified as a parameter

Posted: Thu Feb 10, 2022 10:32 pm
by Auge_Ohr
hi,
you want to use a "UDF" in Index when using ADS ... hm

Re: A function that runs a command specified as a parameter

Posted: Fri Feb 11, 2022 1:33 am
by skiman
Hi,

Something as this?

Code: Select all

Function createindex(cIndexFileName,cFieldnameAsText)
dbCreateIndex( (cIndexFileName), cFieldnameAsText)
return

Re: A function that runs a command specified as a parameter

Posted: Fri Feb 11, 2022 2:30 am
by Auge_Ohr
hi Chris,

like under SQL you can not use a UDF with "own" Function using ADS as it is EVAL() "on-Server"
you must have a Db-Server like LetoDb or NetIO which are written in xBase (but not Xbaase++ )

in German Forum Eugene was told to reduce it

Code: Select all

   index on padr( feld, 25,"." )
to work with ADS

Re: A function that runs a command specified as a parameter

Posted: Fri Feb 11, 2022 4:22 am
by Tom
There is no UDF in what Chris mentioned. Eugene looks for a way to create index files depending on the data situation, like: aIndexKeyFieldArray[n] contains the name of the field to be indexed. Since DbCreateIndex accepts textes as the index expression, this value can be used to create the index.

Re: A function that runs a command specified as a parameter

Posted: Fri Feb 11, 2022 11:17 am
by Auge_Ohr
hi Tom,

Eugene have point to this Thread https://www.xbaseforum.de/viewtopic.php?f=42&t=12208
where he want to use a Macro so i wrote
in German Forum Eugene was told to reduce it

Re: A function that runs a command specified as a parameter

Posted: Fri Feb 11, 2022 11:20 pm
by Eugene Lutsenko
hi!

What form of access to the DbCreateIndex() function is equivalent to the command: INDEX ON File_Date+File_Time TO StartAidos?

The DbCreateIndex() function is good. But I haven't had time to check how it works with ADS yet. I hope it's good. But I had another idea. I thought that if there was such a function that would execute the command given to it as a parameter, then there would be no questions at all. Moreover, she did not call an existing function, namely, she took it from the parameter and launched it. Like this:

ExecuteParameter("INDEX ON File_Date+File_Time TO StartAidos")

Re: A function that runs a command specified as a parameter

Posted: Sat Feb 12, 2022 2:07 am
by skiman
Hi Eugene,

Which comes to the first sample.

Code: Select all

Function startfunction(cText)
Local  bBlock := "{|| "+cText +"')}"
Local uResult
bBlock := &(bBlock)
uResult := eval(bBlock)
return uResult
So you can do startfunction( "dbCreateIndex( (cIndexFileName), cFieldnameAsText)")