home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1998 March / pcx19_9803.iso / PC-XUSER / PC-XUSER.12 / OOP / COUNT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-12-08  |  4.1 KB  |  185 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision 2.0 Demo                        }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7. {                                                }
  8. { With hungarian extension. Copyright '97  R4s ! }
  9. {                                                }
  10. {************************************************}
  11.  
  12. {$X+,V-}
  13.  
  14. unit Count;
  15.  
  16. INTERFACE
  17.  
  18. uses Objects, Drivers, Views;
  19.  
  20.  
  21. type
  22.   PCountView = ^TCountView;
  23.   TCountView = Object(TView)
  24.     Current: Longint;
  25.     Count  : Longint;
  26.     constructor Init(var Bounds: TRect);
  27.     constructor Load(var S: TStream);
  28.     procedure Draw; virtual;
  29.     function  GetPalette: PPalette; virtual;
  30.     procedure SetCount(NewCount: Longint);
  31.     procedure IncCount;
  32.     procedure DecCount;
  33.     procedure SetCurrent(NewCurrent: Longint);
  34.     procedure IncCurrent;
  35.     procedure DecCurrent;
  36.     procedure Store(var S: TStream); virtual;
  37.   end;
  38.  
  39. procedure RegisterCount;
  40.  
  41. const
  42.   CCountView = #1#2#3#8#9;
  43.  
  44.   RCountView: TStreamRec = (
  45.     ObjType: 992;
  46.     VmtLink: Ofs(TypeOf(TCountView)^);
  47.     Load   : @TCountView.Load;
  48.     Store  : @TCountView.Store
  49.   );
  50.  
  51. IMPLEMENTATION
  52.  
  53. { TCountView  }
  54. constructor TCountView.Init(var Bounds:TRect);
  55. begin
  56.   Inherited Init(Bounds);
  57.   SetCount(0);
  58.   SetCurrent(1);
  59. end;
  60.  
  61. constructor TCountView.Load(var S: TStream);
  62. begin
  63.   Inherited Load(S);
  64.   S.Read(Current, SizeOf(Current));
  65.   S.Read(Count, SizeOf(Count));
  66. end;
  67.  
  68. procedure TCountView.Draw;
  69.  
  70.   function GetRag(ForRag: Longint): String;
  71.   begin
  72.     case ForRag mod 10 of
  73.       0, 3, 6, 8: GetRag:='ból';
  74.       1, 2, 4, 5, 7, 9, 10: GetRag:='bôl';
  75.       else GetRag:='bôl';
  76.     end;
  77.   end;
  78.  
  79.   function  ConvertLongintToString(d: Longint): String;
  80.   var S: String;
  81.   begin
  82.     Str(d,s);
  83.     ConvertLongintToString:=S;
  84.   end;
  85.  
  86.   function GetNevelo(ANevelo: Longint): String;
  87.   var
  88.     S: String;
  89.     B, i: Byte;
  90.     L: Longint;
  91.   begin
  92.     S:=ConvertLongintToString(ANevelo);
  93.     B:=Byte(Length(S));
  94.     L:=10;
  95.     for i:=1 to B-1 do L:=L*10;
  96.     B:=ANevelo mod L;
  97.     case B of
  98.       0, 2, 3, 4, 6, 7, 8, 9: GetNevelo:='A';
  99.       1, 5, 10: GetNevelo:='Az';
  100.       else GetNevelo:='A';
  101.     end;
  102.   end;
  103.  
  104.   function GetHanyadik(ADik: Longint): String;
  105.   begin
  106.     if ADik = 1 then GetHanyadik:='elsô'
  107.                 else GetHanyadik:=ConvertLongintToString(ADik)+'.';
  108.   end;
  109.  
  110. var
  111.   B: TDrawBuffer;
  112.   C: Word;
  113.   {Params : Array[0..1] of Longint;} {Remarked By R4s}
  114.   Start  : Word;
  115.   First  : String[10];
  116.   Display: String[20];
  117. begin
  118.   C := GetColor(2);  { Uses same color as frame }
  119.   MoveChar(B, '═', C, Size.X);
  120.  
  121.   {Params[0] := Current;
  122.   Params[1] := Count;
  123.   FormatStr(Display, ' ~%d~ of %d ', Params);} {Remarked By R4s}
  124.   FormatStr(Display, ' '+GetNevelo(Current)+' '+GetHanyadik(Current)+' a %d-'+GetRag(Count), Count);
  125.  
  126.   { If Current is greater than Count, display Current as highlighted }
  127.   if Current > Count then C := GetColor($0504)
  128.   else C := GetColor($0202);
  129.  
  130.   MoveCStr(B, Display, C);
  131.   WriteLine(0, 0, Size.X, Length(Display), B);
  132. end;
  133.  
  134. function TCountView.GetPalette: PPalette;
  135. const
  136.   P: string[Length(CCountView)] = CCountView;
  137. begin
  138.   GetPalette := @P;
  139. end;
  140.  
  141. procedure TCountView.SetCount(NewCount:Longint);
  142. begin
  143.   Count := NewCount;
  144.   DrawView;
  145. end;
  146.  
  147. procedure TCountView.IncCount;
  148. begin
  149.   SetCount(Count + 1);
  150. end;
  151.  
  152. procedure TCountView.DecCount;
  153. begin
  154.   SetCount(Count - 1);
  155. end;
  156.  
  157. procedure TCountView.SetCurrent(NewCurrent:Longint);
  158. begin
  159.   Current := NewCurrent;
  160.   DrawView;
  161. end;
  162.  
  163. procedure TCountView.IncCurrent;
  164. begin
  165.   SetCurrent(Current + 1);
  166. end;
  167.  
  168. procedure TCountView.DecCurrent;
  169. begin
  170.   SetCurrent(Current - 1);
  171. end;
  172.  
  173. procedure TCountView.Store(var S: TStream);
  174. begin
  175.   Inherited Store(S);
  176.   S.Write(Current, SizeOf(Current));
  177.   S.Write(Count, SizeOf(Count));
  178. end;
  179.  
  180. procedure RegisterCount;
  181. begin
  182.   RegisterType(RCountView);
  183. end;
  184.  
  185. END.