Changeset 65 for branches


Ignore:
Timestamp:
Oct 9, 2024, 9:14:47 PM (6 weeks ago)
Author:
chronos
Message:
  • Added: File system file read.
  • Added: AppCode can process commands with single parameter.
Location:
branches/Independent
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/Independent

    • Property svn:ignore set to
      lib
      Independent
      Independent.lps
      Independent.res
  • branches/Independent/Api.pas

    r64 r65  
    1010
    1111  TApi = class
    12     procedure PrintHelloWorld; virtual; abstract;
     12    procedure WriteLine(Text: string); virtual; abstract;
    1313    procedure RunApp(Name: string); virtual; abstract;
    1414    procedure Sleep(Time: TDateTime); virtual; abstract;
  • branches/Independent/Apps.pas

    r64 r65  
    3232begin
    3333  with Context.Api do begin
    34     PrintHelloWorld;
     34    WriteLine('Hello World!');
    3535    Sleep(OneSecond);
    3636    RunApp('Code');
     
    4949  Name := 'Code';
    5050  Code := TStringList.Create;
    51   Code.Add('PrintHelloWorld');
    5251end;
    5352
     
    6261  I: Integer;
    6362  Line: string;
     63  Command: string;
     64  Index: Integer;
    6465begin
    6566  I := 0;
    6667  while (I >= 0) and (I < Code.Count) do begin
    67     Line := Code[I];
     68    Line := Code[I].Trim;
    6869    Inc(I);
    69     if Line = 'PrintHelloWorld' then Context.Api.PrintHelloWorld;
     70    if Line = '' then Continue;
     71
     72    Index := Pos(' ', Line);
     73    if Index > 0 then begin
     74      Command := Copy(Line, 1, Index - 1);
     75      Delete(Line, 1, Index);
     76    end else begin
     77      Command := Line;
     78      Line := '';
     79    end;
     80    if Command = 'WriteLine' then Context.Api.WriteLine(Line)
     81    else if Command = 'Sleep' then Context.Api.Sleep(StrToInt(Line))
     82    else if Command = 'RunApp' then Context.Api.RunApp(Line)
     83    else raise Exception.Create('Unsupported command ' + Command);
    7084  end;
    7185end;
  • branches/Independent/FormMain.lfm

    r64 r65  
    88  ClientWidth = 971
    99  DesignTimePPI = 144
     10  OnCreate = FormCreate
    1011  OnShow = FormShow
    1112  LCLVersion = '3.6.0.0'
  • branches/Independent/FormMain.pas

    r64 r65  
    1212  TFormName = class(TForm)
    1313    Memo1: TMemo;
     14    procedure FormCreate(Sender: TObject);
    1415    procedure FormShow(Sender: TObject);
    1516  private
     17    FileSystemDir: string;
    1618    System: TSystem;
    1719    procedure ConsoleWrite(Text: string);
     20    function LoadFile(Name: string): string;
    1821  public
    1922
     
    3336  System := TSystem.Create;
    3437  System.Console.OnWrite := ConsoleWrite;
     38  System.FileSystem.OnLoadFile := LoadFile;
    3539  System.Start;
     40end;
     41
     42procedure TFormName.FormCreate(Sender: TObject);
     43begin
     44  FileSystemDir := 'FileSystem';
    3645end;
    3746
     
    4150end;
    4251
     52function TFormName.LoadFile(Name: string): string;
     53var
     54  F: TFileStream;
     55begin
     56  F := TFileStream.Create(FileSystemDir + DirectorySeparator + Name, fmOpenRead);
     57  try
     58    if F.Size > 0 then begin
     59      Result := default(string);
     60      SetLength(Result, F.Size);
     61      F.Read(Result[1], F.Size);
     62    end else Result := '';
     63  finally
     64    F.Free;
     65  end;
     66end;
     67
    4368end.
    4469
  • branches/Independent/Independent.lpi

    r64 r65  
    9595        <IsPartOfProject Value="True"/>
    9696      </Unit>
     97      <Unit>
     98        <Filename Value="FileSystem.pas"/>
     99        <IsPartOfProject Value="True"/>
     100      </Unit>
    97101    </Units>
    98102  </ProjectOptions>
  • branches/Independent/Independent.lpr

    r64 r65  
    1111  {$ENDIF}
    1212  Interfaces, // this includes the LCL widgetset
    13   Forms, FormMain, Os, Apps, Api, Console
     13  Forms, FormMain, Os, Apps, Api, Console, FileSystem
    1414  { you can add units after this };
    1515
  • branches/Independent/Os.pas

    r64 r65  
    44
    55uses
    6   Classes, SysUtils, Generics.Collections, DateUtils, Api, Console;
     6  Classes, SysUtils, Generics.Collections, DateUtils, Api, Console, FileSystem;
    77
    88type
     
    4444  private
    4545    FName: string;
    46     procedure PrintHelloWorldSync;
     46    FText: string;
     47    procedure WriteLineSync;
    4748    procedure RunAppSync;
    4849  public
    4950    App: TRunningApp;
    5051    System: TSystem;
    51     procedure PrintHelloWorld; override;
     52    procedure WriteLine(Text: string); override;
    5253    procedure RunApp(Name: string); override;
    5354    procedure Sleep(Time: TDateTime); override;
     
    5859  TSystem = class
    5960    Console: TConsole;
     61    FileSystem: TFileSystem;
    6062    Apps: TApps;
    6163    RunningApps: TRunningApps;
     
    124126{ TSystemApi }
    125127
    126 procedure TSystemApi.PrintHelloWorldSync;
    127 begin
    128   System.Console.Write(App.App.Name + ': Hello world!');
     128procedure TSystemApi.WriteLineSync;
     129begin
     130  System.Console.Write(App.App.Name + ': ' + FText);
    129131end;
    130132
     
    134136end;
    135137
    136 procedure TSystemApi.PrintHelloWorld;
    137 begin
    138   App.AppThread.Synchronize(PrintHelloWorldSync);
     138procedure TSystemApi.WriteLine(Text: string);
     139begin
     140  FText := Text;
     141  App.AppThread.Synchronize(WriteLineSync);
    139142end;
    140143
     
    165168
    166169procedure TSystem.Start;
    167 begin
     170var
     171  AppCode: TAppCode;
     172begin
     173  Apps.AddNew(TAppTest);
     174  AppCode := TAppCode(Apps.AddNew(TAppCode));
     175  AppCode.Code.Text := FileSystem.LoadFile('Code.exe');
     176
    168177  RunApp('Test');
    169178  RunApp('Test');
     
    174183begin
    175184  Console := TConsole.Create;
     185  FileSystem := TFileSystem.Create;
    176186  RunningApps := TRunningApps.Create;
    177187  Apps := TApps.Create;
    178   Apps.AddNew(TAppTest);
    179   Apps.AddNew(TAppCode);
    180188end;
    181189
     
    185193  FreeAndNil(RunningApps);
    186194  FreeAndNil(Console);
     195  FreeAndNil(FileSystem);
    187196  inherited;
    188197end;
Note: See TracChangeset for help on using the changeset viewer.