home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Glyphtry / F_GLYPH.PAS < prev    next >
Pascal/Delphi Source File  |  1995-03-26  |  3KB  |  129 lines

  1. unit F_glyph;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, Menus, ExtCtrls, DBCtrls;
  8.  
  9. type
  10.   TGlyphViewer = class(TForm)
  11.     GlyphBtn: TSpeedButton;
  12.     NewBtn: TButton;
  13.     CloseBtn: TBitBtn;
  14.     GlyphPathEdit: TEdit;
  15.     Label1: TLabel;
  16.     GlyphName: TLabel;
  17.     PrevBtn: TButton;
  18.     AboutBtn: TButton;
  19.     GlyphBtn2: TSpeedButton;
  20.     ResetBtn: TButton;
  21.     procedure NewBtnClick(Sender: TObject);
  22.     procedure FormCreate(Sender: TObject);
  23.     procedure PrevBtnClick(Sender: TObject);
  24.     procedure AboutBtnClick(Sender: TObject);
  25.     procedure GlyphPathEditChange(Sender: TObject);
  26.     procedure ResetBtnClick(Sender: TObject);
  27.   private
  28.     { Private declarations }
  29.     Function LoadGlyphFile( FName : string ) : boolean;
  30.   public
  31.     { Public declarations }
  32.   end;
  33.  
  34. var
  35.   GlyphViewer: TGlyphViewer;
  36.  
  37. implementation
  38.  
  39. const
  40.    iCurrentFile : integer = -1;
  41. var
  42.    SearchRec : TSearchRec;
  43.    aszFileList : TStringList;
  44. {$R *.DFM}
  45.  
  46. Function TGlyphViewer.LoadGlyphFile( FName : string) : boolean;
  47. begin
  48.    GlyphName.Caption := FName;
  49.    try
  50.       GlyphBtn.Glyph.LoadFromFile( GlyphPathEdit.Text + FName );
  51.       GlyphBtn2.Glyph := GlyphBtn.Glyph;
  52.       GlyphBtn2.NumGlyphs := 2;
  53.       Result := TRUE;
  54.    except
  55.       MessageDlg( 'Error! - Unable to load ' + FName + ' into button',
  56.                   mtError, [mbOK], 0 );
  57.       Result := FALSE;
  58.    end;
  59. end;
  60.  
  61. procedure TGlyphViewer.NewBtnClick(Sender: TObject);
  62. var
  63.    iResult : integer;
  64. begin
  65.    iCurrentFile := -1;
  66.    if aszFileList.Count = 0 then begin
  67.       iResult := findfirst( GlyphPathEdit.Text + '*.bmp', faAnyFile, SearchRec );
  68.       if iResult <> 0 then begin
  69.          MessageDlg( 'No files found - check your path',
  70.                      mtError, [mbOK], 0 );
  71.          exit;
  72.       end;
  73.  
  74.    end else begin
  75.       iResult := FindNext( SearchRec );
  76.       if iResult <> 0 then begin
  77.          MessageDlg( 'No more files found in this path',
  78.                      mtInformation, [mbOK], 0 );
  79.          exit;
  80.       end;
  81.    end;
  82.  
  83.    if LoadGlyphFile( SearchRec.Name ) then begin
  84.       aszFileList.Add( SearchRec.Name );
  85.       PrevBtn.Enabled := aszFileList.Count > 1;
  86.    end;
  87. end;
  88.  
  89. procedure TGlyphViewer.FormCreate(Sender: TObject);
  90. begin
  91.    aszFileList := TStringList.Create;
  92.    if aszFileList = nil then
  93.       showMessage( 'create failed' );
  94. end;
  95.  
  96. procedure TGlyphViewer.PrevBtnClick(Sender: TObject);
  97. begin
  98.    if iCurrentFile = -1 then
  99.       iCurrentFile := aszFileList.Count - 2
  100.    else
  101.       dec( iCurrentFile );
  102.    if iCurrentFile >= 0 then
  103.       LoadGlyphFile( AszFileList.Strings[ iCurrentFile ] );
  104.    PrevBtn.Enabled := iCurrentFile >= 1;
  105. end;
  106.  
  107. procedure TGlyphViewer.AboutBtnClick(Sender: TObject);
  108. begin
  109.    MessageDlg( 'Glyph Viewer produced by '#13#10 +
  110.         'John Braga'#13#10'Crown Systems'#13#10 +
  111.         'Huntingdon, UK'#13#10'CIS 70134,201'#13#10#10'Enjoy!',
  112.         mtInformation, [mbOK], 0 );
  113. end;
  114.  
  115. procedure TGlyphViewer.GlyphPathEditChange(Sender: TObject);
  116. begin
  117.    aszFileList.Clear;
  118.    PrevBtn.Enabled := FALSE;
  119. end;
  120.  
  121. procedure TGlyphViewer.ResetBtnClick(Sender: TObject);
  122. begin
  123.    aszFileList.Clear;
  124.    iCurrentFile := -1;
  125.    PrevBtn.Enabled := FALSE;
  126. end;
  127.  
  128. end.
  129.