db_demo.pp 5.6 KB

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