Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Instantiate a class from an .EXE
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01046171
Message ID:
01046248
Vues:
13
This message has been marked as the solution to the initial question of the thread.
Geraldo!

>
> ...But it don't work
>
> loTest = NewObject("MyClassName", "MyPRGName.PRG", "MyExecutableName.EXE")
>
> If I have a class in a program(.EXE) and I want to use this class of an
> another I can use it with the NewObject() function. But if the class are stored in a .PRG
> file it don't work and display an error message.
>

I had this problem too, as I do many of my class declarations in PRG. However I came to a pretty simple solution that does work perfectly well:

In the EXE I have created a Class in a VCX that is just a Wrapper that instantiates the Object from
the PRG-Class:

It merely only has one Method:

(In my case I have packed several reports (in my case PRG's, I Do work with VPE) into an EXE)

This is all there is: (code from the classbrowser)
**************************************************
*-- Class:        areport (d:\programm\schedule\vcx\reporthandler.vcx)
*-- ParentClass:  custom
*-- BaseClass:    custom
*-- Time Stamp:   03/08/04 03:45:05 PM
*
DEFINE CLASS areport AS custom


    *-- Name of the Class to Instantiate
    PROTECTED cclass
    cclass = ""
    *-- Name of th ClassLib to take the class from
    PROTECTED cclasslib
    cclasslib = "SCHEDREPORTS.FXP"
    Name = "areport"


    *-- Return the Report-Object
    PROCEDURE getreport
        lparameters    tcClass, tcClassLib
        tcClass     = iif(vartype(tcClass) = "C", tcClass, This.cClass)
        tcClassLib     = iif(vartype(tcClassLib) = "C", tcClassLib, This.cClasslib)


        return NewObject(tcClass, tcClassLib)
    ENDPROC


ENDDEFINE
*
*-- EndDefine: areport
**************************************************
As You see, there is barely anything in it.

From another EXE You can now instanciate any PRG-based Class.

in my case I subclassed the aReport and preSet the properties. By that I did not need to expose the classnames and libs but You could simply add the parameters to the Newobject-Statement
loMyObject = NewObject("aReport", "ReportHandler.vcx", "MyEXE.exe", <PRG_Class>, <PRG_FileName>)
HTH
Regards from Berlin

Frank

Dietrich Datentechnik (Berlin)
Softwarekombinat Teltow (Teltow)

Frank.Dietrich@dd-tech.de
DFPUG # 327
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform