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 Westi 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 edit a class

Status
Not open for further replies.

mdav2

Programmer
Aug 22, 2000
363
GB
We have a class library that has code I want to change. I open the class using the class browser. Choose the view class code button and that opens the class code. If I make any changes and then save the class reverts back to what it was previously.

Do I have to take this and save it as a program then run it to recreate the class definitions?

Thanks,

Mark.

Mark Davies
Warwickshire County Council
 
You are viewing the class code only, not editing.
On way is type this in the command window (Raplacing the correct name of your class library)

MODIFY CLASS ? OF c:\projects\vai_bf_db\libs\solution.vcx

Select the clas you want to change, and the class designer will open with your class ready to modify.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
the class browser is a tool to help you with a whole class library. And the view class code is giving you an overview, that text is also used to work with versioning systems, not to change code. If you want to modify a single class, open the project manager tree, choose the class, not the lib and click modify.

Bye, Olaf.
 
Thanks for the responses!

Mark Davies
Warwickshire County Council
 
Hi Guys,

Tried that but it don't seem to do what I want. I have some code in the class library that is not relating to a specific class as such.

Basically there is a reference to an include file (see code below) that sits outside the define class statement in the class library file. This is what I am trying to remove (or edit). In this instance I think it should be moved inside the definition and checks taken place to ensure it is relevant.

The code works without error but will pop up an error when you check the "compile all" in a project.

Code:
**************************************************
*-- Class:        kregistry (h:\systemcentre\intapps\pt_speed_awareness\development\vfp8\class\wcc_tools.vcx)
*-- ParentClass:  custom
*-- BaseClass:    custom
*-- Time Stamp:   02/16/01 01:31:01 PM
*
#INCLUDE "e:\vfp6\course\registry.h"
*
DEFINE CLASS kregistry AS custom


	Height = 17
	Width = 27
	*-- a handle to the currently open key
	PROTECTED hkeycurrent
	hkeycurrent = 0
	*-- contains the last error number returned by the registry functions
	nlasterror = 0
	Name = "kregistry"
	multi = .F.
	continue = .F.


	*-- opens, gets value, closes a key
	PROCEDURE getvalue
		lparameters thkeyRoot, tcSubKey, ;
		            tcValueName, tcDefaultValue

		local lcReturnValue
		lcReturnValue = ""

		THIS.OpenKey( thkeyRoot, tcSubKey )
		lcReturnValue = THIS.ReadValue( ;
		               m.tcValueName, m.tcDefaultValue )
		THIS.CloseKey()
		return m.lcReturnValue
	ENDPROC


	*-- opens, sets value, closes a key
	PROCEDURE setvalue
		lparameters thkeyRoot, tcSubKey, ;
		            tcValueName, tcValueData

		THIS.OpenKey( m.thkeyRoot, m.tcSubKey )
		THIS.WriteValue( m.tcValueName, m.tcValueData )
		THIS.CloseKey()
	ENDPROC


	*-- opens key, deletes value, closes key
	PROCEDURE deletevalue
		lparameters thkeyRoot, tcSubKey, tcValueName

		local lhKey, lnResult
		lnResult = 0

		lhKey = THIS.GetKeyHandle( m.thkeyRoot, ;
		                           m.tcSubKey )
		*//    Delete the value:

		lnResult = RegDeleteValue( m.lhKey, ;
		                           m.tcValueName )

		THIS.CheckResult( m.lnResult, 'RegDeleteValue()')

		*//    Close the key:

		THIS.CloseKey( m.lhKey )

		return (m.lnResult=ERROR_SUCCESS)
	ENDPROC


	*-- Creates a registry key
	PROCEDURE createkey
		lparameters thkeyRoot, tcSubKey

		local lhKey

		lhKey = THIS.GetKeyHandle( m.thkeyRoot, ;
		                           m.tcSubKey )
		*//    Close the key

		THIS.CloseKey( m.lhKey )
	ENDPROC


	*-- deletes a registry key. Key must be empty
	PROCEDURE deletekey
		lparameters thkeyRoot, tcParentKey, tcKeyToDelete

		local lhKey, lnResult

		lhKey = THIS.GetKeyHandle( m.thkeyRoot, ;
		                           m.tcParentKey)
		*//    Delete the key:

		lnResult = RegDeleteKey( m.lhKey, ;
		                         m.tcKeyToDelete )

		THIS.CheckResult( m.lnResult, 'RegDeleteKey()')

		*//    Close the key:

		THIS.CloseKey( m.lhKey )

		return (m.lnResult=ERROR_SUCCESS)
	ENDPROC


	*-- opens a key and places handle in THIS.hkeyCurrent
	PROCEDURE openkey
		lparameters thkeyRoot, tcSubKey

		*//   Opens the requested key, and stores it 
		*//   in the member variable .hkeyCurrent

		local lhkey
		lhkey = 0

		if THIS.hkeyCurrent <> 0
		    *//    Close the key:
		    THIS.CloseKey( THIS.hkeyCurrent )
		endif

		lhKey = THIS.GetKeyHandle( m.thkeyRoot, ;
		                           m.tcSubKey )

		THIS.hkeyCurrent = lhKey
	ENDPROC


	*-- reads a value from the currently open key
	PROCEDURE readvalue
		lparameters tcValueName, tcDefaultValue

		*//    Ensure that the key is currently open:

		if THIS.hkeyCurrent = 0
		    return ""
		endif

		*//		Check for non-string default value
		if type( 'm.tcDefaultValue' ) <> 'C'
		    tcDefaultValue = ""
		endif

		*//     Initialise variables:

		local lcReturnValue, lnType, lnResult, ;
		      lcBuffer, lnBufferSize
		store ""            to lcReturnValue
		store 0             to lnType, lnResult
		store space(256)    to lcBuffer
		store len(lcBuffer) to lnBuffersize

		*//    Query the value of the key:

		lnResult = RegQueryValueEx( ;
		                 THIS.hkeyCurrent, ;
		                 m.tcValueName, ;
		                 REG_OPTION_RESERVED, ;
		                 @lnType, ;
		                 @lcBuffer, ;
		                 @lnBufferSize )

		if m.lnResult = ERROR_SUCCESS

		    *//  Clean up the return value:

		    lcReturnValue = strtran( left( m.lcBuffer, ;
		                    m.lnBufferSize), CHR(0), "")
		else
		    *//  Create the value with the default value:

		    THIS.WriteValue( tcValueName, tcDefaultValue )
		    lcReturnValue = m.tcDefaultValue

		endif

		return m.lcReturnValue
	ENDPROC


	*-- writes / creates a value in the currently open key
	PROCEDURE writevalue
		lparameters tcValueName, tcValueData

		local lnResult
		lnResult = 0

		lnResult = RegSetValueEx( ;
		                 THIS.hkeyCurrent, ;
		                 m.tcValueName, ;
		                 REG_OPTION_RESERVED, ;
		                 REG_SZ, ;
		                 m.tcValueData + CHR(0), ;
		                 len(m.tcValueData) )

		THIS.CheckResult( m.lnResult, 'RegSetValueEx()')

		return (m.lnResult=ERROR_SUCCESS)
	ENDPROC


	*-- Closes the currently open key
	PROCEDURE closekey
		lparameters thkey

		*//  We must support implicit closing of the 
		*//  current key THIS.hkeyCurrent, or a specific
		*//  key passed in via the parameter:

		local lhkey
		if pcount() = 1
		    lhkey = m.thkey
		else
		    lhkey = THIS.hkeyCurrent
		endif

		*//    Close the key:

		lnResult = RegCloseKey( lhkey )

		THIS.CheckResult( m.lnResult, 'RegCloseKey()')

		if pcount() = 0
		     *//    Clear our copy of the handle:
		     THIS.hkeyCurrent = 0
		endif

		return (m.lnResult=ERROR_SUCCESS)
	ENDPROC


	*-- returns a handle to the requested key
	PROCEDURE getkeyhandle
		lparameters thkeyRoot, tcSubKey

		local lhKey, lnDisposition, lnResult

		store 0 to lhKey, lnDisposition

		lnResult = RegCreateKeyEx( ;
		             m.thkeyRoot, ;
		             m.tcSubKey, ;
		             REG_OPTION_RESERVED, ;
		             REG_CLASS_DEFAULT, ;
		             REG_OPTION_NON_VOLATILE, ;
		             KEY_ALL_ACCESS, ;
		             REG_SECURITY_DEFAULT, ;
		             @lhKey, ;
		             @lnDisposition ) 

		*//  Currently lnDisposition is not used, but
		*//  it will either be REG_OPENED_EXISTING_KEY
		*//  or REG_CREATED_NEW_KEY

		THIS.CheckResult( m.lnResult, 'RegCreateKeyEx()')

		return m.lhKey
	ENDPROC


	*-- checks the returned code from REgxxx() calls against ERROR_SUCCESS
	PROTECTED PROCEDURE checkresult
		lparameters tnResult, tcModule

		if m.tnResult <> ERROR_SUCCESS

		    if _debug
		        =MessageBox("Error "+ ;
		                    alltrim(str(m.tnResult))+ ;
		                    " was returned from " +  ;
		                    m.tcModule +".")
		    else
		        THIS.nLastError = m.tnResult
		    endif
		endif
	ENDPROC


	PROCEDURE Init
		declare integer RegCreateKeyEx in Win32API ;
		        integer nhKey, ;
		        string  @cSubKey, ;
		        integer nReserved, ;
		        string  cKeyClass, ;
		        integer nOptions, ;
		        integer nSecurityAccessMask, ;
		        integer nSecurityAttributes, ;
		        integer @nKeyHandle, ;
		        integer @nDisposition

		declare integer RegSetValueEx in Win32API ;
		        integer nKeyHandle, ;
		        string  cValueName, ;
		        integer nReserved, ;
		        integer nType, ;
		        string  cBuffer, ;
		        integer nBufferSize

		declare integer RegQueryValueEx in Win32API ;
		        integer nhKey, ;
		        string  cValueName, ;
		        integer nReserved, ;
		        integer @nType, ;
		        string  @cBuffer, ;
		        integer @nBufferSize

		declare integer RegCloseKey    in Win32API ;
		        integer nKeyHandle

		declare integer RegDeleteKey in Win32API ;
		        integer nKeyHandle, ;
		        string  cSubKey

		declare integer RegDeleteValue in Win32API ;
		        integer nKeyHandle, ;
		        string  cValueName
	ENDPROC


	PROCEDURE Destroy
		if THIS.hkeyCurrent <> 0
		    *//    Close the key:
		    THIS.CloseKey( THIS.hkeyCurrent )
		endif
	ENDPROC


ENDDEFINE
*
*-- EndDefine: kregistry
**************************************************

Mark Davies
Warwickshire County Council
 
All you have outside your class is an #INCLUDE. That's simply including a h or header file, mich most probably contains some #DEFINEs, so it defines constants, which are used in the code.

What error do you get if you "compile all" or build the project?

Bye, Olaf.
 
Hi Mark,

This brings back memories. Did you ever attend my Stage 3 course? This class is one that I gave to course delegates to demonstrate registry access. The .H file contains #DEFINEs for the constants used in the class.

To try to answer to your question, you shouldn't be trying to combine the .H file with the class. The whole point of this kind of file is that it lives outside your code, so the essential constants can be changed without affecting anything else.

To prevent compilation errors when you are compiling the class, you have to make sure that VFP can find the .H file. The way to do that is to open the class designer, go to Class / Include File, and enter the full path and filename of the file.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Mike and Olaf. I didn't write this just inherited it so it was probably taken from a course (hence the filename e: probably bieng the old CD it was on). I would normally just put defines into the code but this would be handy for say MS Office defines which there could be hundreds of.

I managed to change the class using the CLASS\INCLUDE so it now points to a valid location. Still think it somewhat odd that once you put an include file into a class you can't seem to remove it only change it.


Mark Davies
Warwickshire County Council
 
Mark,

Still think it somewhat odd that once you put an include file into a class you can't seem to remove it only change it.

Yes, you can remove it. Just go to Class / Include again, delete the filename, and click OK. At least, it works for me.

I didn't write this just inherited it

Well, it's definitely my class. I would normally object to my proprietary code being posted in its entirety in a forum, but it's pretty old stuff and not much use to me any more, so I won't complain.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top