source: branches/Void/UMainForm.pas

Last change on this file was 17, checked in by george, 15 years ago
  • Přidáno: Při kliknutí na chybové hlášení se přesune kurzor v kódu na místo chyby.
File size: 3.5 KB
Line 
1unit UMainForm;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
9 StdCtrls, ComCtrls, SynHighlighterPas, SynEdit, SynHighlighterCpp,
10 UCompilator, UOutputGenerator, UModelViewer, UPascalGenerator, UCGenerator,
11 UZ80Generator;
12
13const
14 SourceFileName = 'Example.void';
15
16type
17
18 { TMainForm }
19
20 TMainForm = class(TForm)
21 ButtonCompile: TButton;
22 ComboBox1: TComboBox;
23 Label1: TLabel;
24 Label2: TLabel;
25 Label3: TLabel;
26 Label4: TLabel;
27 ListView1: TListView;
28 SynCppSyn1: TSynCppSyn;
29 SynEdit1: TSynEdit;
30 SynEdit2: TSynEdit;
31 SynPasSyn1: TSynPasSyn;
32 TreeView1: TTreeView;
33 procedure ButtonCompileClick(Sender: TObject);
34 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
35 procedure FormCreate(Sender: TObject);
36 procedure FormDestroy(Sender: TObject);
37 procedure FormShow(Sender: TObject);
38 procedure ListView1Click(Sender: TObject);
39 private
40 SourceCode: TMemoryStream;
41 ModelViewer: TModelViewer;
42 procedure CompilatorError(Text: string; var Terminate: Boolean;
43 Position: TPoint);
44 public
45 Compilator: TCompilator;
46 end;
47
48var
49 MainForm: TMainForm;
50
51implementation
52
53{ TMainForm }
54
55procedure TMainForm.FormShow(Sender: TObject);
56begin
57 SynEdit1.Lines.LoadFromFile(SourceFileName);
58 ButtonCompileClick(Self);
59end;
60
61procedure TMainForm.ListView1Click(Sender: TObject);
62begin
63 if Assigned(ListView1.Selected) then begin
64 SynEdit1.CaretXY := TErrorMessage(Compilator.ErrorMessages[
65 ListView1.Selected.Index]).CodePosition;
66 SynEdit1.SetFocus;
67 end;
68end;
69
70procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
71begin
72 SynEdit1.Lines.SaveToFile(SourceFileName);
73end;
74
75procedure TMainForm.FormCreate(Sender: TObject);
76begin
77 Compilator := TCompilator.Create;
78 Compilator.OnError := CompilatorError;
79 ModelViewer := TModelViewer.Create;
80end;
81
82procedure TMainForm.FormDestroy(Sender: TObject);
83begin
84 Compilator.Destroy;
85 ModelViewer.Destroy;
86end;
87
88procedure TMainForm.ButtonCompileClick(Sender: TObject);
89var
90 Code: string;
91 OutputFileName: string;
92begin
93 with Compilator do begin
94 ListView1.Clear;
95 Code := SynEdit1.Lines.Text;
96 SourceCode.Size := 0;
97 SourceCode.Write(Code[1], Length(Code));
98 if Assigned(Generator) then Generator.Destroy;
99 if ComboBox1.ItemIndex = 0 then begin
100 Generator := TPascalGenerator.Create;
101 SynEdit2.Highlighter := SynPasSyn1;
102 OutputFileName := 'Output.dpr';
103 end else
104 if ComboBox1.ItemIndex = 1 then begin
105 Generator := TCGenerator.Create;
106 SynEdit2.Highlighter := SynCppSyn1;
107 OutputFileName := 'Output.c';
108 end else
109 if ComboBox1.ItemIndex = 2 then begin
110 Generator := TZ80Generator.Create;
111 SynEdit2.Highlighter := SynCppSyn1;
112 OutputFileName := 'Output.asm';
113 end;
114
115 try
116 Compile;
117 except
118 end;
119
120 SynEdit2.Lines.Assign(Generator.Output);
121 SynEdit2.Lines.SaveToFile(OutputFileName);
122 ModelViewer.Show(TreeView1);
123 end;
124end;
125
126procedure TMainForm.CompilatorError(Text: string; var Terminate: Boolean;
127 Position: TPoint);
128var
129 NewItem: TListItem;
130begin
131 Terminate := False;
132 NewItem := ListView1.Items.Add;
133 with NewItem do begin
134 Caption := '';
135 SubItems.Add(IntToStr(Position.X) + ', ' + IntToStr(Position.Y));
136 SubItems.Add('Error: ' + Text);
137 end;
138end;
139
140initialization
141 {$I UMainForm.lrs}
142
143end.
144
Note: See TracBrowser for help on using the repository browser.