Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


MVC and Visual Foxpro

MVC and Visual Foxpro

MVC and Visual Foxpro

Hello all.
Is there a tutorial on how to implement MVC pattern in VFP?
Can it be done?

Thanks in advance.

RE: MVC and Visual Foxpro

1. Maybe, I don't know one.
2. Yes, what hinders you?
Model = Database and some data access classes.
View = Winforms
Controller = Business logic

That said the MVC architecture pattern does not really apply well to Winform desktop applications. VFP has a very simple way of data binding and there is no reason to make anything more complex than necessary, but generalize this and you have a 3 tier architecture and of course, VFP can do that. Database layer, business logic, and presentation layer. You will put more logic into a VFP form than into a business logic, but of course, it is rather good practice to not put the code into form control elements and instead let them call into form methods, or create a controller class you instantiate within forms or as goApp and call its methods.

Do you have any concrete MVC implementation in mind? ASP.NET MVC, for example?

Bye, Olaf.

RE: MVC and Visual Foxpro

thank you for your reply, Olaf.

A coder that I respect keeps insisting I can implement MVC pattern on a VFP app. and insist I try.... I don't know how to tell him it would be difficult and maybe even impossible.

RE: MVC and Visual Foxpro

Someone told me that I could change my bicycle into a jet plane. Just like your "coder", they are both wrong.

RE: MVC and Visual Foxpro

He's not wrong.

But it depends on what you expect. MVC is mainly used on websites. It is too specific to be the pattern to use in VFP, but using a 3 tier model of data access, business logic and presentation layer is totally normal and possible in VFP, too. Like any N-tier model it would help by making it easy to switch layers. With a business logic/application layer making use of data access objects you can switch from dbf to views to remote viewss or cursoradapter and thereby to remote databases. And it the frontend should be HTML the business logic layer could also create view (presentational view) objects which "emit" HTML and send that as request response to browsers.

You have several frameworks applying these N-tier principles. One I used is Oakleaf Mere Mortals.

Bye, Olaf.

RE: MVC and Visual Foxpro

MVC is great, and you can use it on VFP.

Below I post a demo on how you can implement the MVC ( just the view-controller ) part using VFP.

Regarding the 'model' the controller should never access directly the data; you should use
an object to get/set the data - this way you can change your data backend just changing the object base class.

Using MVC you'll have loosely coupled, interchangeable components.

This is what dependency injection's about.


* mvc sample
oView = createobject('myform')

with oView


	with .controller1

	with .controller2
		.be('print'      ,'button1','click')



read events

define class controller as custom
	osource = ''

	function be(action,src,eventname)


	procedure osource_access
	return asrc(1)


define class myController1 as controller

	procedure sendemail
	messagebox(" I'll send an email! / Form Caption: "+this.parent.caption )


define class myController2 as controller

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

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


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.

	caption = 'MVC DEMO '

	procedure destroy
	clear events


Marco Plaza

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close