home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Zipped / CALMIR21.ZIP / SOURCE.ZIP / VCL / ICONDLG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-20  |  2.4 KB  |  97 lines

  1. {*********************************************************}
  2. {                                                         }
  3. {    Calmira Visual Component Library 2.1                 }
  4. {    by Li-Hsin Huang,                                    }
  5. {    released into the public domain January 1998         }
  6. {                                                         }
  7. {*********************************************************}
  8.  
  9. unit Icondlg;
  10.  
  11. interface
  12.  
  13. uses
  14.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  15.   Forms, Dialogs;
  16.  
  17. type
  18.   TIconDialog = class(TComponent)
  19.   private
  20.     { Private declarations }
  21.     FFilename  : TFilename;
  22.     FIconIndex : Word;
  23.     FHistory : TStrings;
  24.     procedure SetHistory(value : TStrings);
  25.   protected
  26.     { Protected declarations }
  27.   public
  28.     { Public declarations }
  29.     constructor Create(AOwner : TComponent); override;
  30.     destructor Destroy; override;
  31.     function Execute : Boolean;
  32.   published
  33.     { Published declarations }
  34.     property Filename : TFilename read FFilename write FFilename;
  35.     property IconIndex : Word read FIconIndex write FIconIndex default 0;
  36.     property HistoryList : TStrings read FHistory write SetHistory;
  37.   end;
  38.  
  39. procedure Register;
  40.  
  41. implementation
  42.  
  43. uses IconSel, MiscUtil;
  44.  
  45. constructor TIconDialog.Create(AOwner : TComponent);
  46. begin
  47.   inherited Create(AOwner);
  48.   FFilename := Application.Exename;
  49.   FIconIndex := 0;
  50.   FHistory := TStringList.Create;
  51. end;
  52.  
  53. destructor TIconDialog.Destroy;
  54. begin
  55.   FHistory.Free;
  56.   inherited Destroy;
  57. end;
  58.  
  59. procedure TIconDialog.SetHistory(value : TStrings);
  60. begin
  61.   FHistory.Assign(value);
  62. end;
  63.  
  64.  
  65. function TIconDialog.Execute : Boolean;
  66. var form : TIconSelForm;
  67. begin
  68.   form := TIconSelForm.Create(Application);
  69.   with Form do
  70.   try
  71.     FileEdit.Text := Filename;
  72.     OpenDialog.HistoryList.Assign(FHistory);
  73.     Index := IconIndex;
  74.  
  75.     if ShowModal = mrOK then begin
  76.       Result := True;
  77.       Filename := Lowercase(FileEdit.Text);
  78.       IconIndex := Grid.Col;
  79.       with FHistory do begin
  80.         if IndexOf(Filename) = -1 then Insert(0, Filename);
  81.         while (Count > 0) and (Count > MaxHistorySize) do Delete(Count-1);
  82.       end;
  83.     end
  84.     else Result := False;
  85.   finally
  86.     Free;
  87.   end;
  88. end;
  89.  
  90.  
  91. procedure Register;
  92. begin
  93.   RegisterComponents('Dialogs', [TIconDialog]);
  94. end;
  95.  
  96. end.
  97.