Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create code form OCX
Message
From
20/08/2007 12:22:36
 
 
To
17/08/2007 22:19:00
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01248795
Message ID:
01249148
Views:
31
Sure, you can do this, but you have to manually mirror the methods using access and assign methods for the properties, and wrapper methods for the object's methods. Here's the start of a class I use to wrap ChilKat's FTP control (I use their controls rather than Winsock, CDO, etc., as I have more control over what happens over Windows' versions, etc.). You should be able to get the idea of what I'm doing from this, in terms of the properties and the methods.
**************************************************
*-- Class:        pspftp (c:\vfp9lib\classes\pspftp.vcx)
*-- ParentClass:  custom
*-- BaseClass:    custom
*-- Time Stamp:   01/23/07 11:51:05 AM
*
#INCLUDE "c:\vfp9lib\classes\pspftp.h"
*
DEFINE CLASS pspftp AS custom


	*-- Flag used for the Dir Listing currently in aDirItems
	cfileordir_dirlisting = ""
	*-- When a connection is established, cHostname, cUsername, and cPassword are filled  in automatically.
	chostname = ""
	clasterrorhtml = ""
	clasterrortext = ""
	clasterrorxml = ""
	*-- Filled in when a connection is made
	cpassword = ""
	*-- Session log kept if the lKeepSessionLog property is set.
	csessionlog = ""
	*-- Filled in when a connection is made
	cusername = ""
	*-- The CaseMatters flag that pertains to the current dir listing contained in aDirItems
	lcasematters_dirlisting = .F.
	*-- Whether the FTP object is currently connected to the host.
	lconnected = .F.
	*-- Accessing resets to .F.: be sure to check after each routine that doesn't return success (e.g., directory_change())
	lerror = .F.
	*-- If set to .t., keeps a session log that can be retrieved from the cSessionLog property
	lkeepsessionlog = ""
	Name = "pspftp"
	*-- Number of directory items retrieved on the last Directory Listing by the FTP object;  corresponds to number of rows in aDirItems
	ndiritems = 0
	*-- Holds the FTP COM object
	oftp = ""

	*-- Holds the directory items; #defines are in pspftp.h
	DIMENSION adiritems[1,1]


	PROCEDURE chostname_access
		*To do: Modify this routine for the Access method
		RETURN THIS.oFTP.Hostname
	ENDPROC


	PROCEDURE chostname_assign
		LPARAMETERS vNewVal
		*!*	*To do: Modify this routine for the Assign method
		*!*	THIS.chostname = m.vNewVal
	ENDPROC


	PROCEDURE clasterrorhtml_access
		*To do: Modify this routine for the Access method
		RETURN THIS.oFTP.LastErrorHTML
	ENDPROC


	PROCEDURE clasterrortext_access
		*To do: Modify this routine for the Access method
		RETURN THIS.oFTP.LastErrorText
	ENDPROC


	PROCEDURE clasterrortext_assign
		LPARAMETERS vNewVal
		*!*	*To do: Modify this routine for the Assign method
		*!*	THIS.clasterrortext = m.vNewVal
	ENDPROC


	PROCEDURE clasterrorxml_access
		*To do: Modify this routine for the Access method
		RETURN THIS.oFTP.LastErrorXML
	ENDPROC


	PROCEDURE clasterrorxml_assign
		LPARAMETERS vNewVal
		*!*	*To do: Modify this routine for the Assign method
		*!*	THIS.clasterrorxml = m.vNewVal
	ENDPROC


	*-- Connect to a site, with username and password if required.
	PROCEDURE connect_to
		LPARAMETERS tcSite, tcUserName, tcPassword

		tcSite = IIF(UPPER(tcSite) = "FTP://",SUBSTR(tcSite,7),tcSite)
		tcUserName = Param_Val(tcUserName, "")
		tcPassword = Param_Val(tcPassword, "")

		THIS.oFTP.HOSTNAME = tcSite
		THIS.oFTP.Username = tcUserName
		THIS.oFTP.PASSWORD = tcPassword

		IF !THIS.oFTP.CONNECT() = 1
			RETURN .F.
		ENDIF

		RETURN THIS.oFTP.ConnectVerified() = 1
	ENDPROC
... it continues on from here. This comes from a VCX, but I instantiate it using NewObject in the programs.

Hank

>Great question. If I knew more about this stuff I would probably have a great answer, but I'll muddle best I can.
>
>I had a form that used the MSWinsck.ocx, had some of the properties/methods overwritten, and it worked great for what I needed it for. Unfortunately, I don't really understand all that it's doing, but I do want to use it because I already use it for another area (as a standalone service) of our application functionality. That one uses a form, though usually not visible, so I didn't have to be concerned too much the references to the visual OLE object. Now, I don't want the form, but still want the functionality. It wouldn't be a problem if it just referenced the OCX using its' default properties, but there have been changes.
>
>This may be a poor question (yes, there are some), but if I want this as a non-visual class, and retain the code that someone added to the OLE object, do I need to rewrite all the methods and properties? Or can I simply reference directly what has not been changed, and "add" the methods properties in my PRG-based class to match what I see in the visual OLE object on the form?
>
>If that didn't make sense to you, imagine how I feel...
>
>
>>Hi Jay,
>>
>>creating the code from an OCX to that it can be converted to a PRG-based class is what you envision as a solution. What's the problem you are trying to solve?
>>
>>Hank
>>
Previous
Reply
Map
View

Click here to load this message in the networking platform