home *** CD-ROM | disk | FTP | other *** search
- unit Ccsavrsu;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Buttons, ExtCtrls;
-
- type
- TSetupDialog = class(TForm)
- AcceptButton: TBitBtn;
- CancelButton: TBitBtn;
- TestButton: TBitBtn;
- Image1: TImage;
- Label1: TLabel;
- Edit1: TEdit;
- Label2: TLabel;
- Button1: TButton;
- ScrollBar1: TScrollBar;
- Label3: TLabel;
- OpenDialog1: TOpenDialog;
- procedure FormCreate(Sender: TObject);
- procedure AcceptButtonClick(Sender: TObject);
- procedure CancelButtonClick(Sender: TObject);
- procedure TestButtonClick(Sender: TObject);
- procedure ScrollBar1Change(Sender: TObject);
- procedure Edit1Exit(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- TheImageFileName : String; { This holds the image filename and path }
- TheImageSpeed : Integer; { This holds how fast to move the image }
- procedure ReadTheIniFile; { This reads in the configuration info }
- procedure WriteTheIniFile; { This writes out the configuration info }
- end;
-
- var
- SetupDialog: TSetupDialog;
-
- implementation
-
- {$R *.DFM}
-
- uses
- Ccscreen , { Actual screen saver unit }
- CCErrors , { CIUPKC Error dialogs unit }
- IniFiles; { INI Files manipulation unit }
-
- const
- IniFileName = 'CCSAVER.INI'; { Make this a constant to save stack space }
-
- { This procedure reads in the configuration from an INI file }
- procedure TSetupDialog.ReadTheIniFile;
- var
- { The excellent TIniFile object handles the complexity of Windows INI files! }
- TheIniFile : TIniFile;
- begin
- { Combine assignfile and reset into one call with create }
- TheIniFile := TIniFile.Create( IniFileName );
- { Use a try block to make sure the ini file is closed by free call }
- try
- { Use the Tinifile object's read methods to get the configuration data }
- with TheIniFile do
- begin
- { Use readinteger to get the speed to move the image }
- TheImageSpeed := ReadInteger( 'Setup', 'ImageSpeed', 0 );
- { Use readstring to get the image filename }
- TheImageFilename := ReadString( 'Setup', 'ImageFileName', '' );
- end;
- finally
- { Regardless of success or failure, free the TIniFile object }
- TheIniFile.Free;
- end;
- end;
-
- { This procedure writes out the configuration to an INI file }
- procedure TSetupDialog.WriteTheIniFile;
- var
- { Again use the very useful TIniFile object to encapsulate Windows INI files }
- TheIniFile : TIniFile;
- begin
- { Combine an AssignFile and Reset call into the create method }
- TheIniFile := TIniFile.Create( IniFileName );
- try
- { Use the TIniFile object's methods to write out the data }
- with TheIniFile do
- begin
- { Use writeinteger to send the image movement speed }
- WriteInteger( 'Setup' , 'ImageSpeed' , TheImageSpeed );
- { Use writestring to send the image file name }
- WriteString( 'Setup' , 'ImageFileName' , TheImageFileName );
- end;
- finally
- { Regardless of above calls, free the TIniFile object }
- TheIniFile.Free;
- end;
- end;
-
- { Delphi wrote this; put in the call to initialize from the setup INI file }
- procedure TSetupDialog.FormCreate(Sender: TObject);
- begin
- { Load in the setup }
- ReadTheIniFile;
- Scrollbar1.position := TheImageSpeed;
- {$I+}
- { Use a try construct to make sure errors are trapped }
- try
- { Try to load the image }
- Image1.Picture.LoadFromFile( TheImageFileName );
- { If successful reset the stored filename }
- except
- { Since the file exists, only possible error is invalid format }
- on EInvalidGraphic do
- begin
- { Signal error and make no further changes }
- ErrorDialog( 'File ' + TheImageFileName + ' Is Not A Valid Image!' );
- end;
- end;
- end;
-
- { Delphi wrote this; put in the call to save out the configuration data }
- { and close the main form, thereby exiting the configuration program }
- procedure TSetupDialog.AcceptButtonClick(Sender: TObject);
- begin
- { Write out the setup }
- WriteTheIniFile;
- { Close and exit }
- Close;
- end;
-
- { Delphi wrote this; put in call to close form and exit without saving }
- procedure TSetupDialog.CancelButtonClick(Sender: TObject);
- begin
- { Just close and exit since this is a cancel call }
- Close;
- end;
-
- { Delphi wrote this; put in the call to display the actual screen saver form }
- procedure TSetupDialog.TestButtonClick(Sender: TObject);
- begin
- { Show the screen saver form, thereby invoking the screen saver behavior! }
- CCScreenSaverForm.Show;
- end;
-
- { Delphi wrote this: put in the call to reset the label caption when the }
- { scrollbar position changes. }
- procedure TSetupDialog.ScrollBar1Change(Sender: TObject);
- begin
- { Reset the caption to reflect current scrollbar settings }
- Label3.Caption := 'Image Speed = ' + IntToStr( ScrollBar1.Position );
- TheImagespeed := ScrollBar1.position;
- end;
-
- { Delphi wrote this; put in the code to check for a valid image filename; }
- { if one is not found signal error(s); otherwise put it in the image and }
- { change the filename variable. }
- procedure TSetupDialog.Edit1Exit(Sender: TObject);
- begin
- { Only do this is the edit control text was modified }
- if Edit1.modified then
- begin
- { If the file does not exist then signal error and exit }
- if not FileExists( Edit1.Text ) then
- begin
- { This is from the CCErrors unit }
- ErrorDialog( 'File ' + Edit1.Text + ' Not Found!' );
- end
- else
- begin
- { Use a try construct to make sure errors are trapped }
- try
- { Try to load the image }
- Image1.Picture.LoadFromFile( Edit1.Text );
- { If successful reset the stored filename }
- TheImageFileName := Edit1.Text;
- except
- { Since the file exists, only possible error is invalid format }
- on EInvalidGraphic do
- begin
- { Signal error and make no further changes }
- ErrorDialog( 'File ' + Edit1.Text + ' Is Not A Valid Image!' );
- end;
- end;
- end;
- end;
- end;
-
- { Delphi wrote this code; put in call to activate the open dialog box }
- { and get a bitmap (GIF's will be added in sw version) and test it }
- procedure TSetupDialog.Button1Click(Sender: TObject);
- begin
- { Set the default extension and filename for bitmaps in the open dialog }
- OpenDialog1.DefaultExt := 'BMP';
- OpenDialog1.Filename := '*.BMP';
- { If successfully execute the dialog box then make changes }
- if OpenDialog1.Execute then
- begin
- { Get the filename into the edit control }
- Edit1.Text := OpenDialog1.Filename;
- { If the file does not exist then signal error and exit }
- if not FileExists( Edit1.Text ) then
- begin
- { This is from the CCErrors unit }
- ErrorDialog( 'File ' + Edit1.Text + ' Not Found!' );
- end
- else
- begin
- { Use a try construct to make sure errors are trapped }
- try
- { Try to load the image }
- Image1.Picture.LoadFromFile( Edit1.Text );
- { If successful reset the stored filename }
- TheImageFileName := Edit1.Text;
- except
- { Since the file exists, only possible error is invalid format }
- on EInvalidGraphic do
- begin
- { Signal error and make no further changes }
- ErrorDialog( 'File ' + Edit1.Text + ' Is Not A Valid Image!' );
- end;
- end;
- end;
- end;
- end;
-
- end.
-