~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to packages/ncurses/db_demo.pp

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2004-08-12 16:29:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040812162937-moo8ulvysp1ln771
Tags: 1.9.4-5
fp-compiler: needs ld, adding dependency on binutils.  (Closes: #265265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{------------------------------------------------------------------------------
2
 
                                 CncWare
3
 
                           (c) Copyright 2000
4
 
 ------------------------------------------------------------------------------
5
 
  Filename..: db_demo.pp
6
 
  Programmer: Ken J. Wright, ken@cncware.com
7
 
  Date......: 06/29/2000
8
 
 
9
 
  Purpose - Demonstrate the use of oCrt in a simulated database record editor.
10
 
 
11
 
-------------------------------<< REVISIONS >>---------------------------------
12
 
  Ver  |    Date    | Prog| Description
13
 
-------+------------+-----+----------------------------------------------------
14
 
  1.00 | 06/29/2000 | kjw | Initial Release.
15
 
-------------------------------------------------------------------------------
16
 
}
17
 
Program db_demo;
18
 
Uses oCrt;
19
 
Const
20
 
   MAXCOLS = 6;
21
 
   MAXROWS = 10;
22
 
Type
23
 
   tAddress = Record
24
 
      FirstName,
25
 
      LastName,
26
 
      Street  : string[40];
27
 
      Country : string[2];
28
 
      Zip     : string[5];
29
 
      City    : string[30];
30
 
   End;
31
 
 
32
 
   tFields = Record
33
 
      x,y,wid : integer;
34
 
      pic : string;
35
 
   End;
36
 
 
37
 
Var
38
 
   win : tnWindow;
39
 
   address : Array [1..MAXROWS] of tAddress;
40
 
   fields : Array [1..MAXCOLS] of tFields;
41
 
   s : string;
42
 
   i,
43
 
   m1,m2,
44
 
   att1,att2,att3,
45
 
   row,
46
 
   col : integer;
47
 
   ch : char;
48
 
   IsDone : boolean;
49
 
 
50
 
Procedure Display(row : integer);
51
 
Begin
52
 
   With address[row] Do Begin
53
 
      For i := 1 to MAXCOLS Do Begin
54
 
         With fields[i] Do Begin
55
 
            Case i of
56
 
               1 : s := FirstName;
57
 
               2 : s := LastName;
58
 
               3 : s := Street;
59
 
               4 : s := Country;
60
 
               5 : s := Zip;
61
 
               6 : s := City;
62
 
            End;
63
 
            win.FWrite(x,y,att1,x+wid-1,s);
64
 
         End;
65
 
      End;
66
 
   End;
67
 
   col := 1;
68
 
End;
69
 
 
70
 
{ bind the arrow keys so they trigger an exit }
71
 
Procedure BindArrows;
72
 
Begin
73
 
   win.ec.Special := ^I^R^L^P^N;
74
 
   m1 := win.ec.AddChMap(#0+Char(nKeyRight)+^R#0);
75
 
   m2 := win.ec.AddChMap(#0+Char(nKeyLeft)+^L#0);
76
 
   win.FWrite(1,win.Rows,48,0,'[F2]-Arrows');
77
 
End;
78
 
 
79
 
Procedure UnBindArrows;
80
 
Begin
81
 
   win.ec.Special := ^R^L^P^N;
82
 
   win.ec.ClrChMap(m1);
83
 
   win.ec.ClrChMap(m2);
84
 
   win.FWrite(1,win.Rows,62,0,'[F2]-Arrows');
85
 
End;
86
 
 
87
 
Begin
88
 
   FillChar(address,SizeOf(address),#0);
89
 
   With address[1] Do Begin
90
 
      FirstName := 'Rainer';
91
 
      LastName := 'Hantsch';
92
 
      Street := '12345 Some Street';
93
 
      Country := 'A';
94
 
      Zip := '1030';
95
 
      City := 'Vienna';
96
 
   End;
97
 
 
98
 
   For i := 1 to MAXCOLS Do Begin
99
 
      With fields[i] Do Begin
100
 
         Case i of
101
 
            1 : Begin x := 14; y := 2; wid := 40; pic := ''; End;
102
 
            2 : Begin x := 14; y := 3; wid := 40; pic := ''; End;
103
 
            3 : Begin x := 14; y := 4; wid := 40; pic := ''; End;
104
 
            4 : Begin x := 14; y := 5; wid :=  2; pic := ''; End;
105
 
            5 : Begin x := 19; y := 5; wid :=  5; pic := '*#'; End;
106
 
            6 : Begin x := 27; y := 5; wid := 30; pic := ''; End;
107
 
         End;
108
 
      End;
109
 
   End;
110
 
 
111
 
   att1 := 19; { field display color }
112
 
   att2 := 31; { field edit color }
113
 
   att3 := 23; { labels color }
114
 
 
115
 
   nMakeWindow(win,1,1,60,10,att3,30,63,true,center,' Rainer''s Address Book ');
116
 
   With win Do Begin
117
 
      Align(center,center);
118
 
      FWrite(1,Rows,48,Cols,'[F2]-Arrows [F10]-Exit [Tab]-NextField [^P]-Prev [^N]-Next');
119
 
      Writeln;
120
 
      Writeln(' First Name [                                        ]');
121
 
      Writeln('  Last Name [                                        ]');
122
 
      Writeln('     Street [                                        ]');
123
 
      Write  ('   Zip/City [  ]-[     ] [                              ]');
124
 
      Show;
125
 
      ec.AddChMap(^P#0#0+Char(nKeyPgUp));
126
 
      ec.AddChMap(^N#0#0+Char(nKeyPgDn));
127
 
      BindArrows;
128
 
      row := 1;
129
 
      col := 1;
130
 
      display(row);
131
 
      IsDone := false;
132
 
      Repeat
133
 
         Str(row:2,s);
134
 
         FWrite((cols-10) div 2,rows-1,26,0,'Record #'+s);
135
 
         With address[row] Do Begin
136
 
            With fields[col] Do Begin
137
 
               ec.Picture := pic;
138
 
               Case col of
139
 
                  1 : s := FirstName;
140
 
                  2 : s := LastName;
141
 
                  3 : s := Street;
142
 
                  4 : s := Country;
143
 
                  5 : s := Zip;
144
 
                  6 : s := City;
145
 
               End;
146
 
               s := Edit(x,y,att2,x+wid-1,x+Length(s),s,ch);
147
 
               If ch <> #27 Then
148
 
                  Case col of
149
 
                     1 : FirstName := s;
150
 
                     2 : LastName := s;
151
 
                     3 : Street := s;
152
 
                     4 : Country := s;
153
 
                     5 : Zip := s;
154
 
                     6 : City := s;
155
 
                  End;
156
 
               FWrite(x,y,att1,x+wid-1,s);
157
 
               Case Ord(ch) of
158
 
                   9,
159
 
                  13,
160
 
                  Ord(^r) : Inc(col);
161
 
                  Ord(^l) : Dec(col);
162
 
                  nKeyUp : Case col of
163
 
                     1 : col := 4;
164
 
                     2,3,4 : Dec(col);
165
 
                     5,6 : col := 3;
166
 
                  End;
167
 
                  nKeyDown : Case col of
168
 
                     1..3 : Inc(col);
169
 
                     4..6 : col := 1;
170
 
                  End;
171
 
                  nKeyPgDn : Inc(row);
172
 
                  nKeyPgUp : Dec(row);
173
 
                  nKeyF2 : UnBindArrows; { use arrows for editing }
174
 
                  nKeyF10 : IsDone := true;
175
 
               End;
176
 
            End;
177
 
         End;
178
 
         If row > MAXROWS Then row := MAXROWS;
179
 
         If row < 1 Then row := 1;
180
 
         If col > MAXCOLS Then col := 1;
181
 
         If col < 1 Then col := MAXCOLS;
182
 
         If Ord(ch) in [nKeyPgUp,nKeyPgDn] Then Display(row);
183
 
         If Ord(ch) <> nKeyF2 Then BindArrows; { arrows for navigation }
184
 
      Until IsDone;
185
 
      Hide;
186
 
      Done;
187
 
   End;
188
 
End.