home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Win31 / Calmira / SOURCE.ZIP / SRC / TIPS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-20  |  4.1 KB  |  136 lines

  1. {**************************************************************************}
  2. {                                                                          }
  3. {    Calmira shell for Microsoft« Windows(TM) 3.1                          }
  4. {    Source Release 2.1                                                    }
  5. {    Copyright (C) 1997-1998 Li-Hsin Huang                                 }
  6. {                                                                          }
  7. {    This program is free software; you can redistribute it and/or modify  }
  8. {    it under the terms of the GNU General Public License as published by  }
  9. {    the Free Software Foundation; either version 2 of the License, or     }
  10. {    (at your option) any later version.                                   }
  11. {                                                                          }
  12. {    This program is distributed in the hope that it will be useful,       }
  13. {    but WITHOUT ANY WARRANTY; without even the implied warranty of        }
  14. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         }
  15. {    GNU General Public License for more details.                          }
  16. {                                                                          }
  17. {    You should have received a copy of the GNU General Public License     }
  18. {    along with this program; if not, write to the Free Software           }
  19. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             }
  20. {                                                                          }
  21. {**************************************************************************}
  22.  
  23. unit Tips;
  24.  
  25. interface
  26.  
  27. uses
  28.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  29.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls;
  30.  
  31. type
  32.   TTipDialog = class(TForm)
  33.     CloseBtn: TBitBtn;
  34.     NextTip: TBitBtn;
  35.     cbShowDailyTips: TCheckBox;
  36.     Label1: TLabel;
  37.     Panel1: TPanel;
  38.     Label2: TLabel;
  39.     HomePage: TBitBtn;
  40.     BitBtn4: TBitBtn;
  41.     TipLabel: TLabel;
  42.     Bevel1: TBevel;
  43.     Image1: TImage;
  44.     procedure FormShow(Sender: TObject);
  45.     procedure NextTipClick(Sender: TObject);
  46.     procedure CloseBtnClick(Sender: TObject);
  47.     procedure BitBtn4Click(Sender: TObject);
  48.     procedure HomePageClick(Sender: TObject);
  49.     procedure cbShowDailyTipsClick(Sender: TObject);
  50.     procedure FormCreate(Sender: TObject);
  51.   private
  52.     { Private declarations }
  53.     function GetTip(const filename: string): string;
  54.   public
  55.     { Public declarations }
  56.   end;
  57.  
  58. var
  59.   TipDialog: TTipDialog;
  60.  
  61. implementation
  62.  
  63. {$R *.DFM}
  64.  
  65. uses FileMan, Settings, Strings, Files, MiscUtil;
  66.  
  67. function TTipDialog.GetTip(const filename: string): string;
  68. var
  69.   f: TextFile;
  70.   Count, i : Integer;
  71. begin
  72.   if not FileExists(filename) then begin
  73.     Result := TipLabel.Caption;
  74.     Exit;
  75.   end;
  76.  
  77.   ShowHourglass;
  78.   FileMode := 0;
  79.   AssignFile(f, filename);
  80.   Reset(f);
  81.   try
  82.     Readln(f, Count);
  83.     for i := 0 to Random(Count) do begin
  84.       repeat
  85.         Readln(f, Result);
  86.       until Eof(f) or (not Blank(Result) and (Result[1] <> ';'));
  87.       if Eof(f) then Break;
  88.     end;
  89.   finally
  90.     CloseFile(f);
  91.   end;
  92. end;
  93.  
  94.  
  95. procedure TTipDialog.FormShow(Sender: TObject);
  96. begin
  97.   NextTip.Click;
  98. end;
  99.  
  100. procedure TTipDialog.NextTipClick(Sender: TObject);
  101. begin
  102.   TipLabel.Caption := GetTip(ApplicationPath + 'tips.txt');
  103. end;
  104.  
  105. procedure TTipDialog.CloseBtnClick(Sender: TObject);
  106. begin
  107.   Close;
  108.   ini.WriteString('Calmira', 'DateLastRun', DateToStr(Date));
  109. end;
  110.  
  111. procedure TTipDialog.BitBtn4Click(Sender: TObject);
  112. begin
  113.    Application.HelpJump('Contents');
  114. end;
  115.  
  116. procedure TTipDialog.HomePageClick(Sender: TObject);
  117. begin
  118.   DefaultExec('http://www.tribbles.demon.co.uk/calmira/', '', '', SW_SHOW);
  119. end;
  120.  
  121. procedure TTipDialog.cbShowDailyTipsClick(Sender: TObject);
  122. begin
  123.   ShowDailyTips := cbShowDailyTips.Checked;
  124.   ini.WriteBool('Preferences', 'ShowDailyTips', ShowDailyTips);
  125. end;
  126.  
  127. procedure TTipDialog.FormCreate(Sender: TObject);
  128. begin
  129.   cbShowDailyTips.Checked := ShowDailyTips;
  130.   CloseBtn.Cancel := True;
  131. end;
  132.  
  133. initialization
  134.   Randomize;
  135. end.
  136.