home *** CD-ROM | disk | FTP | other *** search
- unit Pcximage;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, ExtCtrls, DelphPCX;
-
- type
- TPCXImage = class(TImage)
- private
- { Private declarations }
- FTheFileName : String;
- ThePCXFO : TPCXFileObject;
- protected
- { Protected declarations }
- OldFileName : String;
- TheBitmap : TBitmap;
- valid_load : Boolean;
- public
- { Public declarations }
- constructor Create( AOwner : TComponent ); override;
- destructor Destroy; override;
- procedure Paint; override;
- procedure LoadPCXFile;
- published
- { Published declarations }
- property TheFileName : String read FTheFileName write FTheFileName;
- end;
-
- procedure Register;
-
- implementation
-
- constructor TPCXImage.Create( AOwner : TComponent );
- begin
- inherited Create( AOwner );
- TheBitmap := TBitmap.Create;
- ThePCXFO := TPCXFileObject.Create;
- end;
-
- destructor TPCXImage.Destroy;
- begin
- TheBitmap.Free;
- ThePCXFO.Free;
- inherited Destroy;
- end;
-
- procedure TPCXImage.LoadPCXFile;
- var ThePChar : PChar;
- TheBMP : hBitmap;
- ThePalette : hPalette;
- begin
- Valid_Load := false;
- if not FileExists( TheFileName ) then
- begin
- MessageDlg( TheFileName + ' cannot be found!',mterror,[mbOK],0);
- exit;
- end;
- Screen.Cursor := crHourGlass;
- GetMem( ThePChar , 256 );
- StrPCopy( ThePChar , theFileName );
- ThePCXFO.Init( ThePChar );
- Freemem( ThePChar , 256 );
- ThePCXFO.LoadPCXBitmap( TheBMP , ThePalette );
- TheBitmap.Handle := TheBMP;
- TheBitmap.Palette := ThePalette;
- Screen.Cursor := crDefault;
- oldFileName := TheFileName;
- valid_load := true;
- end;
-
- procedure TPCXImage.Paint;
- begin
- if csDesigning in ComponentState then
- begin
- inherited Paint;
- exit;
- end;
- if TheFileName = '' then
- begin
- inherited Paint;
- exit;
- end;
- if oldfilename <> Thefilename then
- begin
- LoadPCXFile;
- if not Valid_load then
- begin
- Picture.Bitmap.Height := 0;
- Picture.Bitmap.Width := 0;
- inherited Paint;
- exit;
- end;
- Picture.Bitmap.Height := TheBitmap.Height;
- Picture.Bitmap.Width := TheBitmap.Width;
- Picture.Bitmap.Handle := TheBitmap.Handle;
- inherited Paint;
- exit;
- end;
- inherited Paint;
- end;
-
-
- procedure Register;
- begin
- RegisterComponents('Widgets', [TPCXImage]);
- end;
-
- end.
-