Link to home
Start Free TrialLog in
Avatar of leemarc
leemarc

asked on

Programically Adding Class to a VCX file

I havea class library that I have created over the years that contains mainly comm function/sprocedure to my accoutning package.  All are custom classes based on custom.
I am trying to add to this library programatically as follows [class definition follows:

oPW = CREATEOBJECT("sqlPassWord")
opw.Save()
opw.Select()
opw.Delete()
opW.SaveAsClass("sbtclasses.VCX","sqlPassword")

DEFINE CLASS sqlPassWord as Custom

      FUNCTION Save
            MESSAGEBOX("Saving",0+48)
      ENDFUNC

      FUNCTION Select
            MESSAGEBOX("Selecting",0+48)
      ENDFUNC
      
      FUNCTION Delete
            MESSAGEBOX("Deleteing",0+48)
      ENDFUNC
      
ENDDEFINE

all I get is the message ""one of the members of this call is based on a nonvisual class. Cannot write .VCX File"

I have been lookign all over the web and nary a real defin ition of the probelm - can you be of guidance
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

I think it's because of Custom. Custom is a non-visual class.
Avatar of leemarc
leemarc

ASKER

Good one - It is a custom. But How can I add a clas based upon custom to my library programatically?
You can copy the code and put it in a prg you call it libary or class.

I have class.prg where I have my custom classes.

I reference it in my start.prg by:

SET PROCEDURE TO ..\library\library.prg, ..\library\class.prg
Avatar of leemarc

ASKER

understood - however it is not really what we wanted to do.  Our intent is to create a class to create code programmatically so i don't have to create crud thru a cut and paste process for 200 + tables. Oh, yeah, they are all old legacy dbfs NOT in a DBC container.
Then I suggest to store it in a memo field in a table and use it to generate code. That's what I would do.
The question is why to create 200+ classes for each table. Isn't a table name property/parameter enough in this case?
Avatar of leemarc

ASKER

The idea is t move my existing system to sql without having to rewrite the world. DBF existing in VFP and tabel exist in the database in sql.  My partner has created a crud creator that is consitant thru out. All that is passed is a table name.  His code builds the Inset, update, select and delete usps.  I want to build consistent code that will call the usp's we create in sql so that the work is done on the server and returned to my vfp9 programs.
Avatar of leemarc

ASKER

as for 200+ clases per table, I meant 200+ tables each with CRUD requirements
The class should remain the same. You initialize each instance of the class for that specific table.

oClass = CreateObject("ClassName")
oClass.TableAlias = "MyTableAlias1"
Avatar of leemarc

ASKER

I know that - I just wanted to buidl the class programatically and add it to my existing library programatically as descrivbed above.  I just keep getting the same error "one of the members of this call is based on a nonvisual class. Cannot write .VCX File".

I can figure out what a non-visual class is - but have no idea what it has to do with the object.saveasclass method n the first place, so I cannot get past this and add the new class to the existing library using the code I sent to you
You can either create it using CREATE CLASS and save it as VCX or you can put the code in a prg and instantiate as many instances as needed.
Avatar of leemarc

ASKER

using create class opens a dialog box.  I would have thought my code would be able to simple use the object.saveasclass to ad the new class to the existing library
do you have a small sample of what you are suggesting please
As written above:

opW.SaveAsClass("sbtclasses.VCX","sqlPassword")

will work for you if the original class is created as VCX in class designer.

The parameter is better solution.
The CREATE CLASS opens a dialog for you to choose a name to create the new class using Visual Objects.
Avatar of leemarc

ASKER

Understood. But that is not what I am looking. I simply want to add a class and method programatically to my existing VCX.  How can I do this without the error noted above
It seems my comments are not uploaded... or is it so difficult to create one class as VCX in designer and then all other classes programatically?
Avatar of leemarc

ASKER

Do I understand you to say create the library in the IDE and then add the classes programatically.
If so, the sbtclasses.vcx does already exist.  How do I programatically add classes to it without the error.
The classes will be based upon custom class and just contain some code
Please give me a more detailed sample if you can.
You have the code already.

In the Command Window write:

CREATE CLASS sqlPassWord OF d:\path\testclass.VCX as Custom

It will create the class in IDE. You have to add all methods and properties you need and then you may use following code to create instances programatically:

SET CLASSLIB TO d:\path\testclass.VCX

oPW = CREATEOBJECT("sqlPassWord")
opW.SaveAsClass("d:\path\testclass","sqlPassword2")
opW.SaveAsClass("d:\path\testclass","sqlPassword3")
opW.SaveAsClass("d:\path\testclass","sqlPassword4")

* etc.

Open in new window

Avatar of leemarc

ASKER

I will give this a try and let you know tomorrow
Another way would be not to instanicate and SAVEASCLASS, but use the WriteMethod() methods to write method code into visual classes. The following is such an approach to automate the visual class designer. An advantage is, that you can base your classes on the custom base class instead of a class within a VCX.

Bye, Olaf.
* Create a VCX base class (this opens the class designer)
Create Class someclass Of [d:\tmp\someclasses.vcx] As Custom Nowait
* Get a reference to the class in the class designer
ASelObj(laCustom,1)
loCustom = laCustom[1]

* automate creating methods within this visual class:
Text To lcMethod NoShow
MESSAGEBOX("Saving",0+48)
EndText
loCustom.WriteMethod("Save",lcMethod,.T.)

Text To lcMethod NoShow
MESSAGEBOX("Selecting",0+48)
EndText
loCustom.WriteMethod("Select",lcMethod,.T.)

Text To lcMethod NoShow
MESSAGEBOX("Deleting",0+48)
EndText
loCustom.WriteMethod("Delete",lcMethod,.T.)

* Save the class
Activate Window "Class Designer" && change in localized VFP versions
Keyboard '{CTRL+S}'
Keyboard '{CTRL+F4}'
DoEvents

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Olaf Doschke
Olaf Doschke
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leemarc

ASKER

Olaf - you understood what I was trying to do - wonderful.
I tested the first idea and it works just fine.  I suspected the 2nd concept will also work.
The only thign I don't recognize is DO Events