A function that runs a command specified as a parameter

This forum is for eXpress++ general support.
Message
Author
User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

A function that runs a command specified as a parameter

#1 Post 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.

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

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

#2 Post 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
Best regards,

Chris.
www.aboservice.be

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

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

#3 Post 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

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

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

#4 Post by Auge_Ohr »

hi,
you want to use a "UDF" in Index when using ADS ... hm
greetings by OHR
Jimmy

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

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

#5 Post by skiman »

Hi,

Something as this?

Code: Select all

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

Chris.
www.aboservice.be

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

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

#6 Post 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
greetings by OHR
Jimmy

User avatar
Tom
Posts: 1173
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

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

#7 Post 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.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

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

#8 Post 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
greetings by OHR
Jimmy

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

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

#9 Post 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")

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

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

#10 Post 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)")
Best regards,

Chris.
www.aboservice.be

Post Reply