Changeset 19 for trunk/UMainForm.pas


Ignore:
Timestamp:
Feb 11, 2012, 10:18:19 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Compiler moved to separate unit file.
  • Added: Compiler to PHP.
  • Added: Loading list of available compilers and list them for selection in menu Program - Target.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMainForm.pas

    r18 r19  
    88  Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs,
    99  Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck, UCoolTranslator, StrUtils,
    10   SpecializedList;
     10  SpecializedList, UCompiler;
    1111
    1212type
     
    5959    MenuItem25: TMenuItem;
    6060    MenuItem26: TMenuItem;
    61     MenuItem40: TMenuItem;
     61    MenuItemTarget: TMenuItem;
    6262    MenuItem21: TMenuItem;
    6363    MenuItem3: TMenuItem;
     
    112112  private
    113113    procedure BrainFuckInterpreterChangeState(Sender: TObject);
     114    procedure MenuItemTargetClick(Sender: TObject);
    114115  public
    115116    Modified: Boolean;
     
    118119    BrainFuckInterpreter: TBrainFuckInterpretter;
    119120    BreakPoints: TListInteger;
     121    Compilers: TListObject; // TListObject<TCompiler>
    120122    procedure UpdateInterface;
    121123    procedure UpdateStatusBar;
     124    procedure UpdateTergetList;
    122125  end;
    123126
     
    130133
    131134uses
    132   UInterpreterForm, UApplicationInfo, UCompiledForm, UOptionsForm;
     135  UInterpreterForm, UApplicationInfo, UCompiledForm, UOptionsForm,
     136  UCompilerDelphi, UCompilerPHP;
    133137
    134138{ TMainForm }
     
    169173begin
    170174  UpdateInterface;
     175end;
     176
     177procedure TMainForm.MenuItemTargetClick(Sender: TObject);
     178var
     179  I: Integer;
     180begin
     181  with TMenuItem(Sender) do begin
     182    Checked := True;
     183    for I := 0 to Parent.Count - 1 do
     184      if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False
     185  end;
    171186end;
    172187
     
    194209end;
    195210
     211procedure TMainForm.UpdateTergetList;
     212var
     213  I: Integer;
     214  NewMenuItem: TMenuItem;
     215begin
     216  MenuItemTarget.Clear;
     217  for I := 0 to Compilers.Count - 1 do begin
     218    NewMenuItem := TMenuItem.Create(MenuItemTarget);
     219    NewMenuItem.Caption := TBrainFuckCompiler(Compilers[I]).Name;
     220    NewMenuItem.OnClick := MenuItemTargetClick;
     221    if I = 0 then NewMenuItem.Checked := True;
     222    MenuItemTarget.Add(NewMenuItem);
     223  end;
     224end;
     225
    196226procedure TMainForm.FormCreate(Sender: TObject);
    197227begin
     
    201231  BrainFuckCompiler := TBrainFuckCompiler.Create;
    202232  CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('cs');
     233  Compilers := TListObject.Create;
     234  Compilers.Add(TBrainFuckCompilerDelphi.Create);
     235  Compilers.Add(TBrainFuckCompilerPHP.Create);
     236  UpdateTergetList;
    203237end;
    204238
    205239procedure TMainForm.FormDestroy(Sender: TObject);
    206240begin
     241  Compilers.Free;
    207242  BrainFuckCompiler.Free;
    208243  BrainFuckInterpreter.Free;
     
    275310
    276311procedure TMainForm.ACompileExecute(Sender: TObject);
    277 begin
    278   BrainFuckCompiler.Source := MemoSource.Text;
    279   BrainFuckCompiler.ProgramName := ExtractFileNameOnly(ProjectFileName);
    280   BrainFuckCompiler.Compile;
    281   CompiledForm.MemoCompiled.Text := BrainFuckCompiler.Output;
    282   CompiledForm.Show;
     312var
     313  I: Integer;
     314begin
     315  I := 0;
     316  while (I < MenuItemTarget.Count) and (not MenuItemTarget.Items[I].Checked) do Inc(I);
     317  with TBrainFuckCompiler(Compilers[I]) do begin
     318    Source := MemoSource.Text;
     319    ProgramName := ExtractFileNameOnly(ProjectFileName);
     320    Compile;
     321    CompiledForm.MemoCompiled.Text := Output;
     322    CompiledForm.Show;
     323  end;
    283324end;
    284325
Note: See TracChangeset for help on using the changeset viewer.