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

How do I turn a PRG class definition file into a VFP object?

Status
Not open for further replies.

fmoore1111

Programmer
Sep 7, 2012
2
US
I found some neat code in this forum to create a combo box subclass that I need. However, for life of me cannot figure how to change this PRG file to a VFP VCX file- never done it before. Any suggustions what I need to do?

Code:
**************************************************
*-- Class:        cbonotinlist 
*-- ParentClass:  combobox
*-- BaseClass:    combobox
*-- Time Stamp:   12/12/99 06:38:09 PM
*-- ALLOWS SELECTION OF AN ITEM NOT IN THE COMBO'S LIST TO BE USED AS ITS CONTROLSOURCE...ONLY WORKS IF THE COMBO'S BOUND COLUMN IS 1
*
DEFINE CLASS cbonotinlist AS cboqfill

  *-- Used to save the control source of the combo before the control is unbound
  ccontrolsource = ""
  Name = "cbonotinlist"

  *-- Called from Valid...it updates the "bound" field
  PROCEDURE updatecontrolsource
  LOCAL lcAlias, lcControlSource
  WITH This
    IF ! EMPTY( .cControlSource )
      lcAlias = JUSTSTEM( .cControlSource )
      IF UPPER( ALLTRIM( lcAlias ) ) = 'THISFORM'
        lcControlSource = .cControlSource
        STORE .DisplayValue TO &lcControlSource 
      ELSE
        REPLACE ( .cControlSource ) WITH .DisplayValue IN ( lcAlias )
      ENDIF
    ENDIF
  ENDWITH
  ENDPROC

  *-- Updates display value from the field in the underlying table if this is a "bound" control
  PROCEDURE refreshdisplayvalue
  LOCAL lcControlSource
  WITH This
    IF ! EMPTY( .cControlSource )
      lcControlSource = .cControlSource
      .DisplayValue = &lcControlSource 
    ENDIF
  ENDWITH
  ENDPROC

  PROCEDURE Init
  IF DODEFAULT()
    WITH This
      .cControlSource = .ControlSource
      .ControlSource = '
    ENDWITH
  ENDIF
  ENDPROC

  PROCEDURE Valid
  This.UpdateControlSource()
  ENDPROC

  PROCEDURE Refresh
  This.RefreshDisplayValue()
  ENDPROC

  PROCEDURE GotFocus
  IF LOWER( This.Parent.BaseClass ) = 'column'
    *** This is needed so it will work in a grid
    Combobox::GotFocus()
    This.RefreshDisplayValue()
    NODEFAULT
  ELSE
    DODEFAULT()
  ENDIF
  ENDPROC

ENDDEFINE
 
You only have part of the equation since this class is a subclass of another. You need the entire hierarchy or you'll have to copy the code into a class of your own making.

But assuming you have the whole shooting match, you can just instantiate it and call its SaveAsClass method:

Set Procedure To "your.prg"
ox = CreateObject("cbonotinlist")
ox.SaveAsClass("your.vcx","classname")
 
I second dan, why change it to vcx, when you can also use it this way. There is no automatism that would work, unfortunately.
What you can try is create a new visual class based on the prg class by typing this in the command window:

CREATE CLASS mycombo OF d:\myproject\libs\mynew.vcx AS cbonotinlist From d:\prgclasses\yourfoundcode.prg

In general you just do it manually, the prg has all info in it, class name, defined methods and event code, it's just a bit cumbersome to copy that over into a vcx class, but it's straight forward, isn't it?

Bye, Olaf.
 
Guys,

Jeez, I LIKE my little VCX's. Once setup, I just toss them on a form and I am off an running! And no more coding.

Thanks you for your help. it got me on to the right way to do this.

First, i created a new subclass from the base VCX combo box in the CLASSES tab of the project, and added it to the CLASS I wanted it associated with. Just click on the class you want to draw from, enter the new Class name, specify what type of class it is (in this case a combo box) then direct the save to the CLASS VCX field you want it saved (defaults to the current VCX file, but I wanted it with others of a type). In my case I did not use the name cboqfill, preferring to stick with the sole name cbonotinlist for my subclass name.

Then, using the code above I either updated or revised methods (Proceduress) named in the code with the corresponding methods in the new VCX and then added the PROCEDURES / Methods not existing in the VCX file but in the PRG file. Make sure the names are EXACT. Don't copy in PROCEDURE <name> and ENDPROC - not necessary.

Finally I added the one Property ccontrolsource with a empty value. What shocked me was it worked the first time I tried it! If you hand enter text in the Combo Box, it stays!

One note on the above code: In the INIT PROCEDURE

.ControlSource = '

should be:

.ControlSource = ''

Again, thanks for the help.

Frank
 
I don't think you understood what both Olaf and I tried to tell you.

This class is a subclass of cboqfill:

Code:
DEFINE CLASS cbonotinlist AS cboqfill

If you have the class definition for cboqfill (and all of its dependencies), you can use the three lines of code I showed *or* the single line of code Olaf showed, and have your VCX ready to go.

BUT, not having the parent class you're free to do the copy/pasting that you did. Note that most subclasses depend on behaviors defined in their parent classes. You will NOT have those behaviors. Your mileage may vary.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top