Changeset 54 for branches/DelphiToC/Forms/UMainForm.pas
- Timestamp:
- Aug 10, 2010, 11:54:18 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/Forms/UMainForm.pas
r53 r54 9 9 Dialogs, StdCtrls, USourceCode, UCompiler, UProducerAsm8051, 10 10 UProducerC, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, UProducerTreeView, 11 UProducerPascal, Contnrs ;11 UProducerPascal, Contnrs, UProject; 12 12 13 13 const 14 ExampleFileName = '../../Example.pas';14 ProjectDir = '../../Project/'; 15 15 16 16 type … … 24 24 SynEdit1: TSynEdit; 25 25 SynPasSyn1: TSynPasSyn; 26 TreeViewProject: TTreeView; 26 27 procedure ComboBox1Change(Sender: TObject); 27 28 procedure FormShow(Sender: TObject); … … 31 32 procedure FormDestroy(Sender: TObject); 32 33 procedure ListBox1Click(Sender: TObject); 34 procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode); 35 private 33 36 procedure LoadErrorMessages; 34 private 37 procedure UpdateProjectTree; 38 procedure UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup); 35 39 public 40 Project: TProject; 36 41 ProducerControl: TControl; 37 42 Compiler: TCompiler; 38 SourceTree: TProducerTreeView;39 43 end; 40 44 … … 52 56 I: Integer; 53 57 begin 54 MainForm.ListBox1.Clear;55 Compiler.SourceCode.Assign(SynEdit1.Lines);56 57 58 ProducerControl.Free; 58 59 if ComboBox1.ItemIndex = 0 then begin 59 60 Compiler.Producer.Free; 60 61 Compiler.Producer := TProducerPascal.Create; 61 Compiler.Producer.ProgramCode := Compiler.ProgramCode; 62 Compiler.Compile; 62 end else 63 if ComboBox1.ItemIndex = 1 then begin 64 Compiler.Producer.Free; 65 Compiler.Producer := TProducerC.Create; 66 end else 67 if ComboBox1.ItemIndex = 2 then begin 68 Compiler.Producer.Free; 69 Compiler.Producer := TProducerAsm8051.Create; 70 end else 71 if ComboBox1.ItemIndex = 3 then begin 72 Compiler.Producer.Free; 73 Compiler.Producer := TProducerTreeView.Create; 74 ProducerControl := TTreeView.Create(Self); 75 ProducerControl.Parent := Panel1; 76 ProducerControl.Align := alClient; 77 TProducerTreeView(Compiler.Producer).TreeView := TTreeView(ProducerControl); 78 end; 79 80 // Compile all project files 81 for I := 0 to Project.Items.Count - 1 do begin 82 if TProjectNode(Project.Items[I]) is TProjectFile then begin 83 Compiler.Compile(TProjectFile(Project.Items[I]).Source, 84 TProjectFile(Project.Items[I]).ProducedCode); 85 end; 86 end; 87 88 if ComboBox1.ItemIndex = 0 then begin 63 89 ProducerControl := TMemo.Create(Self); 64 90 ProducerControl.Parent := Panel1; … … 66 92 ProducerControl.Font.Name := 'Courier New'; 67 93 TMemo(ProducerControl).ScrollBars := ssAutoBoth; 68 with TProducerPascal(Compiler.Producer) do69 TMemo(ProducerControl).Lines.Assign(TextSource);70 94 end else 71 95 if ComboBox1.ItemIndex = 1 then begin 72 Compiler.Producer.Free;73 Compiler.Producer := TProducerC.Create;74 Compiler.Producer.ProgramCode := Compiler.ProgramCode;75 Compiler.Compile;76 96 ProducerControl := TMemo.Create(Self); 77 97 ProducerControl.Parent := Panel1; … … 79 99 ProducerControl.Font.Name := 'Courier New'; 80 100 TMemo(ProducerControl).ScrollBars := ssAutoBoth; 81 with TProducerC(Compiler.Producer) do82 TMemo(ProducerControl).Lines.Assign(TextSource);83 101 end else 84 102 if ComboBox1.ItemIndex = 2 then begin 85 Compiler.Producer.Free;86 Compiler.Producer := TProducerAsm8051.Create;87 Compiler.Producer.ProgramCode := Compiler.ProgramCode;88 Compiler.Compile;89 103 ProducerControl := TMemo.Create(Self); 90 104 ProducerControl.Parent := Panel1; … … 92 106 ProducerControl.Font.Name := 'Courier New'; 93 107 TMemo(ProducerControl).ScrollBars := ssAutoBoth; 94 with TProducerAsm8051(Compiler.Producer) do 95 for I := 0 to AssemblyCode.Count - 1 do 96 TMemo(ProducerControl).Lines.Add(TAssemblerLine(AssemblyCode[I]).AsString); 97 end; 108 end else 98 109 if ComboBox1.ItemIndex = 3 then begin 99 Compiler.Producer.Free; 100 Compiler.Producer := TProducerTreeView.Create; 101 Compiler.Producer.ProgramCode := Compiler.ProgramCode; 102 ProducerControl := TTreeView.Create(Self); 103 ProducerControl.Parent := Panel1; 104 ProducerControl.Align := alClient; 105 TProducerTreeView(Compiler.Producer).TreeView := TTreeView(ProducerControl); 106 Compiler.Compile; 107 end; 110 end; 111 108 112 LoadErrorMessages; 109 113 end; … … 128 132 end; 129 133 134 procedure TMainForm.TreeViewProjectChange(Sender: TObject; Node: TTreeNode); 135 begin 136 if Assigned(Node) then begin 137 if TProjectNode(Node.Data) is TProjectFile then begin 138 SynEdit1.Lines.Assign(TProjectFile(Node.Data).Source); 139 if ProducerControl is TMemo then 140 TMemo(ProducerControl).Lines.Assign(TProjectFile(Node.Data).ProducedCode); 141 end; 142 end; 143 end; 144 145 procedure TMainForm.UpdateProjectTree; 146 var 147 NewNode: TTreeNode; 148 begin 149 with TreeViewProject, Items do begin 150 BeginUpdate; 151 Clear; 152 NewNode := AddChild(nil, Project.Name); 153 UpdateProjectGroup(NewNode, Project); 154 NewNode.Expand(True); 155 EndUpdate; 156 end; 157 TreeViewProject.TopItem.Items[0].Selected := True; 158 end; 159 160 procedure TMainForm.UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup); 161 var 162 I: Integer; 163 NewNode: TTreeNode; 164 begin 165 for I := 0 to Group.Items.Count - 1 do begin 166 NewNode := TreeViewProject.Items.AddChild(Node, 167 TProjectNode(Group.Items[I]).Name); 168 NewNode.Data := Pointer(Group.Items[I]); 169 if TProjectNode(Group.Items[I]) is TProjectGroup then 170 UpdateProjectGroup(NewNode, TProjectGroup(Group.Items[I])); 171 end; 172 end; 173 130 174 procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction); 131 175 begin 132 SynEdit1.Lines.SaveToFile(ExampleFileName);176 Project.Save; 133 177 end; 134 178 … … 136 180 begin 137 181 Compiler := TCompiler.Create; 138 SourceTree := TProducerTreeView.Create;182 Project := TProject.Create; 139 183 end; 140 184 141 185 procedure TMainForm.FormDestroy(Sender: TObject); 142 186 begin 187 Project.Free; 143 188 Compiler.Free; 144 SourceTree.Free;145 189 end; 146 190 147 191 procedure TMainForm.FormShow(Sender: TObject); 148 begin 192 var 193 NewProjectFile: TProjectFile; 194 begin 195 Project.Name := 'Project'; 196 NewProjectFile := TProjectFile.Create; 197 NewProjectFile.Name := 'Project.pas'; 198 NewProjectFile.FileName := ProjectDir + 'Project.pas'; 199 Project.Items.Add(NewProjectFile); 200 NewProjectFile := TProjectFile.Create; 201 NewProjectFile.Name := 'System.pas'; 202 NewProjectFile.FileName := ProjectDir + 'System.pas'; 203 Project.Items.Add(NewProjectFile); 204 Project.Load; 205 UpdateProjectTree; 206 149 207 WindowState := wsMaximized; 150 SynEdit1.Lines.LoadFromFile(ExampleFileName);151 208 ButtonCompileClick(Self); 152 209 end;
Note:
See TracChangeset
for help on using the changeset viewer.