Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you store functions in data files

Status
Not open for further replies.

fbizzell

Programmer
Jul 3, 2000
217
I am using Clipper 5.2e and would like to know if there is anyway to store user defined functions in data files and execute them from there?<br><br>
 
Not sure exactly what you are trying to do, but I have stored codeblocks as text strings in a table, then read the table in converting the textstrings into codeblocks and storing them into an array.&nbsp;&nbsp;Later the array element is executed as a codeblock since it contains codeblocks.
 
What I am trying to do is store a function several functions into a database table and then whenever the table is accessed read the program or function name and execute it...For example I have several label printing programs..<br><br>label1<br>label2<br>label3 etc..<br><br>So if the user select customer 3 he gets label3 program, so I want to execute it then..<br><br>Not sure how to explain it...I know what I want to do but hard to tell someone else..
 
If I got this correct, you want to store the function name in a database, then select the appropriate function from the database and execute it.<br><br>You could store the function name in a codeblock then store the codeblock in the database as a string.&nbsp;&nbsp;Read the string in and execute the codeblock.<br><br>Store the function in a string like this:<br>{ ¦p1,p2,...,px¦ function(p1,p2,...,px) }<br>where p1, p2, etc. are parameters.<br>When you evaluate this codeblock it will execute the function.<br><br>Then read in the string from the table and trim it (rtrim) and use macro evaluation (&)to turn it into a codeblock.&nbsp;&nbsp;The & actually converts the string into a codeblock that can be executed.&nbsp;&nbsp;It could look like this (I will store it to a memvar MyCodeBlock):<br>MyCodeBlock:= &(rtrim(TableOfCodeblocks-&gt;fieldname)).<br><br>Then you execute the codeblock which will execute the function like this:<br>eval(MyCodeBlock, p1, p2, ..., px)<br>where p1, p2, etc. are parameters, if you have any, to pass to the function.<br><br>I just happen to read my codeblocks from a table into an array since I have so many tables open.
 
Thanks, this is very helpful.&nbsp;&nbsp;I will try using the method you outlined.&nbsp;&nbsp;Will let you know how it turns out.<br><br>Frank
 
Thanks waterstart.....<br><br>Your method worked perfectly.&nbsp;&nbsp;Many years ago I was a frequent user of the clipper forum on compuserve and when that went away....I felt lost...it is good to know that I can get the same kind of help on this forum.&nbsp;&nbsp;I really appreciate your help.<br><br>Frank<br>
 
Translate:

Puedes hacerlo inclusive solo sobre un archivo de texto usando lo bloques de codigo (CODE BLOCK),

While .....
cBlockToExec := GetLine(hFile)
&(cBlockToExec)
End

Si quieres realizar operaciones complejas, tienes que generar un comgrama interpretador o semi compilador, yo genere uno en el cual pasaba de una instruccion sencilla a una compleja y luego a un bloque de codigo.

Ejemplo:

Escribe &quot;Texto&quot; lo convertia a -> __DevOut(&quot;Texto&quot;, ,)
Escribe <Total> Formato &quot;999.99&quot; -> __DevOut(nTotal, &quot;999.99&quot;, )

LPTRed <Remisiones> -> NetQueue(nRemisiones)

Etc.
etc.

Es algo complejo pero, puedes generar tus propios archivos de programas para realizar reportes complejos, o formatos de documento que tienden a ser muy variables sin modificar el codigo de tu programa ejecutable.

Zea
ramonzea@yahoo.com [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top