Board index » delphi » Detecting TPicture.Loadfromfile - 2nd try.

Detecting TPicture.Loadfromfile - 2nd try.

I've asked this before but still don't have a satisfactory answer. I
need to detect when an image is loaded into the Picture of a TImage
component. Grateful for any suggestions.

Alan Hale

 

Re:Detecting TPicture.Loadfromfile - 2nd try.


Hi !

You may write an event handler, and hook into TImage.Picture.OnChange or
OnProgress:

MyImage.Picture.OnChange:=MyPictureChanged;

procedure TMyForm.MyPictureChanged(Sender: TObject);
begin
  // do something...
end;

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

Alan Hale skrev i meldingen <38C0EDBC.90BAC...@clara.net>...

Quote
>I've asked this before but still don't have a satisfactory answer. I
>need to detect when an image is loaded into the Picture of a TImage
>component. Grateful for any suggestions.

>Alan Hale

Re:Detecting TPicture.Loadfromfile - 2nd try.


Quote
Alan Hale <adh...@clara.net> wrote in message

news:38C0EDBC.90BACD5F@clara.net...

Quote
> I've asked this before but still don't have a satisfactory answer. I
> need to detect when an image is loaded into the Picture of a TImage
> component. Grateful for any suggestions.

> Alan Hale

Have a look at the OH: TImage.Graphic -> TGraphic.Empty:

---OH -------
Indicates whether the graphics object contains a graphic.

property Empty: Boolean;

Description

Use Empty to determine whether the graphic is bound to an image. Each
descendant graphic object defines its own Get method to access the Empty
property.
---OH -------

HTH Martin

Re:Detecting TPicture.Loadfromfile - 2nd try.


Thanks for the reply - but surely the problem with either of these is that
they will respond to ANY event affecting the picture (like if I draw on it).
OnProgress according to the Help "Occurs periodically during slow operations
that affect the image" so sounds like it could not be guaranteed to occur
anyway.

Alan Hale

Quote
"Bj?rge S?ther" wrote:
> Hi !

> You may write an event handler, and hook into TImage.Picture.OnChange or
> OnProgress:

> MyImage.Picture.OnChange:=MyPictureChanged;

> procedure TMyForm.MyPictureChanged(Sender: TObject);
> begin
>   // do something...
> end;

> --
> Bjoerge Saether
> Consultant / Developer
> Asker, Norway
> bsaether.removet...@online.no (remove the obvious)

> Alan Hale skrev i meldingen <38C0EDBC.90BAC...@clara.net>...
> >I've asked this before but still don't have a satisfactory answer. I
> >need to detect when an image is loaded into the Picture of a TImage
> >component. Grateful for any suggestions.

> >Alan Hale

Re:Detecting TPicture.Loadfromfile - 2nd try.


Mmm - maybe. But I want to trigger an operation as soon as the graphic is
loaded. And also if the graphic changes i.e. if a new one is loaded.

Alan Hale

Quote
"Martin Wei?" wrote:
> Alan Hale <adh...@clara.net> wrote in message
> news:38C0EDBC.90BACD5F@clara.net...
> > I've asked this before but still don't have a satisfactory answer. I
> > need to detect when an image is loaded into the Picture of a TImage
> > component. Grateful for any suggestions.

> > Alan Hale

> Have a look at the OH: TImage.Graphic -> TGraphic.Empty:

> ---OH -------
> Indicates whether the graphics object contains a graphic.

> property Empty: Boolean;

> Description

> Use Empty to determine whether the graphic is bound to an image. Each
> descendant graphic object defines its own Get method to access the Empty
> property.
> ---OH -------

> HTH Martin

Re:Detecting TPicture.Loadfromfile - 2nd try.


Quote
In article <38C14394.C409D...@clara.net>, Alan Hale <adh...@clara.net> writes:
>Mmm - maybe. But I want to trigger an operation as soon as the graphic is
>loaded. And also if the graphic changes i.e. if a new one is loaded.

Can you tell me please, how you could possibly _not_ know when a picture was
being loaded.

Gordon.
~~~~~~~~~~~~~~~~~~~~~~~~
Try one get one free Equation Illustrator V equation editor
http://members.aol.com/equation2/betas.htm  :))
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Re:Detecting TPicture.Loadfromfile - 2nd try.


I'm working on a custom component derived from TImage and I would like to be able
to detect programatically when a graphic is loaded and then call a particular
procedure. I could call the procedure from the main application every time a
graphic is loaded, but since calling this procedure is essential to the
functionality of the component and needs to always be done I would prefer the
component to detect when a graphic is loaded.

Alan Hale

Quote
Gordon Whittam wrote:
> In article <38C14394.C409D...@clara.net>, Alan Hale <adh...@clara.net> writes:

> >Mmm - maybe. But I want to trigger an operation as soon as the graphic is
> >loaded. And also if the graphic changes i.e. if a new one is loaded.

> Can you tell me please, how you could possibly _not_ know when a picture was
> being loaded.

> Gordon.
> ~~~~~~~~~~~~~~~~~~~~~~~~
> Try one get one free Equation Illustrator V equation editor
> http://members.aol.com/equation2/betas.htm  :))
> http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
> few links)

> MGCSoft

Re:Detecting TPicture.Loadfromfile - 2nd try.


Quote
On Sun, 05 Mar 2000 06:40:37 GMT, Alan Hale <adh...@clara.net> wrote:
>I'm working on a custom component derived from TImage and I would like to be able
>to detect programatically when a graphic is loaded and then call a particular
>procedure. I could call the procedure from the main application every time a
>graphic is loaded, but since calling this procedure is essential to the
>functionality of the component and needs to always be done I would prefer the
>component to detect when a graphic is loaded.

>Alan Hale

>Gordon Whittam wrote:

>> In article <38C14394.C409D...@clara.net>, Alan Hale <adh...@clara.net> writes:

>> >Mmm - maybe. But I want to trigger an operation as soon as the graphic is
>> >loaded. And also if the graphic changes i.e. if a new one is loaded.

>> Can you tell me please, how you could possibly _not_ know when a picture was
>> being loaded.

Any reason you don't just make your own LoadFileFile which calls the
inherited LoadFromFile then calls your routine?

Michael

Re:Detecting TPicture.Loadfromfile - 2nd try.


Quote
Michael Phillips wrote:
> Any reason you don't just make your own LoadFileFile which calls the
> inherited LoadFromFile then calls your routine?

Thanks for the suggestion, which might seem blindingly obvious. The drawback as far as
I can see is that what you would have to do is make a TPicture-derived custom
component and inherit, extend LoadFromFile from there and make my TImage-derived
component use this.. This would require the  user  to know they have to use the custom
TPicture method (let's call it TadhPicture.LoadFromFile) rather than
tPicture.LoadFromFile. Which doesn't really take me any further on in my aim of
eliminating unnecessary work for the component user. I'm very open to correction or
further suggestions however.

Alan Hale

Re:Detecting TPicture.Loadfromfile - 2nd try.


Quote
In article <38C35790.CA66D...@clara.net>, Alan Hale <adh...@clara.net> writes:
>Thanks for the suggestion, which might seem blindingly obvious. The drawback
>as far as
>I can see is that what you would have to do is make a TPicture-derived custom
>component and inherit, extend LoadFromFile from there and make my
>TImage-derived
>component use this.. This would require the  user  to know they have to use
>the custom
>TPicture method (let's call it TadhPicture.LoadFromFile) rather than
>tPicture.LoadFromFile. Which doesn't really take me any further on in my aim
>of
>eliminating unnecessary work for the component user. I'm very open to
>correction or
>further suggestions however.

You can re-declare LoadFromFile in your new component. As it's static it will
just replace the inherited method, from where you can call the
     inherited LoadFromFile(FileName);

From the D3 Help:
"This means that you cannot override static methods; a static method always
does exactly the same thing no matter what class it is called in. If you
declare a method in a derived class with the same name as a static method in
the ancestor class, the new method simply replaces the inherited one in the
derived class."

Gordon.
~~~~~~~~~~~~~~~~~~~~~~~~
Try one get one free Equation Illustrator V equation editor
http://members.aol.com/equation2/betas.htm  :))
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Re:Detecting TPicture.Loadfromfile - 2nd try.


I may be out of my depth - but I don't understand how you would do this when
Loadfromfile is a method of TPicture, whilst my component is a TImage descendant.

Alan Hale

Quote
Gordon Whittam wrote:
> You can re-declare LoadFromFile in your new component. As it's static it will
> just replace the inherited method, from where you can call the
>      inherited LoadFromFile(FileName);

Re:Detecting TPicture.Loadfromfile - 2nd try.


Quote
In article <38C55B3A.6CD56...@clara.net>, Alan Hale <adh...@clara.net> writes:
> may be out of my depth - but I don't understand how you would do this when
>Loadfromfile is a method of TPicture, whilst my component is a TImage
>descendant.

>Alan Hale

>Gordon Whittam wrote:

>> You can re-declare LoadFromFile in your new component. As it's static it
>will
>> just replace the inherited method, from where you can call the
>>      inherited LoadFromFile(FileName);

Sorry, I should have been reading the thread properly. It should have been

       inherited  Picture.LoadFromFile(FileName);

I've attached the source of  little demo (D3) in your mail.

Gordon.
~~~~~~~~~~~~~~~~~~~~~~~~
Try one get one free Equation Illustrator V equation editor
http://members.aol.com/equation2/betas.htm  :))
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Re:Detecting TPicture.Loadfromfile - 2nd try.


Gordon
This is just what I need - excellent. Many thanks for your help.

Alan

Quote
Gordon Whittam wrote:
> I've attached the source of  little demo (D3) in your mail.

Re:Detecting TPicture.Loadfromfile - 2nd try.


Mmm. When I looked again (it was getting late last night when I first
looked) unfortunately it's not quite what I want. The component user has
to know to use TMyImage.LoadfromFile rather than
TMyImage.Picture.Loadfromfile - so I'm only slightly further on in
making less work for that user. If I  have to tell them to do that, I
may as well tell them to call the procedure I need to be run themselves
from Picture.Loadfromfile.

Still, I learnt something from your code and much appreciated.

Alan

Quote
Alan Hale wrote:
> Gordon
> This is just what I need - excellent. Many thanks for your help.

> Alan

> Gordon Whittam wrote:

> > I've attached the source of  little demo (D3) in your mail.

Re:Detecting TPicture.Loadfromfile - 2nd try.


Quote
In article <38C5F53C.5E0B...@clara.net>, Alan Hale <adh...@clara.net> writes:
>Mmm. When I looked again (it was getting late last night when I first
>looked) unfortunately it's not quite what I want. The component user has
>to know to use TMyImage.LoadfromFile rather than
>TMyImage.Picture.Loadfromfile - so I'm only slightly further on in
>making less work for that user. If I  have to tell them to do that, I
>may as well tell them to call the procedure I need to be run themselves
>from Picture.Loadfromfile.

>Still, I learnt something from your code and much appreciated.

No problem.

     I think you're going to have to declare a TImage as one of your variables
and your component will have to be descended from something further down the
tree. If you do that you will be able to declare 'Picture' as a property, along
with everything else but you're going to have to do an awful lot of inheriting
and message forwarding I think. It depends on how much of the functionality of
TImage you want to keep.

Gordon.
~~~~~~~~~~~~~~~~~~~~~~~~
Try one get one free Equation Illustrator V equation editor
http://members.aol.com/equation2/betas.htm  :))
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Other Threads