home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
555
/
M85
/
TVEXT.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1993-10-07
|
6KB
|
250 lines
UNIT TVExt;
{$X+}
INTERFACE
Uses Objects,Drivers,Dialogs,Views;
CONST
NomMois : Array[1..12] Of String[9] =
('Janvier','Février','Mars','Avril','Mai','Juin','Juillet',
'Août','Septembre','Octobre','Novembre','Décembre');
NomJour : Array[1..7] Of String[12] =
('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi','Dimanche');
cmClockUpDate = 1000;
cmClockSearch = 1001;
Type
PInputByte = ^TInputByte;
TInputByte = Object(TInputLine)
constructor Init(var Bounds : TRect);
function DataSize : Word; Virtual;
Procedure GetData(var Rec); Virtual;
Procedure SetData(var Rec); Virtual;
End;
PInputWord = ^TInputWord;
TInputWord = Object(TInputLine)
constructor Init(var Bounds : TRect);
function DataSize : Word; Virtual;
Procedure GetData(var Rec); Virtual;
Procedure SetData(var Rec); Virtual;
End;
PClock = ^TClock;
TClock = Object(TWindow)
Heure,Min,Sec,Sec100 : Word;
Annee,Mois,Quant,Jour : Word;
Constructor Init(Bounds : TRect);
Procedure HandleEvent(Var Event : TEvent); Virtual;
End;
PStatus = ^TStatus;
TStatus = Object(TView)
Status : PString;
Constructor Init(Bounds : TRect ; eStatus : PString);
Procedure Draw; Virtual;
End;
Function Confirmation(S : String ; h : Byte) : Word;
Procedure Information(S : String ; h : Byte);
IMPLEMENTATION
Uses App,Dos;
{****** TStatus ******}
Constructor TStatus.Init(Bounds : TRect ; eStatus : PString);
Begin
TView.Init(Bounds);
Status:=eStatus;
End;
Procedure TStatus.Draw;
Var B : TDrawBuffer;
C : Byte;
Begin
C:=GetColor(1);
MoveChar(B,' ',C,Size.X);
MoveStr(B,Status^,C);
WriteLine(0,0,Size.X,1,B);
End;
{****** TClock *******}
Type
PClockInt = ^TClockInt;
TClockInt = Object(TView)
Pere : PClock;
Constructor Init(Bounds : TRect ; ePere : PClock);
Procedure Draw; Virtual;
End;
Constructor TClockInt.Init(Bounds : TRect ; ePere : PClock);
Begin
TView.Init(Bounds);
Pere:=ePere;
GrowMode:=gfGrowHiX+gfGrowHiY;
Options:=Options OR ofFramed;
End;
Procedure TClockInt.Draw;
Var S,T : String;
C,I : Byte;
B : TDrawBuffer;
Function Zero(n : Byte) : String;
Var S : String[2];
Begin
S[0]:=#2;
S[1]:=Chr((n div 10)+48);
S[2]:=Chr((n mod 10)+48);
Zero:=S;
End;
Begin
C:=GetColor(1);
For I:=0 to Size.Y-1 do
Begin
S:='';
If I=(Size.Y div 2)-1 Then
Begin
S:=NomJour[Pere^.Jour];
Str(Pere^.Quant,T);
If Pere^.Quant=1 Then T:='1er';
S:=S+' '+T+' '+NomMois[Pere^.Mois]+' ';
Str(Pere^.Annee,T);
S:=S+T;
End;
If I=(Size.Y Div 2)+1 Then
Begin
Str(Pere^.Heure:2,S);
S:=S+':'+Zero(Pere^.Min)+' '+Zero(Pere^.Sec);
End;
FillChar(T,SizeOf(T),32);
S:=Copy(S,1,Size.X);
T[0]:=Chr((Size.X-Length(S)) div 2);
S:=T+S;
MoveChar(B,' ',C,Size.X);
MoveStr(B,S,C);
WriteLine(0,I,Size.X,1,B);
End;
End;
Procedure TClock.HandleEvent(Var Event : TEvent);
Var H,M,S,S100 : Word;
A,Mo,Q,J : Word;
Modif : Boolean;
Begin
TWindow.HandleEvent(Event);
If Event.What=evBroadCast Then
Begin
Case Event.Command Of
cmClockUpDate :
Begin
Modif:=FALSE;
GetTime(H,M,S,S100);
GetDate(A,Mo,Q,J);
If S<>Sec Then Begin Sec:=S; Modif:=TRUE; End;
If M<>Min Then Begin Min:=M; Modif:=TRUE; End;
If H<>Heure Then Begin Heure:=H; Modif:=TRUE; End;
If J<>Jour Then Begin Jour:=J; Modif:=TRUE; End;
If Q<>Quant Then Begin Quant:=Q; Modif:=TRUE; End;
If Mo<>Mois Then Begin Mois:=Mo; Modif:=TRUE; End;
If A<>Annee Then Begin Annee:=A; Modif:=TRUE; End;
if Modif Then ReDraw;
End;
cmClockSearch : ;
Else
Exit;
End;
ClearEvent(Event);
End;
End;
Constructor TClock.Init(Bounds : TRect);
Begin
TWindow.Init(Bounds,'Horloge',0);
GetTime(Heure,Min,Sec,Sec100);
GetDate(Annee,Mois,Quant,Jour);
GetClipRect(Bounds);
Bounds.Grow(-1,-1);
Insert(New(PClockInt,Init(Bounds,@Self)));
End;
{******* TInputByte ******}
Constructor TInputByte.Init(var Bounds : TRect);
Begin
TInputLine.Init(Bounds,3);
End;
Function TInputByte.DataSize : Word;
Begin
DataSize:=1;
End;
Procedure TInputByte.GetData(var Rec);
Var e,r : Integer;
Begin
Val(Data^,e,r);
byte(Rec):=byte(e);
End;
Procedure TInputByte.SetData(var Rec);
Var a : Byte;
Begin
a:=Byte(Rec);
Str(a:3,Data^);
End;
Constructor TInputWord.Init(var Bounds : TRect);
Begin
TInputLine.Init(Bounds,5);
End;
Function TInputWord.DataSize : Word;
Begin
DataSize:=2;
End;
Procedure TInputWord.GetData(var Rec);
Var e,r : Integer;
Begin
Val(Data^,e,r);
Word(Rec):=Word(e);
End;
Procedure TInputWord.SetData(var Rec);
Var a : Word;
Begin
a:=Word(Rec);
Str(a:5,Data^);
End;
Function Confirmation(S : String ; h : Byte) : Word;
Var D : PDialog;
R : TRect;
Begin
R.Assign(5,2,5+50,2+h+5);
D:=New(PDialog,Init(R,'Confirmation'));
R.Assign(2,1,49,1+h);
D^.Insert(New(PStaticText,Init(R,S)));
R.Assign(37,2+h,48,4+h);
D^.Insert(New(PButton,Init(R,'Annuler',cmCancel,bfNormal)));
R.Assign(27,2+h,37,4+h);
D^.Insert(New(PButton,Init(R,'OK',cmOK,bfDefault)));
Confirmation:=DeskTop^.ExecView(D);
End;
Procedure Information(S : String ; h : Byte);
Var D : PDialog;
R : TRect;
Begin
R.Assign(5,2,5+50,2+h+5);
D:=New(PDialog,Init(R,'Information'));
R.Assign(2,1,49,1+h);
D^.Insert(New(PStaticText,Init(R,S)));
R.Assign(19,2+h,29,4+h);
D^.Insert(New(PButton,Init(R,'OK',cmOK,bfDefault)));
DeskTop^.ExecView(D);
End;
END.