Changeset 206 for branches/interpreter2/UFormMain.pas
- Timestamp:
- Apr 20, 2020, 10:23:44 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter2/UFormMain.pas
r205 r206 7 7 uses 8 8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus, 9 ActnList, SynHighlighterPas, SynEdit, USource;9 ActnList, ExtCtrls, SynHighlighterPas, SynEdit, USource; 10 10 11 11 type … … 14 14 15 15 TFormMain = class(TForm) 16 ButtonCompile: TButton; 17 ButtonGenerate1: TButton; 18 ButtonRun: TButton; 19 ButtonGenerate: TButton; 20 Label1: TLabel; 16 ACompile: TAction; 17 AExit: TAction; 18 ARun: TAction; 19 AGenerateCSharp: TAction; 20 AGeneratePhp: TAction; 21 AGeneratePascal: TAction; 22 ActionList1: TActionList; 21 23 Label2: TLabel; 22 M emoLog: TMemo;24 MainMenu1: TMainMenu; 23 25 MemoOutput: TMemo; 24 SynEditSource: TSynEdit; 25 SynFreePascalSyn1: TSynFreePascalSyn; 26 procedure ButtonCompileClick(Sender: TObject); 27 procedure ButtonGenerate1Click(Sender: TObject); 28 procedure ButtonGenerateClick(Sender: TObject); 29 procedure ButtonRunClick(Sender: TObject); 26 MenuItem1: TMenuItem; 27 MenuItem2: TMenuItem; 28 MenuItem3: TMenuItem; 29 MenuItem4: TMenuItem; 30 MenuItem5: TMenuItem; 31 MenuItem6: TMenuItem; 32 MenuItemRun: TMenuItem; 33 MenuItemGenerate: TMenuItem; 34 MenuItemFile: TMenuItem; 35 PanelSource: TPanel; 36 PanelMessages: TPanel; 37 procedure ACompileExecute(Sender: TObject); 38 procedure AExitExecute(Sender: TObject); 39 procedure AGenerateCSharpExecute(Sender: TObject); 40 procedure AGeneratePascalExecute(Sender: TObject); 41 procedure AGeneratePhpExecute(Sender: TObject); 42 procedure ARunExecute(Sender: TObject); 30 43 procedure FormActivate(Sender: TObject); 31 44 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); … … 38 51 procedure InterpreterError(Pos: TPoint; Text: string); 39 52 procedure UpdateInterface; 53 procedure DockForm(Form: TForm; DockSite: TWinControl); 40 54 public 41 55 … … 51 65 52 66 uses 53 UParser, UExecutor, UGeneratorPascal, UGeneratorPhp; 67 UParser, UExecutor, UGeneratorPascal, UGeneratorPhp, UFormMessages, UFormSource, 68 UGeneratorCSharp; 54 69 55 70 { TFormMain } … … 59 74 if not Initialized then begin 60 75 Initialized := True; 61 SynEditSource.Lines.LoadFromFile('Test.pas');62 ButtonRun.Click;76 FormSource.SynEditSource.Lines.LoadFromFile('Test.pas'); 77 ARun.Execute; 63 78 end; 64 79 end; … … 76 91 procedure TFormMain.FormShow(Sender: TObject); 77 92 begin 93 DockForm(FormMessages, PanelMessages); 94 DockForm(FormSource, PanelSource); 78 95 UpdateInterface; 79 96 end; 80 97 81 procedure TFormMain.ButtonRunClick(Sender: TObject); 98 procedure TFormMain.AExitExecute(Sender: TObject); 99 begin 100 Close; 101 end; 102 103 procedure TFormMain.ACompileExecute(Sender: TObject); 104 var 105 Parser: TParser; 106 begin 107 FormMessages.Clear; 108 Parser := TParser.Create; 109 Parser.OnError := InterpreterError; 110 Parser.Source := FormSource.SynEditSource.Lines.Text; 111 Parser.Parse; 112 if Assigned(Prog) then Prog.Free; 113 Prog := Parser.Prog; 114 Parser.Free; 115 UpdateInterface; 116 end; 117 118 procedure TFormMain.AGenerateCSharpExecute(Sender: TObject); 119 var 120 Generator: TGeneratorCSharp; 121 begin 122 ACompile.Execute; 123 MemoOutput.Lines.Clear; 124 if Assigned(Prog) then begin 125 Generator := TGeneratorCSharp.Create; 126 Generator.Prog := Prog; 127 Generator.Generate; 128 MemoOutput.Lines.Text := Generator.Output; 129 Generator.Free; 130 MemoOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.cs'); 131 end; 132 end; 133 134 procedure TFormMain.AGeneratePascalExecute(Sender: TObject); 135 var 136 Generator: TGeneratorPascal; 137 begin 138 ACompile.Execute; 139 MemoOutput.Lines.Clear; 140 if Assigned(Prog) then begin 141 Generator := TGeneratorPascal.Create; 142 Generator.Prog := Prog; 143 Generator.Generate; 144 MemoOutput.Lines.Text := Generator.Output; 145 Generator.Free; 146 MemoOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.pas'); 147 end; 148 end; 149 150 procedure TFormMain.AGeneratePhpExecute(Sender: TObject); 151 var 152 Generator: TGeneratorPhp; 153 begin 154 ACompile.Execute; 155 MemoOutput.Lines.Clear; 156 if Assigned(Prog) then begin 157 Generator := TGeneratorPhp.Create; 158 Generator.Prog := Prog; 159 Generator.Generate; 160 MemoOutput.Lines.Text := Generator.Output; 161 Generator.Free; 162 MemoOutput.Lines.SaveToFile('Generated' + DirectorySeparator + 'Test.php'); 163 end; 164 end; 165 166 procedure TFormMain.ARunExecute(Sender: TObject); 82 167 var 83 168 Executor: TExecutor; 84 169 begin 85 ButtonCompile.Click;170 ACompile.Execute; 86 171 MemoOutput.Lines.Clear; 87 172 if Assigned(Prog) then begin … … 94 179 end; 95 180 96 procedure TFormMain.ButtonCompileClick(Sender: TObject);97 var98 Parser: TParser;99 begin100 MemoLog.Lines.Clear;101 Parser := TParser.Create;102 Parser.OnError := InterpreterError;103 Parser.Source := SynEditSource.Lines.Text;104 Parser.Parse;105 if Assigned(Prog) then Prog.Free;106 Prog := Parser.Prog;107 Parser.Free;108 UpdateInterface;109 end;110 111 procedure TFormMain.ButtonGenerate1Click(Sender: TObject);112 var113 Generator: TGeneratorPhp;114 begin115 ButtonCompile.Click;116 MemoOutput.Lines.Clear;117 if Assigned(Prog) then begin118 Generator := TGeneratorPhp.Create;119 Generator.Prog := Prog;120 Generator.Generate;121 MemoOutput.Lines.Text := Generator.Output;122 Generator.Free;123 end;124 end;125 126 procedure TFormMain.ButtonGenerateClick(Sender: TObject);127 var128 Generator: TGeneratorPascal;129 begin130 ButtonCompile.Click;131 MemoOutput.Lines.Clear;132 if Assigned(Prog) then begin133 Generator := TGeneratorPascal.Create;134 Generator.Prog := Prog;135 Generator.Generate;136 MemoOutput.Lines.Text := Generator.Output;137 Generator.Free;138 end;139 end;140 141 181 procedure TFormMain.InterpreterError(Pos: TPoint; Text: string); 142 182 begin 143 MemoLog.Lines.Add('[' + IntToStr(Pos.X) + ', ' + IntToStr(Pos.Y) + '] ' + Text);183 FormMessages.AddLine('[' + IntToStr(Pos.X) + ', ' + IntToStr(Pos.Y) + '] ' + Text); 144 184 end; 145 185 146 186 procedure TFormMain.UpdateInterface; 147 187 begin 148 ButtonRun.Enabled := Assigned(Prog); 188 end; 189 190 procedure TFormMain.DockForm(Form: TForm; DockSite: TWinControl); 191 begin 192 Form.ManualDock(DockSite, nil, alClient); 193 Form.Align := alClient; 194 Form.Show; 149 195 end; 150 196
Note:
See TracChangeset
for help on using the changeset viewer.