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
leemarcAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
I think it's because of Custom. Custom is a non-visual class.
0
leemarcAuthor Commented:
Good one - It is a custom. But How can I add a clas based upon custom to my library programatically?
0
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
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
0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

leemarcAuthor Commented:
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.
0
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
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.
0
pcelbaCommented:
The question is why to create 200+ classes for each table. Isn't a table name property/parameter enough in this case?
0
leemarcAuthor Commented:
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.
0
leemarcAuthor Commented:
as for 200+ clases per table, I meant 200+ tables each with CRUD requirements
0
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
The class should remain the same. You initialize each instance of the class for that specific table.

oClass = CreateObject("ClassName")
oClass.TableAlias = "MyTableAlias1"
0
leemarcAuthor Commented:
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
0
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
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.
0
leemarcAuthor Commented:
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
0
pcelbaCommented:
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.
0
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
The CREATE CLASS opens a dialog for you to choose a name to create the new class using Visual Objects.
0
leemarcAuthor Commented:
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
0
pcelbaCommented:
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?
0
leemarcAuthor Commented:
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.
0
pcelbaCommented:
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

0
leemarcAuthor Commented:
I will give this a try and let you know tomorrow
0
Olaf DoschkeSoftware DeveloperCommented:
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

0
Olaf DoschkeSoftware DeveloperCommented:
The error you get from SaveAsClass is not about the visual/nonvisual aspect of the class, the same would fail if you DEFINE CLASS ... As container, even though a container is a visual class. It's the difference of a VCX vs a PRG (DEFINE CLASS) even though both have the same base class "custom". SaveAsClass only works, if the first level (aside from the VFP base classes) is a VCX class. So waht you can do much easier perhaps is change all the DEFINE CLASS lines of your prgs or memo field contents to define classes not based on custom, but on eg _custom, which is a class within the VCX. (This is what pcelba said):

1. create a VCX with a base custom class, call that _custom
2. change the custom classes of your classes defined by DEFINE CLASS
as DEFINE CLASS ybc AS _custom OF xyz.vcx

Besides that change in the class definition you can use your code 1:1

The following does that and the difference in the end result is, that the class now is a subclass of _custom insted of the base custom class.
* Create a VCX base class (this opens the class designer)
* This really is just a on time thing, you can also do that manually:

Create Class _custom Of [d:\tmp\someclasses.vcx] As Custom Nowait
* Don't add anything this time:
Activate Window "Class Designer" && change in localized VFP versions
Keyboard '{CTRL+S}'
Keyboard '{CTRL+F4}'
DoEvents

* Now your SaveAsClass code, modified to use _custom instead of custom as the base class:

oPW = CREATEOBJECT("sqlPassWord")
oPW.SaveAsClass(d:\tmp\sbtclasses.vcx,"sqlPassword2")

DEFINE CLASS sqlPassWord As _custom Of d:\tmp\someclasses.vcx

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

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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leemarcAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
FoxPro

From novice to tech pro — start learning today.