Changeset 233 for branches/xpascal/Forms


Ignore:
Timestamp:
Jun 26, 2023, 6:08:23 PM (17 months ago)
Author:
chronos
Message:
  • Added: Support for procedures.
  • Added: Project pascal file can be opened from main menu. Last file name is remembered.
  • Modified: Improved XML output of source structure.
Location:
branches/xpascal/Forms
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/xpascal/Forms/FormMain.lfm

    r230 r233  
    1010  Menu = MainMenu1
    1111  OnActivate = FormActivate
     12  OnClose = FormClose
    1213  OnCreate = FormCreate
    1314  OnDestroy = FormDestroy
     
    4950  object MainMenu1: TMainMenu
    5051    Left = 744
    51     Top = 760
     52    Top = 759
    5253    object MenuItemFile: TMenuItem
    5354      Caption = 'File'
     55      object MenuItem10: TMenuItem
     56        Action = AFileOpen
     57      end
    5458      object MenuItem6: TMenuItem
    5559        Action = AExit
     
    129133      OnExecute = AConsoleExecute
    130134    end
     135    object AFileOpen: TAction
     136      Caption = 'Open...'
     137      OnExecute = AFileOpenExecute
     138    end
     139  end
     140  object OpenDialog1: TOpenDialog
     141    DefaultExt = '.pas'
     142    Filter = 'Pascal file (.pas)|*.pas|Any file|*.*'
     143    Left = 536
     144    Top = 759
     145  end
     146  object ApplicationInfo1: TApplicationInfo
     147    Identification = 1
     148    VersionMajor = 1
     149    VersionMinor = 0
     150    VersionBugFix = 0
     151    AuthorsName = 'Chronosoft'
     152    EmailContact = 'robie@centrum.cz'
     153    AppName = 'xPascal'
     154    Description = 'Pascal mutli language transpiler and interpreter'
     155    RegistryKey = '\Software\xpascal'
     156    RegistryRoot = rrKeyCurrentUser
     157    License = 'CC0'
     158    Left = 348
     159    Top = 274
    131160  end
    132161end
  • branches/xpascal/Forms/FormMain.lrj

    r230 r233  
    1313{"hash":209392028,"name":"tformmain.ageneratexml.caption","sourcebytes":[71,101,110,101,114,97,116,101,32,88,77,76],"value":"Generate XML"},
    1414{"hash":371876,"name":"tformmain.atest.caption","sourcebytes":[84,101,115,116],"value":"Test"},
    15 {"hash":174433893,"name":"tformmain.aconsole.caption","sourcebytes":[67,111,110,115,111,108,101],"value":"Console"}
     15{"hash":174433893,"name":"tformmain.aconsole.caption","sourcebytes":[67,111,110,115,111,108,101],"value":"Console"},
     16{"hash":107745630,"name":"tformmain.afileopen.caption","sourcebytes":[79,112,101,110,46,46,46],"value":"Open..."},
     17{"hash":239474242,"name":"tformmain.applicationinfo1.description","sourcebytes":[80,97,115,99,97,108,32,109,117,116,108,105,32,108,97,110,103,117,97,103,101,32,116,114,97,110,115,112,105,108,101,114,32,97,110,100,32,105,110,116,101,114,112,114,101,116,101,114],"value":"Pascal mutli language transpiler and interpreter"}
    1618]}
  • branches/xpascal/Forms/FormMain.pas

    r230 r233  
    44
    55uses
    6   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus,
    7   ActnList, ExtCtrls, SynHighlighterPas, SynEdit, Source, Optimizer,
    8   Generator, FormSource, FormMessages, FormOutput, FormConsole, FormEx;
     6  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, LazFileUtils,
     7  ActnList, ExtCtrls, SynHighlighterPas, SynEdit, Source, Optimizer, RegistryEx,
     8  Generator, FormSource, FormMessages, FormOutput, FormConsole, FormEx,
     9  ApplicationInfo;
    910
    1011type
     
    1516    ACompile: TAction;
    1617    AConsole: TAction;
     18    AFileOpen: TAction;
     19    ApplicationInfo1: TApplicationInfo;
    1720    ATest: TAction;
    1821    AGenerateXml: TAction;
     
    2528    MainMenu1: TMainMenu;
    2629    MenuItem1: TMenuItem;
     30    MenuItem10: TMenuItem;
    2731    MenuItem2: TMenuItem;
    2832    MenuItem3: TMenuItem;
     
    3640    MenuItemGenerate: TMenuItem;
    3741    MenuItemFile: TMenuItem;
     42    OpenDialog1: TOpenDialog;
    3843    PanelOutput: TPanel;
    3944    PanelSource: TPanel;
     
    4348    procedure AConsoleExecute(Sender: TObject);
    4449    procedure AExitExecute(Sender: TObject);
     50    procedure AFileOpenExecute(Sender: TObject);
    4551    procedure AGenerateCSharpExecute(Sender: TObject);
    4652    procedure AGeneratePascalExecute(Sender: TObject);
     
    5157    procedure ARunExecute(Sender: TObject);
    5258    procedure FormActivate(Sender: TObject);
     59    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    5360    procedure FormCreate(Sender: TObject);
    5461    procedure FormDestroy(Sender: TObject);
    5562    procedure FormShow(Sender: TObject);
    5663  private
     64    LastFileName: string;
    5765    Prog: TProgram;
    5866    Initialized: Boolean;
     
    6169    FormOutput: TFormOutput;
    6270    FormConsole: TFormConsole;
     71    procedure LoadFromRegistry;
     72    procedure SaveToRegistry;
     73    procedure ProjectOpen(FileName: string);
    6374    procedure Generate(GeneratorClass: TGeneratorClass);
    6475    procedure ExecutorOutput(Text: string);
     
    8798  if not Initialized then begin
    8899    Initialized := True;
    89     FormSource.SynEditSource.Lines.LoadFromFile('Examples' + DirectorySeparator +
    90       'Example.pas');
    91     ARun.Execute;
     100    ProjectOpen(LastFileName);
     101    //ARun.Execute;
    92102  end;
    93103end;
     
    104114procedure TFormMain.FormShow(Sender: TObject);
    105115begin
     116  LoadFromRegistry;
    106117  FormMessages := TFormMessages.Create(nil);
    107118  FormMessages.Show;
     
    119130end;
    120131
     132procedure TFormMain.LoadFromRegistry;
     133begin
     134  with TRegistryEx.Create do
     135  try
     136    CurrentContext := ApplicationInfo1.GetRegistryContext;
     137    LastFileName := ReadStringWithDefault('LastFileName', 'Examples' + DirectorySeparator + 'Example.pas');
     138  finally
     139    Free;
     140  end;
     141end;
     142
     143procedure TFormMain.SaveToRegistry;
     144begin
     145  with TRegistryEx.Create do
     146  try
     147    CurrentContext := ApplicationInfo1.GetRegistryContext;
     148    WriteString('LastFileName', LastFileName);
     149  finally
     150    Free;
     151  end;
     152end;
     153
     154procedure TFormMain.ProjectOpen(FileName: string);
     155begin
     156  LastFileName := FileName;
     157  FormSource.SynEditSource.Lines.LoadFromFile(FileName);
     158end;
     159
    121160procedure TFormMain.Generate(GeneratorClass: TGeneratorClass);
    122161var
     
    130169    FormOutput.SetText(Generator.Output);
    131170    TargetFileName := 'Generated' + DirectorySeparator +
    132       Generator.Name + DirectorySeparator + 'Example' + Generator.FileExt;
     171      Generator.Name + DirectorySeparator + ExtractFileNameOnly(LastFileName) + Generator.FileExt;
    133172    ForceDirectories(ExtractFileDir(TargetFileName));
    134173    FormOutput.SynEditOutput.Lines.SaveToFile(TargetFileName);
     
    141180begin
    142181  Close;
     182end;
     183
     184procedure TFormMain.AFileOpenExecute(Sender: TObject);
     185begin
     186  OpenDialog1.InitialDir := ExtractFileDir(LastFileName);
     187  OpenDialog1.FileName := ExtractFileName(LastFileName);
     188  if OpenDialog1.Execute then begin
     189    ProjectOpen(OpenDialog1.FileName);
     190  end;
    143191end;
    144192
     
    224272end;
    225273
     274procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     275begin
     276  FormConsole.Terminated := True;
     277  SaveToRegistry;
     278end;
     279
    226280procedure TFormMain.FormCreate(Sender: TObject);
    227281begin
     
    248302begin
    249303  ACompile.Execute;
    250   FormOutput.SynEditOutput.Highlighter := nil;
    251   FormOutput.SynEditOutput.Lines.Clear;
     304  FormConsole.Memo1.Lines.Clear;
    252305  if Assigned(Prog) then begin
    253306    Executor := TExecutor.Create;
Note: See TracChangeset for help on using the changeset viewer.