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

MVC and Visual Foxpro

Status
Not open for further replies.

ka Lok

Programmer
Jan 19, 2023
3
GB
thread184-1777610

I hope mine is correct.

***********************************
* mvc sample
***********************************
oView = createobject('myform')

with oView

.addobject('controller1','myController1')
.addobject('controller2','myController2')

with .controller1
.be('sendEmail','button1','click')
endwith

with .controller2
.be('print' ,'button2','click')
.be('changeColor','button2','click')
.be('retrieveCustomer','button2','click')
endwith

.show()

endwith

read events


***********************************************
define class controller as custom
osource = ''

function be(action,src,eventname)
bindevent(this.parent.&src,m.eventname,this,m.action) && action = m.action
ENDFUNC

procedure osource_access
aevents(asrc,0)
return asrc(1)
ENDPROC
enddefine
***********************************************

***********************************************
define class myController1 as controller
procedure sendemail
messagebox(" I'll send an email! / Form Caption: "+this.parent.caption )
ENDPROC
enddefine
***********************************************

***********************************************
define class myController2 as controller
ADD OBJECT model as MyModel

procedure print
messagebox("I will print.. My Caption is : "+this.osource.caption)
ENDPROC

procedure changecolor
thisform.backcolor = rgb(26, 118, 209)
ENDPROC

PROCEDURE retrieveCustomer
this.model.retrieveCustomer()
thisform.showCustomerName(this.model)
ENDPROC
enddefine
***********************************************

*********************************************
define class myform as form

add object button1 as commandbutton ;
with caption= "I don't know what I do ",;
left = 10, height = 50 , visible = .t., width = 150

add object button2 as commandbutton ;
with caption= " me neither!",;
left = 10, top = 100,height = 50, width = 150, visible = .t.


add object customerLabel as label ;
with caption= "",;
left = 10, top = 180,height = 40, width = 150, visible = .t.


caption = 'MVC DEMO '

procedure destroy
clear events
ENDPROC


PROCEDURE showCustomerName(toModel as Object)
this.customerLabel.caption = toModel.cName
ENDPROC
enddefine
*********************************************

*********************************************
DEFINE CLASS MyModel as Custom
cName = ""

PROCEDURE retrieveCustomer
SELECT cs_Name FROM customer WHERE cs_tel='07891430852' INTO CURSOR lcCursor
this.cName = "Customer name is " + cs_name
USE IN lcCursor
ENDPROC
ENDDEFINE
*********************************************
 
I don't know. For a start, to know if it is "correct", I would have to know what its goal is, that is, what you expect it to do. I would then have to either study the code line by line, or run it (in which case I would also need a copy of your data).

Is there any reason why you can't do that yourself?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I used someone's code and add a MODEL on it, I just practice MVC concept and do not know whether mine is right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top