summaryrefslogtreecommitdiff
path: root/src/bin/pgaccess/forms.html
blob: cb1d5ce8c57c45c4a06a26d68bc67c7bd6c3d801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (X11; I; Linux 2.0.32 i586) [Netscape]">
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFEBCD" LINK="#0000EF" VLINK="#51188E" ALINK="#FF0000">

<H1>
FORMS</H1>

<HR WIDTH="100%">

<P>This version (0.83) of PgAccess has changed a little the visual form
builder introduced since 0.82 version : variable handling, query results
interface and control bindings naming convention. Please read it carefully,
download the database demo and practice a while before trying to design
your own forms.

<P>For the moment, it has only some basic widgets : labels, entries, buttons
, listboxes , checkboxes and radiobuttons.

<P>Also there is a pseudo query widget that allows you yo have access to
a query results.

<P><B>How do you generate widgets :</B>
<OL>
<LI>
select a widget from the toolbox by clicking the appropriate radiobutton</LI>

<LI>
move to the canvas , point with the mouse at the desired location and click
the mouse button to begin</LI>

<LI>
keeping the mouse-button pressed move the mouse in order to draw a rectangle
that will hold the widget</LI>

<LI>
release the mouse-button</LI>
</OL>
In the rectangle that you have designed it will appear the selected object.
<BR>Move now to the attribute window to change some of its properties.

<P>Renaming, resizing items are possible (for the moment) only by modifying
appropriate parameters in attribute window. You <B>must </B>press Enter
in the edit field after changing a value in order to be accepted.

<P>You can also move items by dragging them or delete them by pressing
Del key after selecting them.

<P>In attribute window, there are some fields named <B><TT><FONT SIZE=+1>Command
</FONT></TT></B>and <B><TT><FONT SIZE=+1>Variable</FONT></TT></B>.

<P>The field <B><TT><FONT SIZE=+1>Command </FONT></TT></B>have meaning
only for Button widgets and holds the command that will be invoked when
the button is pressed.

<P>&nbsp;&nbsp;&nbsp; The field <B><TT><FONT SIZE=+1>Variable </FONT></TT></B>have
meaning only for EditField , Label widgets , checkboxes and radiobuttons
and it is the name of the global variable that will hold the value for
that widget. For checkboxes the values are <B>t</B> and <B>f</B> (from
true and false) in order to simplify binding to logical data fields (PgAccess
0.82 used 0 and 1).

<P>&nbsp;&nbsp;&nbsp; For radiobuttons, it is usual to assign the same
variable to the same radiobuttons within the same group. That variable
will contain the name of the widget of the radiobutton that has been pressed.
Let's presume that you have entered 3 radiobuttons named red, green and
blue, all of them having the same variable named color. If you will press
them, they will assign their names to global variable.

<P>&nbsp;&nbsp;&nbsp; In order to make a simple test, put an entry field
and set it's variable to <B>v1</B> and a button who's command is "set v1
whisky". Press the button "Test form" and click on the button. In that
entry should appear whisky.
<BR>Another test is defining in Script module a script called "My first
script" having the following commands:
<BR><TT><FONT SIZE=+1>tk_messageBox -title Warning -message "This is my
first message!"</FONT></TT>
<BR>and then define a button who's command is <B><TT><FONT SIZE=+1>execute_script
"My first script"</FONT></TT></B>.
<H2>
Database manipulation</H2>
Let's presume that our form have the internal name <B><TT>mf </TT></B>(my
form). He will be referred inside the Tcl/Tk source as <B><TT>.mf</TT></B>
<BR>If you want to close the form in run-time you have to issue the command
<B><TT>destroy .mf</TT></B>

<P>Also, any widget will have the name prefixed by <B><TT>.mf&nbsp;</TT></B>&nbsp;&nbsp;&nbsp;&nbsp;
We will have <B><TT>.mf.button1</TT></B> or <B><TT>.mf.listbox1</TT></B>
.

<P>We can name the query widget <B><TT>qry</TT></B> for example. The complete
name will be <B><TT>.mf.qry</TT></B> then.
<BR>The <B><TT>Command </TT></B>property of the query widget must contain
the SQL command that will be executed.
<BR>When the form will be in run-time, automatically you will have access
to the following procedures and functions :

<P><B><TT>.mf.qry:open</TT></B> - opens the connection and execute the
query (returns nothing)
<BR><B><TT>.mf.qry:setsql newsql</TT></B> - set the command query that
will be executed at the next <B><TT>.mf.qry:open</TT></B>
<BR><B><TT>.mf.qry:nrecords</TT></B> - returns the number of records in
the selected query
<BR><B><TT>.mf.qry:crtrecord </TT></B>- returns the current record number
inside the query result
<BR><B><TT>.mf.qry:fields</TT></B> - returns a list of the fields in the
result set
<BR><B><TT>.mf.qry:movefirst</TT></B> - move the cursor to the first record
in the recordset
<BR><B><TT>.mf.qry:movelast</TT></B><TT> , <B>.mf.qry:movenext</B> , <B>.mf.qry:moveprevious</B>
</TT>- moves the cursor there
<BR><B><TT>.mf.qry:moveto newrecno</TT></B> - move the cursor to that new
record number (first is 0)
<BR><B><TT>.mf.qry:updatecontrols</TT></B> - update the variables inside
the designed form that have a particular name (I'll explain later)
<BR><B><TT>.mf.qry:clearcontrols</TT></B> - clear the variables inside
the designed form binded to a query result
<BR><B><TT>.mf.qry:fill listbox field</TT></B><TT> </TT>- fill the named
listbox (whole widget name as <B><TT>.mf.listbox1</TT></B>) with the all
the values of that field in the current queryresult
<BR><B><TT>.mf.qry:close</TT></B> - close the connection (<B><FONT COLOR="#FF0000">if
you don't close the query result, you will loose some memory</FONT></B>)

<P>It's no need to close a query-result if you want to assign it a new
SQL command and open it again. That will be done automatically.

<P>If you want to bound some controls to the fields of the recordset, you
will have to name their associate variable like that :

<P><B><TT>mfqry(salary)</TT></B> to get the "salary" field , or <B><TT>mfqry(name)</TT></B>
to get the "name" field. So, you take the internal name of the form (without
the leading point) and merge it with the query-widget name and you will
get a associative array name. The values are given using the field name
as a key in this associative array.
<BR><B><FONT COLOR="#FF0000">* WARNING *</FONT></B> The naming style has
been changed from 0.82 version of PgAccess and I cannot guarantee that
it not be changed again in the future. I'm just trying to make it as simple
it could be. The old style naming convention had some incompatibilities
with Tcl/Tk syntax.

<P><B><FONT SIZE=+1><FONT COLOR="#9400D3">QUESTION</FONT> : </FONT></B>Do
you think that it would be more clear if the above functions and procedures
regarding a query-widget would be named in a similar manner as binded variable
controls ? That mean, <B><TT>mfqry:open</TT></B> and <B><TT>mfqry:updatecontrols</TT></B>
instead of <B><TT>.mf.qry:open</TT></B> and <B><TT>.mf.qry:updatecontrols</TT></B>
?

<P>The only advantage of <B><TT>.mf.qry:open</TT></B> is that is much closer
to the Tk method of referring objects within a window and it may give to
the programmer the feeling that he is using a object-oriented widget. Since
I cannot use further for naming binded variables a similar manner (<B><TT>.mf.qry.salary)</TT></B>
it might be possible to abandon that naming convention .

<P>Here it is a dumped <B><A HREF="formdemo.sql">sample database</A></B>
that contains a demo database. What should you do ?
<BR>Shift-click the above URL in order to download that tiny file (4 Kb).
Create a empty database and <B><TT>psql yourdatabase &lt;formdemo.sql</TT></B>

<P>You should find a single table called "phonebook" a form called "Phone
book" and another "A simple demo form".

<P>First of all enter and view the phonebook table in table view. Note
the fields and their values.
<BR>Open the "Phone book" form and enter a letter (a, e or i) in the field
to the left of "Find" button then press Find. It's fine to enter one letter
in order to get more records in query result. You will get information
about the number of records selected, in the listbox you will see all the
values of field "name" from the current data set. Use buttons to move to
first, next, previous or last record within the record set.

<P>In order to add a new record, press the "New" button in order to get
new, clean entries. Fill them with your data and press "Add new" button.
A new phonebook record will be added. Also, if you want to update a record,
change it's values in the displayed fields after finding it and press "Update"
button. The values will be updated in the database BUT NOT IN THE CURRENT
QUERY RESULT . If you want to see them modified, make a new query trying
to find it again.

<P><FONT COLOR="#000080">Before using the results from a query you should
know that the information that has been retrieved could be found only in
your computer client memory. It has <B>no live connection</B> to the data
from the database. That's why it isn't possible to develop a simple update
function as interface to that query-result widget. More than that : a query
result could be obtained from a SQL command that return a non-updatable
data set !!! For example fields gathered from multiple tables or summary
fields. It isn't just simple to make an automatic update procedure. The
programmer must know how to make the update or the append procedure, sometimes
using key fields to point to the desired record or an OID. There are examples
in the demo database in "Phone book" form. It may be possible that in the
future, I will develop another pseudo-widget describing a table. It would
be more simple than to implement an update or append or even a delete procedure.</FONT>

<P>There is in the demo database also another simple form called "A simple
demo form". It will show you how to handle variables from checkboxes, radiobuttons,
how to use listboxes, open another forms and so on. I think they will help
you.

<P>In order to avoid naming user defined forms with&nbsp; a particular
name of another PgAccess form, I would recommend naming them as udf0, udf1
(user defined form 0 , 1 )

<P>
<HR WIDTH="25%">

<P>Please feel free to send me your opinion at <B>teo@flex.ro</B> on forms
designing and usage.

<P><B><FONT SIZE=+1>KEEP IN MIND !&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
THE FORM API WILL CHANGE IN ORDER TO BE MORE SIMPLE AND BETTER!&nbsp;&nbsp;&nbsp;
SEND ME YOUR WISHES, YOUR IDEAS, YOUR OPINIONS !</FONT></B>
<BR><B><FONT SIZE=+1>ALSO ... DON'T BLAME ME IF YOU WILL HAVE TO RE-DESIGN
YOUR OLD FORMS DUE TO SOME INCOMPATIBILITIES WITH NEWER PGACCESS VERSIONS.</FONT></B>
</BODY>
</HTML>