Ignore:
Timestamp:
Aug 10, 2010, 11:54:18 AM (14 years ago)
Author:
george
Message:

Added support for multiple source files and compilations for multiple modules in Project.pas

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/Forms/UMainForm.pas

    r53 r54  
    99  Dialogs, StdCtrls, USourceCode, UCompiler, UProducerAsm8051,
    1010  UProducerC, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, UProducerTreeView,
    11   UProducerPascal, Contnrs;
     11  UProducerPascal, Contnrs, UProject;
    1212
    1313const
    14   ExampleFileName = '../../Example.pas';
     14  ProjectDir = '../../Project/';
    1515
    1616type
     
    2424    SynEdit1: TSynEdit;
    2525    SynPasSyn1: TSynPasSyn;
     26    TreeViewProject: TTreeView;
    2627    procedure ComboBox1Change(Sender: TObject);
    2728    procedure FormShow(Sender: TObject);
     
    3132    procedure FormDestroy(Sender: TObject);
    3233    procedure ListBox1Click(Sender: TObject);
     34    procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode);
     35  private
    3336    procedure LoadErrorMessages;
    34   private
     37    procedure UpdateProjectTree;
     38    procedure UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup);
    3539  public
     40    Project: TProject;
    3641    ProducerControl: TControl;
    3742    Compiler: TCompiler;
    38     SourceTree: TProducerTreeView;
    3943  end;
    4044
     
    5256  I: Integer;
    5357begin
    54   MainForm.ListBox1.Clear;
    55   Compiler.SourceCode.Assign(SynEdit1.Lines);
    56 
    5758  ProducerControl.Free;
    5859  if ComboBox1.ItemIndex = 0 then begin
    5960    Compiler.Producer.Free;
    6061    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
    6389    ProducerControl := TMemo.Create(Self);
    6490    ProducerControl.Parent := Panel1;
     
    6692    ProducerControl.Font.Name := 'Courier New';
    6793    TMemo(ProducerControl).ScrollBars := ssAutoBoth;
    68     with TProducerPascal(Compiler.Producer) do
    69       TMemo(ProducerControl).Lines.Assign(TextSource);
    7094  end else
    7195  if ComboBox1.ItemIndex = 1 then begin
    72     Compiler.Producer.Free;
    73     Compiler.Producer := TProducerC.Create;
    74     Compiler.Producer.ProgramCode := Compiler.ProgramCode;
    75     Compiler.Compile;
    7696    ProducerControl := TMemo.Create(Self);
    7797    ProducerControl.Parent := Panel1;
     
    7999    ProducerControl.Font.Name := 'Courier New';
    80100    TMemo(ProducerControl).ScrollBars := ssAutoBoth;
    81     with TProducerC(Compiler.Producer) do
    82       TMemo(ProducerControl).Lines.Assign(TextSource);
    83101  end else
    84102  if ComboBox1.ItemIndex = 2 then begin
    85     Compiler.Producer.Free;
    86     Compiler.Producer := TProducerAsm8051.Create;
    87     Compiler.Producer.ProgramCode := Compiler.ProgramCode;
    88     Compiler.Compile;
    89103    ProducerControl := TMemo.Create(Self);
    90104    ProducerControl.Parent := Panel1;
     
    92106    ProducerControl.Font.Name := 'Courier New';
    93107    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
    98109  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
    108112  LoadErrorMessages;
    109113end;
     
    128132end;
    129133
     134procedure TMainForm.TreeViewProjectChange(Sender: TObject; Node: TTreeNode);
     135begin
     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;
     143end;
     144
     145procedure TMainForm.UpdateProjectTree;
     146var
     147  NewNode: TTreeNode;
     148begin
     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;
     158end;
     159
     160procedure TMainForm.UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup);
     161var
     162  I: Integer;
     163  NewNode: TTreeNode;
     164begin
     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;
     172end;
     173
    130174procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
    131175begin
    132   SynEdit1.Lines.SaveToFile(ExampleFileName);
     176  Project.Save;
    133177end;
    134178
     
    136180begin
    137181  Compiler := TCompiler.Create;
    138   SourceTree := TProducerTreeView.Create;
     182  Project := TProject.Create;
    139183end;
    140184
    141185procedure TMainForm.FormDestroy(Sender: TObject);
    142186begin
     187  Project.Free;
    143188  Compiler.Free;
    144   SourceTree.Free;
    145189end;
    146190
    147191procedure TMainForm.FormShow(Sender: TObject);
    148 begin
     192var
     193  NewProjectFile: TProjectFile;
     194begin
     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
    149207  WindowState := wsMaximized;
    150   SynEdit1.Lines.LoadFromFile(ExampleFileName);
    151208  ButtonCompileClick(Self);
    152209end;
Note: See TracChangeset for help on using the changeset viewer.