WinDev MVC

WinDev Add comments

Developing WinDev applications can be fun and challenging, but where there’s ease of use comes great responsibility.

You need to structure your code is such a way that it will be easily maintainable for yourself and other developers involved in the project.

So MVC comes to the rescue when you want to have a clean and tidy source project. But I here you say, “WinDev doesn’t have an MVC framework”. Well I am going to show you how easy it is to structure your project in such a way that will make it MVC friendly.

What are we trying to achieve here?

To often we just add H commands to our form code just because it is easy to do. But the problem is this soon makes the application messy and you will find more cases of duplicating a process that was in another form.

I am going to show you a simple example of how I structure my projects in an MVC style.

Firstly I created 2 custom folders in Classes, one for Models which will interact with the database, and the other is Controllers which is the conduit between the window form code and the model.

image

Models

In the screen shot above you can see I have created a UserModel. This class contains all the methods I need to access the database related to a user.

Within the model is a Structure object which represents the User table fields in the database.

image 

So here is an example of the GetUser method in the model which returns an object of type STUser.

image

Now the windows code does not access the model, it’s the controller that uses the model to return the required data and other information needed by the window.

image

In the controller the code here calls the model and returns the data as a STUser object. Here you would code other functionality you needed to manipulate the data to show in the View (form/window).

If you are using WinDev 14 then you can use the STUser structure in a very simple way to update the form.

Firstly you would create an object used to hold the data returned from the controller.

image

In the example above I have created a global object which will now allow me to link the controls on the form to it, as you can see in the screen shot below.

image

Now I have linked the controls to the object I can get the user data in just a couple lines of code.

image

If you don’t have WinDev 14 then its a simple task of assigning the object field data to the controls instead, as shown in this screen shot.

image

So now you can see how using the MVC pattern in WinDev / WebDev can make your code clean and easy to maintain.


Bookmark and Share

2 Responses to “WinDev MVC”

  1. Rubén Sánchez Peña Says:

    Very interesting. Thank you.

    In other systems (Java or Net) this approach is obligated. I think in Windev the use of ScreenToFile and the Windows links minimize this necesity and is more easy of maintain.

  2. patfrat Says:

    Hi,
    Your example to get MVC pattern is excellent ! Thank you … but …
    My colleague starts playing with Windev 15 and HyperfileSQL server … and I’m surprised he did not have easy access to datas as with RubyOnRails (MVC architecture), with abstraction of data access patterns.
    Example of a blog: article and associated comments.
    Two tables : articles and comments
    the table comments has a field named article_id
    Two models : Article and Comment
    Article contains “has_many :comments”
    Comment contains “belongs_to :article”
    Nothing else …
    I call the article having id=1 :
    art = Article.find(1)
    and I get all its comments with :
    art.comments
    If i want to add a new comment containing message and author columns to this article :
    c = Comment.new(:author => “me”, :message => “hello world”, :article => art)
    c.save
    No call to IDAuto or anything like this …
    How can we do this with WinDev 15 ?
    Is it possible ?
    Thank you in advance ….

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in