Professional Documents
Culture Documents
oThing is the name of the object and MyClass is the name of the class.
BorderStyle = 1
SpecialEffect = 1
Visible = .T.
function DblClick
endfunc
enddefine
ENDPROC
a. http://www.spacefold.com/colin/archive/articles/oo_menus/menus.htm
An Example:
define class MyEditBox as EditBox && Custom editbox class for Grid
BorderStyle = 1
SpecialEffect = 1
Visible = .T.
cDataSource = ""
cReturnVal = ""
cText = ""
cFieldName = ""
if pcount() = 2
this.cDataSource = alltrim(cDs)
this.cFieldName = alltrim(cFName)
&&messagebox("1" + this.cText)
&&messagebox(cDs)
endif
endproc
function DblClick
&&messagebox("test")
lcVal = this.cText
&&messagebox("3" + lcVal)
cMemoTxt = ALLTRIM(&lcVal)
&&messagebox(cMemoTxt)
this.cReturnVal = cMemoTxt
&&messagebox(lcField)
endfunc
function getRetVal()
return(this.cReturnVal)
endfunc
enddefine
this.grdPbsOwnCodes.recordSource = tcCurName
lnFieldsNo = afield(arrFieldSpec)
objName = "edtBox"
thisform.grdPbsOwnCodes.columns(i).addObject(objName, "MyEditBox",
tcCurName, arrFieldSpec(i, 1))
Showing content of a memo field in “command window”
If the table has a memo field and we have to be able to see the content of
that memo filed without double clicking on that then we can so such a thing:
Use myTable &&myTable has 2 fields ‘id’ and ‘myMemo’
Clear Events
Issue CLEAR EVENTS to stop event processing. When CLEAR EVENTS is
issued, program execution continues with the line immediately following
READ EVENTS.
Read Events
When READ EVENTS is issued, Visual FoxPro starts event processing
Note that only one READ EVENTS can be active at a time. If a READ EVENTS is
in effect, any subsequent READ EVENTS commands have no effect.
Then you would see a window. The second record is the data environment(
we can see it by clicking of the ‘Class’ memo field, then the 3rd record is the
form and codes of the methods are stored under method fields and objected
code in ‘ObjCode’. So we can change the value of the ‘Class ‘ field of the 3rd
recode which is a form and for example make it parentform from childform or
vice versa. We also can put the location of that class that we just specified in
‘Class’ field by changing the value of the ‘ClassLoc’ field
Every time cy pressing ‘ctrl+w’ we save and exit from a memo filed window
to the main table (formName.scx)
Random Function
If we want to generate a number between n and m and we n > m then we
should have:
Int(rand() * (n – m + 1) + m)
To have a parent form an d a few child forms we should set a few properties
in the parent form and child form.
Copy Structure
Select patient
NewObject()
goApp = newObject("ExcelConvert", "ExcelConvertor") && Create an instance
of ExcelConvertor
first parameter is the real class which we want to have an instace of it and
second parameter is the name of the class library. The relation of class library
and class can be seen in the classes tab in project manager like below
class library->class
So a class is located in a class library and if we don’t specify class library VFP
looks for the specified class in few different places:
CreateObject()
goApp = createObject(("ExcelConvert")
Before you can create an object from a user-defined class, the user-defined
class must first be created with DEFINE CLASS, or it must be available in a
.vcx visual class library opened with SET CLASSLIB.
this.loExcel = CreateObject("Excel.Application")
AddObject()
objName = “myEditBox”
thisform.grdPbsOwnCodes.columns(i).addObject(objName, EditBox")
Here first parameter is the name of the object which will be added and
second parameter is the name of a class which could be one of VFP base
classes (like here) or we could difine a lass for example in a prg file and then
have a:
llErr = .f.
oldErrHandling = on("error")
this.createPbsOwnCodes()
this.createPbsTCodes()
on error &oldErrHandling
if llErr
goApp.leaveApp()
return
endif
lnScreenX = GetSystemMetrics(SM_CXSCREEN)
lnScreenY = GetSystemMetrics(SM_CYSCREEN)
lcTitleBarHeight = GetSystemMetrics(SM_CYCAPTION)
lnMenuBarHeight = GetSystemMetrics(SM_CYMENU)
CLEAR DLLs
* GetSystemMetrics() codes
#DEFINE SM_CXSCREEN 0
#DEFINE SM_CYSCREEN 1
#DEFINE SM_CXVSCROLL 2
#DEFINE SM_CYHSCROLL 3
#DEFINE SM_CYCAPTION 4
#DEFINE SM_CXBORDER 5
#DEFINE SM_CYBORDER 6
#DEFINE SM_CXDLGFRAME 7
#DEFINE SM_CYDLGFRAME 8
#DEFINE SM_CYVTHUMB 9
On Error
On error messagebox(‘error’)
lcErrHandler = on(‘error’)
On error &lcErrHandler
llTry = .T.
lnTryCount = 1
oldError = ON("ERROR")
lnTryCount = lnTryCount + 1
llTry = .F.
IF llTry
goSystem.Sleep(1000)
ENDIF
ENDDO
ON ERROR &oldError
IF llTry
glCompleted = .F.
ENDIF
goMessage.wmsge(" ")
ENDFUNC
Event Sequencing
When A Form Getting Loaded:
1. DataEnvironmet.openTables()
2. DataEnvironmet.beforeOpenTables()
3. Form.load()
5. DataEnvironment.init()
7. Form.init()
8. Form.show()
9. Form.activate()
10.Form.refresh()
2. Form.activate()
4. Form.gotFocus()
5. [object1].gotFocus()
6. [object1].message()
3. [object(i)].message()
2. [object(j)].lostFocus()
If We Move To The Next Text Box From Currently Focused Text Box And
Type Something In The Next Text Box:
1. Text(i).keyPress()
2. Text(i).valid
3. Text(i).lostFocus
4. Text(i+1).when()
5. Text(i+1).gotFocus()
2. Text(i).interactiveChange()
2. Form.destroy()
3. Form.[command buttons].destroy()
4. Form.[objects].destroy()
5. Form.unload()
6. DataEnvironment.afterCloseTables()
7. DataEnvironment..destroy()