fpevalw.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. {
  2. Copyright (c) 1997-2008 by the Daniel Mantione
  3. Debug expression evaluator dialog
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. unit fpevalw;
  11. {$H-}
  12. {****************************************************************************}
  13. interface
  14. {****************************************************************************}
  15. uses fpdebug,dialogs,WViews,objects,fpconst,drivers,WEditor;
  16. type Pevaluate_dialog=^Tevaluate_dialog;
  17. Tevaluate_dialog=object(TCenterDialog)
  18. watch : PWatch;
  19. expr_input : PEditorInputLine;
  20. expr_output : PEditorInputLine;
  21. constructor init(var bounds:Trect);
  22. procedure evaluate;
  23. procedure HandleEvent(var Event:TEvent);virtual;
  24. destructor done;
  25. end;
  26. {****************************************************************************}
  27. implementation
  28. {****************************************************************************}
  29. uses FPViews;
  30. constructor Tevaluate_dialog.init(var bounds:Trect);
  31. var r:Trect;
  32. l:Plabel;
  33. b:Pbutton;
  34. EditorWindow : PSourceWindow;
  35. S : String;
  36. begin
  37. inherited init(bounds,'Evaluate expression');
  38. {watch is auto initialized to nil.}
  39. r.assign(2,3,size.x-20,4);
  40. new(expr_input,init(r,255));
  41. insert(expr_input);
  42. r.assign(size.x-20,3,size.x-18,4);
  43. insert(new(Phistory,init(r,expr_input,hidEvaluate)));
  44. r.assign(2,2,size.x-20,3);
  45. new(l,init(r,'E~x~pression:',expr_input));
  46. insert(l);
  47. r.assign(2,6,size.x-20,7);
  48. new(expr_output,init(r,255));
  49. insert(expr_output);
  50. r.assign(2,5,size.x-20,6);
  51. new(l,init(r,'~R~esult:',expr_output));
  52. insert(l);
  53. r.assign(size.x-14,3,size.x-3,5);
  54. new(b,init(r,'~E~valuate',cmEvaluate,bfDefault));
  55. insert(b);
  56. //r.assign(size.x-14,6,size.x-3,8);
  57. //new(b,init(r,'Help',cmHelp,bfNormal));
  58. //insert(b);
  59. EditorWindow:=FirstEditorWindow;
  60. If assigned(EditorWindow) then
  61. S:=EditorWindow^.Editor^.GetCurrentWord
  62. else
  63. S:='';
  64. expr_input^.SetData(S);
  65. expr_input^.Select;
  66. if s <>'' then
  67. evaluate;
  68. { for right arrow to give a char from EditorWindow }
  69. if assigned(EditorWindow) then
  70. FindReplaceEditor:=EditorWindow^.Editor;
  71. end;
  72. procedure Tevaluate_dialog.Evaluate;
  73. begin
  74. if watch<>nil then
  75. dispose(watch,done);
  76. new(watch,init(expr_input^.data^));
  77. expr_output^.data^:=strpas(watch^.current_value);
  78. expr_output^.drawview;
  79. end;
  80. procedure Tevaluate_dialog.HandleEvent(var Event:TEvent);
  81. begin
  82. inherited HandleEvent(Event);
  83. if Event.what=evCommand then
  84. case Event.command of
  85. cmEvaluate:
  86. evaluate;
  87. end;
  88. end;
  89. destructor Tevaluate_dialog.done;
  90. begin
  91. FindReplaceEditor:=nil;
  92. if watch<>nil then
  93. dispose(watch,done);
  94. end;
  95. end.