Solved

Creating Image Viewer Component (Again!)

Posted on 2007-11-26
2
2,150 Views
Last Modified: 2013-11-23
Hi, I am making an Image viewer component in Delphi 7 that displays only bmp's. I have placed all of my sub components in a TPanel,  including

an Image Box
a Load File Button
An exit (close) button
A label that displays the file size

I have managed to code where I want  my buttons , labels and image box to be,  but what I want to know is how I add events to the buttons,  what code do I add to make the exit button close and to open a bmp?

I first made an application with all of the functionality working, just need to know how to transfer that to the compnent code?

Any ideas would be gratefully appreciated.

I have already asked this question before and I got a great solution from  expert dinilud (his code is below) but I forgot to ask him how I could retrieve & show another 2  image  properies in a label

1. File size in bytes or MB
2. Date file was created.

Cheers


unit ImageViewer;

 

interface

 

uses

  SysUtils, Classes, Controls, ExtCtrls, StdCtrls,ExtDlgs,Forms,Graphics;

 

type

  TImageViewer = class(TPanel)

  private

    { Private declarations }

    FLoadBmpBtn: TButton;

    FExitBtn: TButton;

    FInfoBtn: TButton;

    FImage1: TImage;

    FCreatedLabel: TLabel;

    FSizeLabel: TLabel;

    FSizeLabelCaption: TLabel;

    procedure FExitBtnClick(Sender: TObject);

    procedure FLoadBmpBtnClick(Sender: TObject);

    function GetPicture:TPicture;

    procedure SetPicture(Value:TPicture);

  protected

    { Protected declarations }

 

  public

    constructor Create(AOwner: TComponent); override;

    destructor Destroy; override;

    { Public declarations }

  published

    { Published declarations }

    property Picture:TPicture read GetPicture write SetPicture;

  end;

 

procedure Register;

 

implementation

 

procedure Register;

begin

  RegisterComponents('Samples', [TImageViewer]);

end;

 

constructor TImageViewer.Create(AOwner: TComponent);

begin

  inherited Create(AOwner);

  Caption:=' ';

  SetBounds(Left,Top,260,345);

  FLoadBmpBtn:=TButton.Create(Self);

  FLoadBmpBtn.Parent:=Self;

  FLoadBmpBtn.Caption:='Laod';

  FLoadBmpBtn.SetBounds(85,305,80,25);

  FLoadBmpBtn.Anchors:=[akBottom,akRight];

  FLoadBmpBtn.OnClick:=FLoadBmpBtnClick;

  FExitBtn:= TButton.Create(Self);

  FExitBtn.Parent:=Self;

  FExitBtn.Caption:='Exit';

  FExitBtn.SetBounds(167,305,80,25);

  FExitBtn.Anchors:=[akBottom,akRight];

  FExitBtn.OnClick:=FExitBtnClick; 

  FInfoBtn:= TButton.Create(Self);

  FInfoBtn.Parent:=Self;

  FInfoBtn.Caption:='Info';

  FInfoBtn.SetBounds(2,305,80,25);

  FInfoBtn.Anchors:=[akBottom,akRight];

  FImage1:=TImage.Create(Self);

  FImage1.Parent:=Self;

  FImage1.SetBounds(8,8,243,243);

  FImage1.Anchors:=[akLeft,akTop,akRight,akBottom];

  FImage1.Stretch:=True;

 

  FSizeLabelCaption:= TLabel.Create(Self);

  FSizeLabelCaption.Parent:=Self;

  FSizeLabelCaption.SetBounds(8,256,32,13);

  FSizeLabelCaption.Caption:='Size: ';

  FSizeLabelCaption.Anchors:=[akBottom,akLeft];

  FSizeLabel:= TLabel.Create(Self);

  FSizeLabel.Parent:=Self;

  FSizeLabel.SetBounds(FSizeLabelCaption.Left+FSizeLabelCaption.Width,256,32,13);

  FSizeLabel.Caption:='0 X 0';

  FSizeLabel.Anchors:=[akBottom,akLeft];

end;

 

destructor TImageViewer.Destroy;

begin

  FSizeLabelCaption.Free;

  FSizeLabel.Free;

  FImage1.Free;

  FInfoBtn.Free;

  FLoadBmpBtn.Free;

  FExitBtn.Free;

  inherited;

end;

 

procedure TImageViewer.FExitBtnClick(Sender: TObject);

var c:TComponent;

begin

  c:=Self;

  While TWinControl(C).Parent<>nil do

  begin

     if TWinControl(C).Parent is TCustomForm then

     begin

        TCustomForm(TWinControl(C).Parent).Close;

        Break;

     end;

     c:=TWinControl(C).Parent;

  end;

{  if TWinControl(C).Parent is TCustomForm then

      TCustomForm(TWinControl(C).Parent).Close;}

end;

 

procedure TImageViewer.FLoadBmpBtnClick(Sender: TObject);

var f:TOpenPictureDialog;

begin

   f:=TOpenPictureDialog.Create(Self);

   try

     if f.Execute then

     begin

       FImage1.Picture.LoadFromFile(f.FileName);

       FSizeLabel.Caption:=IntToStr(FImage1.Picture.Width)+' X '+

                               IntToStr(FImage1.Picture.Height);

     end;

 

   finally

     f.Free;

   end;

end;

 

function TImageViewer.GetPicture:TPicture;

begin

  Result:=FImage1.Picture;

end;

 

procedure TImageViewer.SetPicture(Value:TPicture);

begin

   FImage1.Picture.Assign(Value);

   FSizeLabel.Caption:=IntToStr(FImage1.Picture.Width)+' X '+

                               IntToStr(FImage1.Picture.Height);

end;

 

end.

Open in new window

0
Comment
Question by:gedge73
2 Comments
 

Author Comment

by:gedge73
ID: 20353839
Anybody?
0
 
LVL 1

Accepted Solution

by:
carcotasu earned 500 total points
ID: 20356389
try to replace this procedure:



procedure TImageViewer.FLoadBmpBtnClick(Sender: TObject);

var f:TOpenPictureDialog;

    fs: file of Byte;

    fSize, fDate :string ;

begin

   f:=TOpenPictureDialog.Create(Self);

   try

     if f.Execute then

     begin

       FImage1.Picture.LoadFromFile(f.FileName);

       // size in bytes

       try

          AssignFile(fs, F.FileName);

          Reset(fs);

          fSize:=IntToStr(FileSize(fs)) ;

          CloseFile(fs);

       except

         fSize:='Unknown' ;

       end ;

       // end size

       // date file

       try

          fDate:=DateTimeToStr(FileDateToDateTime(FileAge(F.FileName)));

       except

          fDate:='Unknown';

       end ;

       // end date file

       FSizeLabel.Caption:=IntToStr(FImage1.Picture.Width)+' X '+

                               IntToStr(FImage1.Picture.Height)+' Size: '+

                               fSize+' Date File: '+fDate ;

     end;
 

   finally

     f.Free;

   end;

end;

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
indy tidtcpclient threading issue 8 63
Delphi cmd execution 6 55
LAN or WAN ? 11 81
How do I add a client SSL certificate to a SOAP client in Rad Studio Delphi? 2 42
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now