Paradox Community
Search:

 Welcome |  What is Paradox |  Paradox Folk |  Paradox Solutions |
 Interactive Paradox |  Paradox Programming |  Internet/Intranet Development |
 Support Options |  Classified Ads |  Wish List |  Submissions 


Paradox OCX Internet/Intranet Articles  |  Non-OCX Internet/Intranet Articles  


Paradox Web Server
Lesson 1 - The Basics
© 2001 Tony McGuire

Lesson 1 - The Basics

I have been trying to figure out what level of "help" people are looking for in setting up Paradox as a web server. I finally decided that it really didn't matter. If I start with "up & running", those who weren't looking for this could ignore it and if I started with a technical explanation the same would apply. So I am just going to start, and you can determine whether this is of any value to you.

Paradox "talks" to the Internet in the same basic manner that any other program does. Until you actually make a request for, or are sending, data (and that is basically what _all_ POST and GET actions are doing) there is no real action required by Paradox.

What I mean is that when you are on the Internet and click on a link, it is usually just going to result in a different page showing up on screen.

Where the exchange of data really comes in is when you get a block on screen where you type something in or select from a dropdown etc., and then there is a button you click on; the information you filled in gets sent TO something. This something is Paradox (in my discussions, I am going to insist that Paradox do the work - NOT Cold Fusion, NOT ASP, NOT CGI, NOT anything else [unless _I_ make an exception]).

The block you filled in is called a field, just as in Paradox. The field is part of a form, just as in Paradox. However, the form is normally just a small portion of the page, not the whole page. On the Internet, a form is a formal structure, and can have dropdown boxes, text fill-in fields, radio buttons, checkboxes, etc.

A form (and most other elements, if proper HTML is used) has an open statement and a close statement. Within the opening and closing of the form, the elements describing the form (including the above field types) appear.

A simple form for collecting a name might appear as follows:

<form name="getname" method="POST" action="getname">
<input type="text" width="25" maxlength="23" name="fullname"> Enter Your Name
<input type="Submit" value="Send Name">
</form>

This would draw an input field, named "fullname", on screen 25 character wide, which would accept up to 23 characters. Next to the field would appear the text "Enter Your Name". It would also create a button, with a label of "Send Name".

In the block, any 23 characters, up to the 23 limit, would be accepted. The extra 2 characters would remain as whitespace (I do this so that if the user continues to type beyond what I allow for the input they can see that not everything they typed was accepted).

When the user clicked on the button, the information that was typed into the block would be sent to the server that drew the form; along with the information filled in would be included the information that the form should be handled as a POST operation, by whatever the server understands to be the "getname" function.

Now, on the Paradox side, there is a method in a library that is designed to handle the input from this form (you create the method and the code that handles the input). The meat of the method might look something like this:
method getname(var Request OleAuto, var Response OleAuto) logical
var
  namvar string
endvar

namvar=request.getfield("fullname")
request is an OLEAuto function that Paradox uses for making the connection to the Internet (through the websrv.ocx). Using request is how you are able to use Paradox to process incoming "requests" for "action" from the Internet.

From this point, until you are ready to send something back to the user's browser, everything you do is straight OPAL!!! You now have whatever the user typed into the field on the form on the Internet stored in the variable namvar.

If all you wanted to do was display on screen what the user typed, your next lines might be:
response.resultstring="You typed "+namvar
return true
endmethod
response is the OLEAuto function you use to send text (Paradox's response) back to the websrv.ocx, which then sends it on to the user's browser. There is no need to create an HTML file, unless you wish to. What you send is what the user's browser gets. resultstring is where the response is stored and passed back to the websrv.ocx, which in turn sends it back to the user. The response above is _VERY_ simplistic. Normally, you will send the standard HTML constructs along with your actual response.

Most pages contain the following elements:

<html>
<head>
<title>This Page's Title</title>
</head>
<body>
</body>
</html>

Note the "almost" duplicated entries, such as <html> and </html>. These are the opening and closing statements of some element of HTML. Although you can get away, sometimes, with not closing an element, this depends in large part on how forgiving the browser that the viewer is using is. Then, there are a few elements that don't have the <element></element> construct. Not very many, though, and I will try to remember to point them out if I use any.

Next, let's assume that the form above is one that you use to gather the name of people visiting your site - you let anyone in, but only after they give you their name.

After namvar=getfield("fullname") you might include the following (assuming that you added tc tcursor to the var construct: if namvar.size()<5 then response.resultstring="Name must contain at least 5 characters" return true endif 5 is arbitrary. You could make this any number you want. It just guarantees that the user typed _something_
tc.open("users.db")
tc.edit()
if not tc.qlocate(namvar) then
  tc.insertrecord()
  tc."name"=namvar
endif

tc."date"=today()
tc."time"=strval(time())
tc."logins"=tc."logins"+1
logvar=tc."logins"
tc.endedit()
tc.close()
Then, you might have something like this:
storagevar="Welcome "
if logvar>1 then
  storagevar=storagevar+"back "
endif
storagevar=storagevar+"to my world, "
storagevar=storagear+namvar
response.resultstring=storagevar
return true
endmethod
The above would result in "Welcome to my world, John" or "Welcome back to my world, John" appearing on the user's browser.

What this does is maintains a list of your site visitors, the # of times they have visited, and the last day & time they came back (I would set the "defaultvalue" on tc."logins" to be 0, so the field would never be blank even when a new record was created).

In this example, I opened the tcursor as I was processing the individual "request". This could just as easily have been a tcursor opened when the library opened; it could also already be in edit mode (I don't recommend the edit part, but experiment).

As you can see, this is all pretty basic OPAL. The difference is only the way you gathered information from the user - from an Internet form instead of from a desktop form.

The responses above would appear in very plain text, with no font control, alignment or coloring. Placing data elements, retrieving and displaying rows of records, font control, alignment, etc. will have to be in another (several) posting. As I said before, I am not a writer or instructor by nature. I can talk all day long, but trying to write coherently wears me out. Perhaps someone can translate my postings into usable explanations (Lance?).

If the above isn't the type of information you guys (and, of course, gals) are looking for, let me know and I will cease & desist. I am also preparing a technical FAQ on the Internet that shows the flow of information through the websrv.ocx, into Paradox, and the form & library functions that interconnect it all. I will post a link when there is enough to do someone some good.

Hopefully, this posting demonstrates just how simple the mechanics of retrieving data from the Internet is when using Paradox. Of course, we didn't get into the intervening mechanics - the step by step of the OCX and how it talks to Paradox. I did this on purpose. If you see how easy the meat of the process is, you'll be more likely to hang in there for the, to me, hard part. Not hard in making it work - Corel makes it pretty automatic and it works beautifully when you use the examples as a template. Most of us, however, want to know the inner workings so we can adjust them as necessary for the app we are setting up.


Lesson 2


Discussion of this article


 Feedback |  Paradox Day |  Who Uses Paradox |  I Use Paradox |  Downloads 


 The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation.
 Paradox is a registered trademark of Corel Corporation.


 Modified: 15 May 2003
 Terms of Use / Legal Disclaimer


 Copyright © 2001- 2003 Paradox Community. All rights reserved. 
 Company and product names are trademarks or registered trademarks of their respective companies. 
 Authors hold the copyrights to their own works. Please contact the author of any article for details.