Ignore:
Timestamp:
Feb 18, 2012, 8:44:10 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Target specific options is maintained by target class in registry.
  • Modified: Integer index TargetIndex replaced by object reference CurrentTarget.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UMainForm.pas

    r31 r32  
    1818
    1919  TMainForm = class(TForm)
    20     ACompile: TAction;
     20    AProgramCompile: TAction;
    2121    AAbout: TAction;
    2222    ABreakpointToggle: TAction;
     
    2929    AProgramStepOut: TAction;
    3030    AProgramRunToCursor: TAction;
    31     AProgramStopOver: TAction;
     31    AProgramStepOver: TAction;
    3232    AProgramStepInto: TAction;
    3333    AViewCompiled: TAction;
     
    108108    procedure ABreakpointToggleExecute(Sender: TObject);
    109109    procedure ACompileAndRunExecute(Sender: TObject);
    110     procedure ACompileExecute(Sender: TObject);
     110    procedure AProgramCompileExecute(Sender: TObject);
    111111    procedure AExitExecute(Sender: TObject);
    112112    procedure AFormatSourceExecute(Sender: TObject);
     
    138138      Shift: TShiftState; X, Y: Integer);
    139139  private
     140    FCurrentTarget: TTarget;
    140141    procedure AProjectOpenRecentExecute(Sender: TObject);
    141142    procedure BrainFuckInterpreterChangeState(Sender: TObject);
    142143    procedure MenuItemTargetClick(Sender: TObject);
    143144    procedure ProjectOpen(FileName: string);
     145    procedure SetCurrentTarget(AValue: TTarget);
    144146  public
    145147    Modified: Boolean;
    146     CompilerIndex: Integer;
    147148    ProjectFileName: string;
    148     BrainFuckCompiler: TTarget;
    149     BrainFuckInterpreter: TTargetInterpretter;
    150149    BreakPoints: TListInteger;
    151150    Targets: TTargetList;
     
    157156    procedure UpdateStatusBar;
    158157    procedure UpdateTargetList;
     158    property CurrentTarget: TTarget read FCurrentTarget write SetCurrentTarget;
    159159  end;
    160160
     
    222222begin
    223223  with TMenuItem(Sender) do begin
    224     CompilerIndex := MenuIndex;
     224    CurrentTarget := TTarget(Targets[MenuIndex]);
    225225    Checked := True;
    226226    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;
    228228  end;
    229229end;
     
    238238end;
    239239
     240procedure TMainForm.SetCurrentTarget(AValue: TTarget);
     241var
     242  I: Integer;
     243begin
     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;
     249end;
     250
    240251procedure TMainForm.LoadFromRegistry(Root: HKEY; Key: string);
     252var
     253  TargetName: string;
    241254begin
    242255  with TRegistryEx.Create do
     
    245258    OpenKey(Key, True);
    246259    OpenProjectOnStart := ReadBoolWithDefault('OpenProjectOnStart', True);
    247     BrainFuckInterpreter.CellSize := ReadIntegerWithDefault('CellSize', 256);
    248     BrainFuckInterpreter.MemorySize := ReadIntegerWithDefault('MemorySize', 30000);
    249260    if ValueExists('LanguageCode') then
    250261      CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
    251262      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]);
    253266  finally
    254267    Free;
     
    267280    OpenKey(Key, True);
    268281    WriteBool('OpenProjectOnStart', OpenProjectOnStart);
    269     WriteInteger('CellSize', BrainFuckInterpreter.CellSize);
    270     WriteInteger('MemorySize', BrainFuckInterpreter.MemorySize);
    271282    if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then
    272283      WriteString('LanguageCode', CoolTranslator1.Language.Code)
    273284      else DeleteValue('LanguageCode');
    274     WriteInteger('SelectedCompiler', CompilerIndex);
     285    WriteString('TargetName', CurrentTarget.Name);
    275286  finally
    276287    Free;
     
    289300  MemoSource.Enabled := ProjectFileName <> '';
    290301  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 <> '');
    295313  UpdateStatusBar;
    296314  UpdateTargetList;
     
    312330    NewMenuItem.Caption := TTarget(Targets[I]).Name;
    313331    NewMenuItem.OnClick := MenuItemTargetClick;
    314     if I = CompilerIndex then NewMenuItem.Checked := True;
     332    if TTarget(Targets[I]) = CurrentTarget then NewMenuItem.Checked := True;
    315333    MenuItemTarget.Add(NewMenuItem);
    316334  end;
     
    320338begin
    321339  BreakPoints := TListInteger.Create;
    322   BrainFuckInterpreter := TTargetInterpretter.Create;
    323   BrainFuckInterpreter.OnChangeState := BrainFuckInterpreterChangeState;
    324   BrainFuckCompiler := TTarget.Create;
    325340  Targets := TTargetList.Create;
    326341  Targets.Add(TTargetInterpretter.Create);
     
    340355  LastOpenedList.Free;
    341356  Targets.Free;
    342   BrainFuckCompiler.Free;
    343   BrainFuckInterpreter.Free;
    344357  BreakPoints.Free;
    345358end;
     
    349362  InterpreterForm.LastStepCounter := 0;
    350363  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;
    354368end;
    355369
     
    442456procedure TMainForm.AOptionsExecute(Sender: TObject);
    443457begin
    444   OptionsForm.LoadFromInterpretter(BrainFuckInterpreter);
     458  //OptionsForm.LoadFromInterpretter(CurrentTarget);
    445459  if OptionsForm.ShowModal = mrOK then begin
    446     OptionsForm.SaveToInterpretter(BrainFuckInterpreter);
    447   end;
    448 end;
    449 
    450 procedure TMainForm.ACompileExecute(Sender: TObject);
    451 begin
    452   with TTarget(Targets[CompilerIndex]) do begin
     460    //OptionsForm.SaveToInterpretter(CurrentTarget);
     461  end;
     462end;
     463
     464procedure TMainForm.AProgramCompileExecute(Sender: TObject);
     465begin
     466  with CurrentTarget do begin
    453467    Optimization := coNormal;
    454468    Source := MemoSource.Text;
     
    467481procedure TMainForm.ACompileAndRunExecute(Sender: TObject);
    468482begin
    469   with TTarget(Targets[CompilerIndex]) do begin
     483  with CurrentTarget do begin
    470484    Optimization := coNormal;
    471485    Source := MemoSource.Text;
     
    480494procedure TMainForm.AProgramPauseExecute(Sender: TObject);
    481495begin
    482   MainForm.BrainFuckInterpreter.Pause
     496  CurrentTarget.Pause
    483497end;
    484498
    485499procedure TMainForm.AProgramStopExecute(Sender: TObject);
    486500begin
    487   MainForm.BrainFuckInterpreter.Stop;
     501  CurrentTarget.Stop;
    488502end;
    489503
Note: See TracChangeset for help on using the changeset viewer.