Changeset 25 for trunk/Forms/UMainForm.pas
- Timestamp:
- Feb 13, 2012, 9:47:18 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UMainForm.pas
r24 r25 8 8 Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs, 9 9 Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck, UCoolTranslator, StrUtils, 10 SpecializedList, UCompiler, Registry, URegistry, ULastOpenedList ;10 SpecializedList, UCompiler, Registry, URegistry, ULastOpenedList, Process; 11 11 12 12 const … … 21 21 AAbout: TAction; 22 22 ABreakpointToggle: TAction; 23 ACompileAndRun: TAction; 24 AViewCompilers: TAction; 23 25 AGenerateNumber: TAction; 24 26 AShrinkSource: TAction; … … 68 70 MenuItem28: TMenuItem; 69 71 MenuItem29: TMenuItem; 72 MenuItem30: TMenuItem; 73 MenuItem31: TMenuItem; 70 74 MenuItemOpenRecent: TMenuItem; 71 75 MenuItemTarget: TMenuItem; … … 95 99 ToolButton9: TToolButton; 96 100 procedure ABreakpointToggleExecute(Sender: TObject); 101 procedure ACompileAndRunExecute(Sender: TObject); 97 102 procedure ACompileExecute(Sender: TObject); 98 103 procedure AExitExecute(Sender: TObject); … … 110 115 procedure AShrinkSourceExecute(Sender: TObject); 111 116 procedure AViewCompiledExecute(Sender: TObject); 117 procedure AViewCompilersExecute(Sender: TObject); 112 118 procedure AViewInterpretterExecute(Sender: TObject); 113 119 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); … … 135 141 BrainFuckInterpreter: TBrainFuckInterpretter; 136 142 BreakPoints: TListInteger; 137 Compilers: T ListObject; // TListObject<TCompiler>143 Compilers: TCompilerList; 138 144 LastOpenedList: TLastOpenedList; 139 145 OpenProjectOnStart: Boolean; … … 142 148 procedure UpdateInterface; 143 149 procedure UpdateStatusBar; 144 procedure UpdateT ergetList;150 procedure UpdateTargetList; 145 151 end; 146 152 … … 154 160 uses 155 161 UInterpretterForm, UApplicationInfo, UCompiledForm, UOptionsForm, 156 UCompilerDelphi, UCompilerPHP ;162 UCompilerDelphi, UCompilerPHP, UCompilersForm; 157 163 158 164 resourcestring 159 165 SEnterNumber = 'Enter number'; 160 166 SNumberGeneration = 'Number generation'; 167 SProgramExited = 'Program exited'; 168 SCompilerNotFound = 'Compiler "%s" not found'; 169 SCompiledFileNotFound = 'Program compiled file "%s" not found'; 161 170 162 171 { TMainForm } … … 167 176 ProjectOpen(LastOpenedList[0]) 168 177 else AProjectNew.Execute; 178 UpdateInterface; 169 179 end; 170 180 … … 234 244 CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', '')) 235 245 else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(''); 246 CompilerIndex := ReadIntegerWithDefault('SelectedCompiler', 0); 236 247 finally 237 248 Free; 238 249 end; 239 250 LastOpenedList.LoadFromRegistry(Root, Key); 251 Compilers.LoadFromRegistry(Root, Key); 240 252 end; 241 253 242 254 procedure TMainForm.SaveToRegistry(Root: HKEY; Key: string); 243 255 begin 256 Compilers.SaveToRegistry(Root, Key); 244 257 LastOpenedList.SaveToRegistry(Root, Key); 245 258 with TRegistryEx.Create do … … 253 266 WriteString('LanguageCode', CoolTranslator1.Language.Code) 254 267 else DeleteValue('LanguageCode'); 268 WriteInteger('SelectedCompiler', CompilerIndex); 255 269 finally 256 270 Free; … … 274 288 ACompile.Enabled := ProjectFileName <> ''; 275 289 UpdateStatusBar; 290 UpdateTargetList; 276 291 end; 277 292 … … 281 296 end; 282 297 283 procedure TMainForm.UpdateT ergetList;298 procedure TMainForm.UpdateTargetList; 284 299 var 285 300 I: Integer; … … 302 317 BrainFuckInterpreter.OnChangeState := BrainFuckInterpreterChangeState; 303 318 BrainFuckCompiler := TBrainFuckCompiler.Create; 304 Compilers := T ListObject.Create;319 Compilers := TCompilerList.Create; 305 320 Compilers.Add(TBrainFuckCompilerDelphi.Create); 306 321 Compilers.Add(TBrainFuckCompilerPHP.Create); 307 UpdateT ergetList;322 UpdateTargetList; 308 323 LastOpenedList := TLastOpenedList.Create; 309 324 LastOpenedList.MenuItem := MenuItemOpenRecent; … … 352 367 begin 353 368 CompiledForm.Show; 369 end; 370 371 procedure TMainForm.AViewCompilersExecute(Sender: TObject); 372 begin 373 FormCompilers.Show; 354 374 end; 355 375 … … 437 457 end; 438 458 459 procedure TMainForm.ACompileAndRunExecute(Sender: TObject); 460 var 461 Process: TProcess; 462 CompiledFile: string; 463 begin 464 with TBrainFuckCompiler(Compilers[CompilerIndex]) do begin 465 Optimization := coNormal; 466 Source := MemoSource.Text; 467 ProgramName := ExtractFileNameOnly(ProjectFileName); 468 Compile; 469 CompiledFile := ExtractFilePath(ProjectFileName) + 470 'compiled' + DirectorySeparator + Name + DirectorySeparator + 471 ExtractFileNameOnly(ProjectFileName) + SourceExtension; 472 ForceDirectoriesUTF8(ExtractFilePath(CompiledFile)); 473 with TStringList.Create do 474 try 475 Text := Output; 476 SaveToFile(CompiledFile); 477 finally 478 Free; 479 end; 480 if FileExistsUTF8(CompilerPath) then 481 try 482 Process := TProcess.Create(nil); 483 Process.CommandLine := '"' + CompilerPath + '" "' + CompiledFile + '"'; 484 Process.Options := [poWaitOnExit]; 485 Process.Execute; 486 finally 487 Process.Free; 488 end else raise Exception.Create(Format(SCompilerNotFound, [CompilerPath])); 489 490 if CompiledExtension <> '' then begin 491 CompiledFile := ExtractFilePath(CompiledFile) + ExtractFileNameOnly(CompiledFile) + CompiledExtension; 492 if FileExistsUTF8(CompiledFile) then 493 try 494 Process := TProcess.Create(nil); 495 Process.CommandLine := '"' + CompiledFile + '"'; 496 Process.Options := [poWaitOnExit]; 497 Process.Execute; 498 finally 499 Process.Free; 500 end else raise Exception.Create(Format(SCompiledFileNotFound, [CompiledFile])); 501 end; 502 end; 503 end; 504 439 505 procedure TMainForm.AProgramPauseExecute(Sender: TObject); 440 506 begin
Note:
See TracChangeset
for help on using the changeset viewer.