Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Modal form created from prg won't release ?
Message
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Title:
Modal form created from prg won't release ?
Miscellaneous
Thread ID:
00215532
Message ID:
00215532
Views:
55
Hi all,

I have created a prg that instantiates a modal form with CommandButtons that I can call from anywhere and recieve a character string of numbers back.

But I can't get the form to release in code??

Can someone please advise me ?

Thanks in advance

Greg Foote
Software At Work



This code will release the modal form ????


***********Code Follows below***********


oForm = CreateObject("Form")
oForm.AddObject( "txt1" , "myButton" )

oForm.Show(1)


DEFINE Class myButton as Commandbutton
Visible = .T.
PROCEDURE Click()
WITH ThisForm
.Release()
ENDWITH
ENDPROC

ENDDEFINE

***********End of Code ***********



The culprit code:

***********Code Follows below***********
****Name this prg GetNumber.prg

****Call this code with :
*** ? GetNumber( "Enter Code" , 6 , "999-999" )



PARAMETERS cCaption , nNumbersToReturn , cInputMask , lPassword

#DEFINE CR chr(13)

PUBLIC cReturnVal , oForm , llPassword

llPassword = lPassword

nButtonWidth = 60
nButtonSpacing = 10

IF lPassword
cTextInputMask = ""
cPasswordChar = "*"
ELSE
cTextInputMask = cInputMask
cPasswordChar = ""
ENDIF

cReturnVal = ""

oForm = CreateObject("frmNumbers")

oForm.nNumbersToReturn = nNumbersToReturn
oForm.Caption = cCaption
oForm.ControlBox = .F.
oForm.WindowType = 1

oForm.AddObject( "txtNumbers" , "txtNumbersTextBox" )


FOR lni = 9 to 0 Step -1

cName = "cmdNumber" + allt( Str( lni ) )
oForm.AddObject( cName , "cmdNumbers" )

objButton = Eval( "oForm." + cName )
objButton.Name = cName
objButton.Comment = allt( Str( lni ) )
objButton.Caption = "\<" + allt( Str( lni ) )

= SetLeftPosition( objButton )
= SetTopPosition( objButton )

ENDFOR

oForm.AddObject( "cmdB" , "cmdBackSpace" )
oForm.cmdB.Name = "cmdB"
= SetLeftPosition(oForm.cmdB)
= SetTopPosition(oForm.cmdB)

WITH oForm.cmdB
oForm.Width = .Width + .Left + nButtonSpacing
oForm.Height = .Height + .Top + nButtonSpacing
ENDWITH

oForm.txtNumbers.Width = oForm.Width - ( nButtonSpacing * 2 )
oForm.txtNumbers.Left = nButtonSpacing



oForm.AutoCenter = .T.

oForm.Show()
READ Events

cReturn = cReturnVal
Release cReturnVal , oForm , llPassword
RETURN cReturn



DEFINE Class frmNumbers as Form
nNumbersChosen = 0
nNumbersToReturn = 0
cReturnValue = ""
KeyPreview = .T.
ShowWindow = 1

PROCEDURE ButtonClicked(oButton)

WITH This

.nNumbersChosen = .nNumbersChosen + 1
.cReturnValue = .cReturnValue + oButton.Comment
.txtNumbers.Value = .cReturnValue

.Refresh()

IF .nNumbersChosen = .nNumbersToReturn

IF llPassword
cReturnVal = .cReturnValue
Clear Events
.Release()
ELSE
IF MessageBox( "Is this correct ?" + CR + CR + .txtNumbers.Value , 36 ,
"Correct ? ") = 6
cReturnVal = .cReturnValue
Clear Events
.Release()
ENDIF
ENDIF

ENDIF

ENDWITH

ENDPROC

PROCEDURE KeyPress(nKeyCode, nShiftAltCtrl)

IF nKeyCode = 127
this.cmdB.Click()
ENDIF

ENDPROC

ENDDEFINE


DEFINE Class cmdNumbers as Commandbutton
FontBold = .T.
FontSize = 14
FONT = "Arial"
Width = nButtonWidth
Height = nButtonWidth
Visible = .T.

PROCEDURE Click()
thisform.ButtonClicked(This)
ENDPROC

ENDDEFINE

DEFINE Class cmdBackSpace as Commandbutton
FontBold = .T.
FontSize = 10
FONT = "Arial"
Width = nButtonWidth
Height = nButtonWidth
Caption = "Backspc"
Visible = .T.

PROCEDURE Click()

nChosen = thisform.nNumbersChosen
thisform.nNumbersChosen = iif( nChosen > 0 , nChosen - 1 , 0 )

cString = ThisForm.cReturnValue

thisform.cReturnValue = Left( cString , len( cString ) - 1 )

thisform.txtNumbers.Value = ThisForm.cReturnValue

thisform.Refresh()

ENDPROC

ENDDEFINE

DEFINE Class txtNumbersTextBox as Textbox
TabStop = .F.
Top = 10
Width = 120
Height = 25
Visible = .T.
Format = "R"
InputMask = cTextInputMask
PasswordChar = cPasswordChar
FontSize = 12
FontBold = .T.
FONT = "Arial"

ENDDEFINE



FUNCTION SetLeftPosition(oButton)

cNumber = Right( oButton.Name , 1 )

DO Case

CASE InList( cNumber , "7" , "4" , "1" , "0" )
oButton.Left = 10

IF cNumber = "0"
oButton.Width = nButtonWidth * 2
ENDIF

CASE InList( cNumber , "8" , "5" , "2" )
nLeft = nButtonWidth + ( nButtonSpacing * 2 )
oButton.Left = nLeft

CASE InList( cNumber , "9" , "6" , "3" , "B" )
nLeft = ( nButtonWidth * 2 ) + ( nButtonSpacing * 3 )
oButton.Left = nLeft

ENDCASE


FUNCTION SetTopPosition(oButton)

cNumber = Right( oButton.Name , 1 )
nStartRow = oButton.Parent.txtNumbers.Top + oButton.Parent.txtNumbers.Height
+ nButtonSpacing

DO Case

CASE InList( cNumber , "7" , "8" , "9" )
oButton.Top = nStartRow

CASE InList( cNumber , "4" , "5" , "6" )
oButton.Top = nStartRow + oButton.Width + nButtonSpacing

CASE InList( cNumber , "1" , "2" , "3" )
oButton.Top = nStartRow + ( oButton.Width * 2 ) + ( nButtonSpacing * 2 )

CASE InList( cNumber , "0" , "B" )
oButton.Top = nStartRow + ( nButtonWidth * 3 ) + ( nButtonSpacing * 3 )

ENDCASE
Greg Foote
Software At Work, Inc.
Next
Reply
Map
View

Click here to load this message in the networking platform