edit_demo.pp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. Program Edit_Demo;
  2. {---------------------------------------------------------------------------
  3. CncWare
  4. (c) Copyright 1999
  5. ---------------------------------------------------------------------------
  6. Filename..: edit_demo.pp
  7. Programmer: Ken J. Wright, [email protected]
  8. Date......: 12/12/99
  9. Purpose - Demonstrate the use of nCrt unit.
  10. -------------------------------<< REVISIONS >>--------------------------------
  11. Ver | Date | Prog| Description
  12. -------+----------+-----+-----------------------------------------------------
  13. 1.00 | 12/12/99 | kjw | Initial Release.
  14. 1.01 | 12/13/99 | kjw | Changed to use oCrt.
  15. ------------------------------------------------------------------------------
  16. }
  17. uses oCrt;
  18. var
  19. ss : array[1..25] of string[80];
  20. xp,yp,
  21. s : string;
  22. c : char;
  23. win1,status : tnWindow;
  24. idx : integer;
  25. Finished : boolean;
  26. Begin
  27. Status.Init(1,25,80,25,63,false,0);
  28. Status.FWrite(1,1,63,80,' [F1-InsLn] [F2-DelLn] [F10-Exit]');
  29. Status.Show;
  30. fillchar(ss,sizeof(ss),#0);
  31. win1.Init(1,1,80,24,31,true,31);
  32. win1.PutHeader(' nCrt Editor Demonstration ',15,center);
  33. win1.Show;
  34. win1.GotoXY(1,1);
  35. {--------------------------------------------------------------------
  36. The next line causes sedit to exit after every keystroke so we can
  37. capture the insert mode and cursor positions.
  38. --------------------------------------------------------------------}
  39. win1.ec.ExitMode := true;
  40. idx := 1;
  41. Finished := false;
  42. Repeat
  43. With win1 Do Begin
  44. Case ec.InsMode of
  45. true : Status.FWrite(40,1,48,0,'Ins');
  46. false: Status.FWrite(40,1,48,0,'Ovr');
  47. End;
  48. Str(WhereX:0,xp);
  49. Str(WhereY:0,yp);
  50. Status.FWrite(50,1,48,80,'X='+xp+', Y='+yp);
  51. ss[idx] := SEdit(1,idx,30,Cols,WhereX,ss[idx],c);
  52. Case ord(c) of
  53. nKeyUp : dec(idx);
  54. nKeyDown : inc(idx);
  55. nKeyPgUp : idx := 1;
  56. nKeyPgDn : idx := Rows;
  57. nKeyEnter: Begin
  58. inc(idx);
  59. GotoXY(1,WhereY);
  60. End;
  61. nKeyF1 : Begin
  62. InsLine;
  63. system.move(ss[idx],ss[idx+1],(rows-idx)*81);
  64. ss[idx] := '';
  65. End;
  66. nKeyF2 : Begin
  67. DelLine;
  68. system.move(ss[idx+1],ss[idx],(rows-idx)*81);
  69. ss[rows] := '';
  70. End;
  71. nKeyEsc,
  72. nKeyF10 : Finished := true;
  73. End;
  74. If idx > rows Then idx := rows;
  75. If idx < 1 Then idx := 1;
  76. GotoXY(WhereX,idx);
  77. End;
  78. Until Finished;
  79. win1.Done;
  80. Status.Done;
  81. halt(1);
  82. End.