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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute external or dinamyc code

Status
Not open for further replies.

Irwin1985

Programmer
Feb 2, 2017
44
ES
By Google Translate:

Greetings Community,

I raise my problem:

In a normal and current EXE, I want to execute an external code that I create and execute from a button, it is an accounting business rule, in short, let's say the code is this:

Rule.txt

Public oForm
oForm = CreateObject ("Accounting.Format")
oForm.Show (1)

************************************************** ****************************************

From my button I set it in a variable memo and execute it like this:
Code:
Local lnHandle, lcScript As Memo
lnHandle = FOPEN ("c: \ Rule.txt")
IF lnHandle> 0
   DO WHILE! FEOF (lnHandle)
      IF EMPTY (lcScript)
         lcScript = FGETS (lnHandle)
      ELSE && EMPTY (lcScript)
         lcScript = lcScript + CHR (13) + FGETS (lnHandle)
      ENDIF && EMPTY (lcScript)
   ENDDO
ELSE && lnHandle> 0
ENDIF && lnHandle> 0
FCLOSE (lnHandle)

* I already have the external code located in rule.txt and I execute it like this:
Code:
IF! EMPTY (lcScript)
   = EXECSCRIPT (lcScript)
ELSE &&! EMPTY (lcScript)
ENDIF &&! EMPTY (lcScript)

The error I get is "Failed to create an instance of the class. Can not find C: \ systempath \ vcx \ accounting.vcx"

I have read that to use the libraries of another EXE should be included as:

Code:
SET CLASSLIB miClass IN miExe.exe ADDITIVE ALIAS miAlias

The problem is that the code located in Regla.txt does not belong to an EXE but I run it inside the EXE itself.

The library is already declared in the main exe so I do not know what else it can be. If for example I take the code of Regla.txt and execute it inside the click of the button then it marks perfectly but the idea is to have the dynamic code since each client has different needs.

Thank you...!
 
Accounting.Format sounds like being an OLE class, I just tried and you can't give a classlib an alias name containing a point.

What I do to instantiate classes from another EXE or APP is making use of NEWOBJECT() instead. The scripts in Rule.txt / Regula.txt will then need to hardcode such paths, so I see the advantage of aliasing, but you can only use plain names, no multipart names with points.

Also, the Syntax of SET CLASSLIB always is [tt]SET CLASSLIB TO some.vcx IN some.exe[/tt]

As you use it, Accounting.Format looks like an OLEPUBLIC form, that would only work when compiling the PJX containing that accounting.vcx as an EXE, not as a DLL. Only a COM SERVER EXE can provide visual classes. OLE DLLs use the mutithreadable vfp9t.dll runtime not providing any visual classes and behavior.

When defining olepublic classes, any code using them won't need to SET CLASSLIB first, those classes are found by being registered.

Bye, Olaf.
 
You didn't ask about this, but if this is VFP 6 or later, you can change all this code:

Code:
Local lnHandle, lcScript As Memo
lnHandle = FOPEN ("c: \ Rule.txt")
IF lnHandle> 0
   DO WHILE! FEOF (lnHandle)
      IF EMPTY (lcScript)
         lcScript = FGETS (lnHandle)
      ELSE && EMPTY (lcScript)
         lcScript = lcScript + CHR (13) + FGETS (lnHandle)
      ENDIF && EMPTY (lcScript)
   ENDDO
ELSE && lnHandle> 0
ENDIF && lnHandle> 0
FCLOSE (lnHandle)

to:

Code:
lcScript = FileToString("c: \ Rule.txt")

Tamar
 
Thanks EveryBody, I've solved my problem by including a PRG on the Project.

Bye..!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top