AddBreakpoint.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. unit AddBreakpoint;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, ExtCtrls, lua, lualib, lauxlib, LuaUtils, Misc;
  6. type
  7. TfrmAddBreakpoint = class(TForm)
  8. Panel1: TPanel;
  9. Panel2: TPanel;
  10. Button1: TButton;
  11. Button2: TButton;
  12. Label1: TLabel;
  13. cboUnits: TComboBox;
  14. Label2: TLabel;
  15. txtCondition: TEdit;
  16. Label3: TLabel;
  17. txtLine: TEdit;
  18. procedure txtLineKeyPress(Sender: TObject; var Key: Char);
  19. procedure Button2Click(Sender: TObject);
  20. procedure FormShow(Sender: TObject);
  21. private
  22. { Private declarations }
  23. public
  24. { Public declarations }
  25. end;
  26. var
  27. frmAddBreakpoint: TfrmAddBreakpoint;
  28. implementation
  29. uses Main, Breakpoints;
  30. {$R *.dfm}
  31. procedure TfrmAddBreakpoint.txtLineKeyPress(Sender: TObject; var Key: Char);
  32. begin
  33. if ((not (Ord(Key) in [48..57])) and (not (Ord(Key) = 8))) then
  34. Key := Char(0);
  35. end;
  36. procedure TfrmAddBreakpoint.Button2Click(Sender: TObject);
  37. var
  38. ReturnMsg: String;
  39. L: PLua_State;
  40. pBreakpoint: TBreakpoint;
  41. begin
  42. ModalResult := mrNone;
  43. if cboUnits.ItemIndex = -1 then
  44. begin
  45. Application.MessageBox('Please choose a unit where to add the breakpoint.', 'LuaEdit', MB_OK+MB_ICONERROR);
  46. cboUnits.SetFocus;
  47. Exit;
  48. end;
  49. if txtLine.Text = '' then
  50. begin
  51. Application.MessageBox('Please choose a line where to add the breakpoint.', 'LuaEdit', MB_OK+MB_ICONERROR);
  52. txtLine.SetFocus;
  53. Exit;
  54. end;
  55. if TLuaEditUnit(cboUnits.Items.Objects[cboUnits.ItemIndex]).DebugInfos.GetBreakpointAtLine(StrToInt(txtLine.Text)) <> nil then
  56. begin
  57. Application.MessageBox(PChar('There is already a breakpoint set at line number '+txtLine.Text+'!'), 'LuaEdit', MB_OK+MB_ICONERROR);
  58. txtLine.SetFocus;
  59. Exit;
  60. end;
  61. if txtCondition.Text <> '' then
  62. begin
  63. L := lua_open;
  64. // test the given expression
  65. if luaL_loadbuffer(L, PChar('return ('+txtCondition.Text+')'), Length('return ('+txtCondition.Text+')'), 'Main') <> 0 then
  66. begin
  67. ReturnMsg := lua_tostring(L, 1);
  68. ReturnMsg := Copy(ReturnMsg, Pos(':', ReturnMsg) + 1, Length(ReturnMsg) - Pos(':', ReturnMsg));
  69. ReturnMsg := Copy(ReturnMsg, Pos(':', ReturnMsg) + 1, Length(ReturnMsg) - Pos(':', ReturnMsg));
  70. Application.MessageBox(PChar('The expression "'+txtCondition.Text+'" is not a valid expression: '#13#10#13#10#13#10+ReturnMsg), 'LuaEdit', MB_OK+MB_ICONERROR);
  71. txtCondition.SetFocus;
  72. Exit;
  73. end;
  74. lua_close(L);
  75. end;
  76. if txtLine.Text = '' then
  77. begin
  78. Application.MessageBox('You must specify a line number where to insert the breakpoint!', 'LuaEdit', MB_OK+MB_ICONERROR);
  79. txtLine.SetFocus;
  80. Exit;
  81. end
  82. else if (StrToInt(txtLine.Text) > TLuaEditUnit(cboUnits.Items.Objects[cboUnits.ItemIndex]).synUnit.Lines.Count) or (StrToInt(txtLine.Text) < 1) then
  83. begin
  84. Application.MessageBox(PChar('The line number must stands between 1 and '+IntToStr(TLuaEditUnit(cboUnits.Items.Objects[cboUnits.ItemIndex]).synUnit.Lines.Count)+' for the unit "'+TLuaEditUnit(cboUnits.Items.Objects[cboUnits.ItemIndex]).Name+'"'), 'LuaEdit', MB_OK+MB_ICONERROR);
  85. txtLine.SetFocus;
  86. Exit;
  87. end;
  88. if cboUnits.Text = '' then
  89. begin
  90. Application.MessageBox('You must select a unit where to insert the breakpoint!', 'LuaEdit', MB_OK+MB_ICONERROR);
  91. cboUnits.SetFocus;
  92. Exit;
  93. end;
  94. pBreakpoint := TBreakpoint.Create;
  95. pBreakpoint.sCondition := txtCondition.Text;
  96. pBreakpoint.iLine := StrToInt(txtLine.Text);
  97. TLuaEditUnit(cboUnits.Items.Objects[cboUnits.ItemIndex]).DebugInfos.lstBreakpoint.Add(pBreakpoint);
  98. frmBreakpoints.RefreshBreakpointList;
  99. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab.Data) then
  100. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.Refresh;
  101. ModalResult := mrOk;
  102. end;
  103. procedure TfrmAddBreakpoint.FormShow(Sender: TObject);
  104. var
  105. x: Integer;
  106. begin
  107. cboUnits.Items.Clear;
  108. for x := 0 to LuaOpenedFiles.Count - 1 do
  109. begin
  110. cboUnits.AddItem(TLuaEditUnit(LuaOpenedFiles.Items[x]).Name, LuaOpenedFiles.Items[x]);
  111. end;
  112. txtCondition.Text := '';
  113. txtLine.Text := '';
  114. end;
  115. end.