1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
   |  
program test;
 
{ Extrait de DISK8RED.PAS
  http://mdalbin.developpez.com/tutoriels/pascal/tvpa/
  
  Le programme original est écrit pour Turbo Pascal. En le compilant avec Free
  pascal ou avec Virtual Pascal, on rencontre différents problèmes relatifs aux
  dimensions de la fenêtre : ou bien la fenêtre est plus grande que le bureau
  (Free Pascal), ou bien la "status line" n'est pas visible (Virtual Pascal).
}
 
{$IFDEF VPASCAL}
{$PMTYPE VIO}
{$USE32+}
{$ENDIF}
 
uses
  Dos, App, Objects, Views, Drivers, Dialogs, MsgBox, Validate, Menus, StdDlg;
 
{$R ICONE.RES}
 
type
  PClockStaticText = ^TClockStaticText;
  TClockStaticText = object(TStaticText)
    private
      Second, HundredthSecond: Word;
    public
      constructor Init(var Bounds: TRect; AText: string);
      procedure SetText(AText: string);
      procedure Update;
  end;
 
  TDisk8Reader = object(TApplication)
    private
      CommandLabel: PLabel;
      ClockStaticText: PClockStaticText;
    public
      constructor Init;
      procedure HandleEvent(var Event: TEvent); virtual;
      procedure InitMenuBar; virtual;
      procedure InitStatusLine; virtual;
      procedure InitDesktop; virtual;
      procedure InitClock;
      function GetPalette: PPalette; virtual;
      procedure Idle; virtual;
      destructor Done; virtual;
  end;
 
const
  CAppPalette = #$78#$70#$78#$74#$20#$74#$78#$73#$7F#$7A +
                #$31#$31#$1E#$71#$00#$2F#$3F#$3A#$13#$13 +
                #$3E#$21#$00#$70#$7F#$13#$78#$74#$70#$7F +
                #$00#$70#$7F#$7A#$13#$13#$70#$70#$7F#$7E +
                #$20#$2B#$2F#$78#$2E#$70#$30#$3F#$3E#$1F +
                #$2F#$1A#$20#$72#$31#$31#$30#$2F#$3E#$31 +
                #$13#$00#$00;
 
var
  Disk8Reader: TDisk8Reader;
 
(****************************************************************************)
(***                    *****************************************************)
(***  TClockStaticText  *****************************************************)
(***                    *****************************************************)
(****************************************************************************)
 
constructor TClockStaticText.Init(var Bounds: TRect; AText: string);
begin
  if not inherited Init(Bounds, AText) then Fail;
  Second := 0;
  HundredthSecond := 0;
end;
 
procedure TClockStaticText.SetText(AText: string);
begin
  if Text <> nil then DisposeStr(Text);
  Text := NewStr(AText);
end;
 
procedure TClockStaticText.Update;
var H, M, S, Sec: Word;
    SH, SM, SS, SSec: string;
begin
  GetTime(H, M, S, Sec);
  If (S * 100 + Sec) - (Second * 100 + HundredthSecond) >= 100 then
  begin
    Second := S;
    HundredthSecond := Sec;
    Str(H, SH); if H < 10 then SH := '0' + SH;
    Str(M, SM); if M < 10 then SM := '0' + SM;
    Str(S, SS); if S < 10 then SS := '0' + SS;
    Str(Sec, SSec);
    SetText(SH + ':' + SM + ':' + SS);
    DrawView;
  end;
end;
 
(****************************************************************************)
(***                *********************************************************)
(***  TDisk8Reader  *********************************************************)
(***                *********************************************************)
(****************************************************************************)
 
constructor TDisk8Reader.Init;
var Bounds: TRect;
    I: Integer;
begin
  if not inherited Init then Fail;
  SetScreenMode(smCO80 + smFont8x8);
  Redraw;
  InitClock;
end;
 
procedure TDisk8Reader.HandleEvent(var Event: TEvent);
begin
  inherited HandleEvent(Event);
end;
 
procedure TDisk8Reader.InitMenuBar;
begin
  MenuBar := nil;
end;
 
procedure TDisk8Reader.InitStatusLine;
var Bounds: TRect;
begin
  Bounds.Assign(0, 49, 80, 50);
  StatusLine := New(PStatusLine, Init(Bounds, NewStatusDef(0, 0,
  NewStatusKey('~Alt+X~ Exit', kbAltX, cmQuit, nil), nil)));
end;
 
procedure TDisk8Reader.InitDesktop;
var Bounds: TRect;
begin
  Bounds.Assign(0, 0, 80, 49);
  Desktop := New(PDesktop, Init(Bounds));
end;
 
procedure TDisk8Reader.InitClock;
var Bounds: TRect;
begin
  Bounds.Assign(0, 0, 80, 1);
  ClockStaticText := New(PClockStaticText, Init(Bounds, ''));
  Desktop^.Insert(ClockStaticText);
end;
 
function TDisk8Reader.GetPalette: PPalette;
const P: string[Length(CAppPalette)] = CAppPalette;
begin
  GetPalette := @P;
end;
 
procedure TDisk8Reader.Idle;
begin
  inherited Idle;
  ClockStaticText^.Update;
end;
 
destructor TDisk8Reader.Done;
begin
  Dispose(ClockStaticText, Done);
  inherited Done;
end;
 
(****************************************************************************)
(***        *****************************************************************)
(***  Main  *****************************************************************)
(***        *****************************************************************)
(****************************************************************************)
 
begin
  Disk8Reader.Init;
  Disk8Reader.Run;
  Disk8Reader.Done;
end. | 
Partager