Changeset 32 for trunk/Forms/UMainForm.pas
- Timestamp:
- Feb 18, 2012, 8:44:10 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UMainForm.pas
r31 r32 18 18 19 19 TMainForm = class(TForm) 20 A Compile: TAction;20 AProgramCompile: TAction; 21 21 AAbout: TAction; 22 22 ABreakpointToggle: TAction; … … 29 29 AProgramStepOut: TAction; 30 30 AProgramRunToCursor: TAction; 31 AProgramSt opOver: TAction;31 AProgramStepOver: TAction; 32 32 AProgramStepInto: TAction; 33 33 AViewCompiled: TAction; … … 108 108 procedure ABreakpointToggleExecute(Sender: TObject); 109 109 procedure ACompileAndRunExecute(Sender: TObject); 110 procedure A CompileExecute(Sender: TObject);110 procedure AProgramCompileExecute(Sender: TObject); 111 111 procedure AExitExecute(Sender: TObject); 112 112 procedure AFormatSourceExecute(Sender: TObject); … … 138 138 Shift: TShiftState; X, Y: Integer); 139 139 private 140 FCurrentTarget: TTarget; 140 141 procedure AProjectOpenRecentExecute(Sender: TObject); 141 142 procedure BrainFuckInterpreterChangeState(Sender: TObject); 142 143 procedure MenuItemTargetClick(Sender: TObject); 143 144 procedure ProjectOpen(FileName: string); 145 procedure SetCurrentTarget(AValue: TTarget); 144 146 public 145 147 Modified: Boolean; 146 CompilerIndex: Integer;147 148 ProjectFileName: string; 148 BrainFuckCompiler: TTarget;149 BrainFuckInterpreter: TTargetInterpretter;150 149 BreakPoints: TListInteger; 151 150 Targets: TTargetList; … … 157 156 procedure UpdateStatusBar; 158 157 procedure UpdateTargetList; 158 property CurrentTarget: TTarget read FCurrentTarget write SetCurrentTarget; 159 159 end; 160 160 … … 222 222 begin 223 223 with TMenuItem(Sender) do begin 224 C ompilerIndex := MenuIndex;224 CurrentTarget := TTarget(Targets[MenuIndex]); 225 225 Checked := True; 226 226 for I := 0 to Parent.Count - 1 do 227 if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False 227 if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False; 228 228 end; 229 229 end; … … 238 238 end; 239 239 240 procedure TMainForm.SetCurrentTarget(AValue: TTarget); 241 var 242 I: Integer; 243 begin 244 if FCurrentTarget = AValue then Exit; 245 FCurrentTarget := AValue; 246 for I := 0 to Targets.Count - 1 do 247 TTarget(Targets[I]).OnChangeState := nil; 248 FCurrentTarget.OnChangeState := BrainFuckInterpreterChangeState; 249 end; 250 240 251 procedure TMainForm.LoadFromRegistry(Root: HKEY; Key: string); 252 var 253 TargetName: string; 241 254 begin 242 255 with TRegistryEx.Create do … … 245 258 OpenKey(Key, True); 246 259 OpenProjectOnStart := ReadBoolWithDefault('OpenProjectOnStart', True); 247 BrainFuckInterpreter.CellSize := ReadIntegerWithDefault('CellSize', 256);248 BrainFuckInterpreter.MemorySize := ReadIntegerWithDefault('MemorySize', 30000);249 260 if ValueExists('LanguageCode') then 250 261 CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', '')) 251 262 else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(''); 252 CompilerIndex := ReadIntegerWithDefault('SelectedCompiler', 0); 263 TargetName := ReadStringWithDefault('TargetName', 'Interpretter'); 264 CurrentTarget := Targets.FindByName(TargetName); 265 if not Assigned(CurrentTarget) then CurrentTarget := TTarget(Targets[0]); 253 266 finally 254 267 Free; … … 267 280 OpenKey(Key, True); 268 281 WriteBool('OpenProjectOnStart', OpenProjectOnStart); 269 WriteInteger('CellSize', BrainFuckInterpreter.CellSize);270 WriteInteger('MemorySize', BrainFuckInterpreter.MemorySize);271 282 if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then 272 283 WriteString('LanguageCode', CoolTranslator1.Language.Code) 273 284 else DeleteValue('LanguageCode'); 274 Write Integer('SelectedCompiler', CompilerIndex);285 WriteString('TargetName', CurrentTarget.Name); 275 286 finally 276 287 Free; … … 289 300 MemoSource.Enabled := ProjectFileName <> ''; 290 301 AProjectClose.Enabled := ProjectFileName <> ''; 291 AProgramRun.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State = rsStopped); 292 AProgramPause.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State = rsRunning); 293 AProgramStop.Enabled := (ProjectFileName <> '') and (BrainFuckInterpreter.State <> rsStopped); 294 ACompile.Enabled := ProjectFileName <> ''; 302 AProgramRun.Enabled := (tcRun in CurrentTarget.Capabilities) and 303 (ProjectFileName <> '') and (CurrentTarget.State = rsStopped); 304 AProgramPause.Enabled := (tcPause in CurrentTarget.Capabilities) and 305 (ProjectFileName <> '') and (CurrentTarget.State = rsRunning); 306 AProgramStop.Enabled := (tcStop in CurrentTarget.Capabilities) and 307 (ProjectFileName <> '') and (CurrentTarget.State <> rsStopped); 308 AProgramCompile.Enabled := (tcCompile in CurrentTarget.Capabilities) and (ProjectFileName <> ''); 309 AProgramStepInto.Enabled := (tcStepInto in CurrentTarget.Capabilities) and (ProjectFileName <> ''); 310 AProgramStepOut.Enabled := (tcStepOut in CurrentTarget.Capabilities) and (ProjectFileName <> ''); 311 AProgramRunToCursor.Enabled := (tcRunToCursor in CurrentTarget.Capabilities) and (ProjectFileName <> ''); 312 AProgramStepOver.Enabled := (tcStepOver in CurrentTarget.Capabilities) and (ProjectFileName <> ''); 295 313 UpdateStatusBar; 296 314 UpdateTargetList; … … 312 330 NewMenuItem.Caption := TTarget(Targets[I]).Name; 313 331 NewMenuItem.OnClick := MenuItemTargetClick; 314 if I = CompilerIndexthen NewMenuItem.Checked := True;332 if TTarget(Targets[I]) = CurrentTarget then NewMenuItem.Checked := True; 315 333 MenuItemTarget.Add(NewMenuItem); 316 334 end; … … 320 338 begin 321 339 BreakPoints := TListInteger.Create; 322 BrainFuckInterpreter := TTargetInterpretter.Create;323 BrainFuckInterpreter.OnChangeState := BrainFuckInterpreterChangeState;324 BrainFuckCompiler := TTarget.Create;325 340 Targets := TTargetList.Create; 326 341 Targets.Add(TTargetInterpretter.Create); … … 340 355 LastOpenedList.Free; 341 356 Targets.Free; 342 BrainFuckCompiler.Free;343 BrainFuckInterpreter.Free;344 357 BreakPoints.Free; 345 358 end; … … 349 362 InterpreterForm.LastStepCounter := 0; 350 363 InterpreterForm.Show; 351 BrainFuckInterpreter.Input := InterpreterForm.MemoInput.Lines.Text; 352 BrainFuckInterpreter.Source := MemoSource.Text; 353 BrainFuckInterpreter.Run; 364 if CurrentTarget is TTargetInterpretter then 365 TTargetInterpretter(CurrentTarget).Input := InterpreterForm.MemoInput.Lines.Text; 366 CurrentTarget.Source := MemoSource.Text; 367 CurrentTarget.Run; 354 368 end; 355 369 … … 442 456 procedure TMainForm.AOptionsExecute(Sender: TObject); 443 457 begin 444 OptionsForm.LoadFromInterpretter(BrainFuckInterpreter);458 //OptionsForm.LoadFromInterpretter(CurrentTarget); 445 459 if OptionsForm.ShowModal = mrOK then begin 446 OptionsForm.SaveToInterpretter(BrainFuckInterpreter);447 end; 448 end; 449 450 procedure TMainForm.A CompileExecute(Sender: TObject);451 begin 452 with TTarget(Targets[CompilerIndex])do begin460 //OptionsForm.SaveToInterpretter(CurrentTarget); 461 end; 462 end; 463 464 procedure TMainForm.AProgramCompileExecute(Sender: TObject); 465 begin 466 with CurrentTarget do begin 453 467 Optimization := coNormal; 454 468 Source := MemoSource.Text; … … 467 481 procedure TMainForm.ACompileAndRunExecute(Sender: TObject); 468 482 begin 469 with TTarget(Targets[CompilerIndex])do begin483 with CurrentTarget do begin 470 484 Optimization := coNormal; 471 485 Source := MemoSource.Text; … … 480 494 procedure TMainForm.AProgramPauseExecute(Sender: TObject); 481 495 begin 482 MainForm.BrainFuckInterpreter.Pause496 CurrentTarget.Pause 483 497 end; 484 498 485 499 procedure TMainForm.AProgramStopExecute(Sender: TObject); 486 500 begin 487 MainForm.BrainFuckInterpreter.Stop;501 CurrentTarget.Stop; 488 502 end; 489 503
Note:
See TracChangeset
for help on using the changeset viewer.