Ignore:
Timestamp:
Nov 2, 2024, 10:04:51 PM (3 weeks ago)
Author:
chronos
Message:
  • Modified: Apps split into separate units.
  • Modified: SystemApi moved into separate unit.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Independent/Os.pas

    r66 r67  
    2222  TRunningApp = class
    2323  private
    24     AppThread: TAppThread;
    2524    FApp: TApp;
    2625    procedure SetApp(AValue: TApp);
    2726  public
    2827    Context: TAppContext;
     28    AppThread: TAppThread;
    2929    procedure Run;
    3030    constructor Create;
     
    3737  TRunningApps = class(TObjectList<TRunningApp>)
    3838    function AddNew(App: TApp; System: TSystem): TRunningApp;
    39   end;
    40 
    41   { TSystemApi }
    42 
    43   TSystemApi = class(TApi)
    44   private
    45     FName: string;
    46     FText: string;
    47     procedure WriteLineSync;
    48     procedure RunAppSync;
    49   public
    50     App: TRunningApp;
    51     System: TSystem;
    52     procedure WriteLine(Text: string); override;
    53     procedure RunApp(Name: string); override;
    54     procedure Sleep(Time: TDateTime); override;
    55     function CreateWindow: THandle; override;
    56     procedure SetWindowName(Handle: THandle; Name: string); override;
    57     procedure SetWindowRect(Handle: THandle; Rect: TRect); override;
    58     procedure SetWindowVisible(Handle: THandle; Visible: Boolean); override;
    5939  end;
    6040
     
    8060  private
    8161    FOnDraw: TNotifyEvent;
    82     procedure Redraw;
    8362  public
    8463    Console: TConsole;
     
    8867    Windows: TWindows;
    8968    Handles: THandles;
     69    procedure Redraw;
    9070    procedure RunApp(Name: string);
    9171    procedure Start;
     
    9575  end;
    9676
     77
    9778implementation
    9879
    9980uses
    100   Apps;
     81  AppCode, AppTest, SystemApi;
    10182
    10283{ TAppThread }
     
    151132end;
    152133
    153 { TSystemApi }
    154 
    155 procedure TSystemApi.WriteLineSync;
    156 begin
    157   System.Console.Write(App.App.Name + ': ' + FText);
    158 end;
    159 
    160 procedure TSystemApi.RunAppSync;
    161 begin
    162   System.RunApp(FName);
    163 end;
    164 
    165 procedure TSystemApi.WriteLine(Text: string);
    166 begin
    167   FText := Text;
    168   App.AppThread.Synchronize(WriteLineSync);
    169 end;
    170 
    171 procedure TSystemApi.RunApp(Name: string);
    172 begin
    173   FName := Name;
    174   App.AppThread.Synchronize(RunAppSync);
    175 end;
    176 
    177 procedure TSystemApi.Sleep(Time: TDateTime);
    178 begin
    179   App.AppThread.Sleep(Round(Time / OneMillisecond));
    180 end;
    181 
    182 function TSystemApi.CreateWindow: THandle;
    183 var
    184   Window: TWindow;
    185 begin
    186   Window := System.Windows.AddNew;
    187   Window.Handle := System.Handles.AddNew;
    188   Result := Window.Handle;
    189 end;
    190 
    191 procedure TSystemApi.SetWindowName(Handle: THandle; Name: string);
    192 var
    193   Window: TWindow;
    194 begin
    195   Window := System.Windows.SearchByHandle(Handle);
    196   if Assigned(Window) then begin
    197     Window.Name := Name;
    198     System.Redraw;
    199   end;
    200 end;
    201 
    202 procedure TSystemApi.SetWindowRect(Handle: THandle; Rect: TRect);
    203 var
    204   Window: TWindow;
    205 begin
    206   Window := System.Windows.SearchByHandle(Handle);
    207   if Assigned(Window) then begin
    208     Window.Rect := Rect;
    209     System.Redraw;
    210   end;
    211 end;
    212 
    213 procedure TSystemApi.SetWindowVisible(Handle: THandle; Visible: Boolean);
    214 var
    215   Window: TWindow;
    216 begin
    217   Window := System.Windows.SearchByHandle(Handle);
    218   if Assigned(Window) then begin
    219     Window.Visible := Visible;
    220     System.Redraw;
    221   end;
    222 end;
    223 
    224134{ TWindows }
    225135
Note: See TracChangeset for help on using the changeset viewer.