Solved

Form Inheritance

Posted on 2004-04-12
10
482 Views
Last Modified: 2013-11-25
Hi there :)
I have a question,
My freinds and I are building an application and we would like all the forms to inherit from a Base Form. This is fine, howerever we need to use roll over images. We cannot use the TImage component because this does not have built in roll over capability, so my freind downloaded a component that inherits from TImage. It is called ExTImage and includes roll over functionality. The problem is the forms that inherit from the Base form do not pick up the image and we don't know why. If we use Timage then the other forms do pick up the image, so it is kind of strange. We have looked at the source code for ExTImage and it is quite simple, it inherits from TImage and has four extra functions to allow for roll overs, so we can't understand why it doesn't work. Does anyone have any ideas?
Thanks much appreciated
Myles
0
Comment
Question by:myleseven2
  • 5
  • 4
10 Comments
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10811804
Do you mind telling which language you are using? (Everybody might not have heard of the ExTImage to figure that out).
0
 
LVL 9

Expert Comment

by:Cayce
ID: 10814776
I suppose you're either using Delphi/C++Builder/Kylix. However it would be great to know which one are you using.

Regards
0
 

Author Comment

by:myleseven2
ID: 10815862
Hi
I am using Delphi 7

thanks :)
0
 
LVL 9

Expert Comment

by:Cayce
ID: 10817504
Is the ExTImaga available for FREE download? So I can test this. I guess I can google for it, but and URL for prosperity would be good.
0
 

Author Comment

by:myleseven2
ID: 10817885
I will try and find it for you
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 9

Expert Comment

by:Cayce
ID: 10817915
I found it at: http://extimage.narod.ru/

It's closed source... bad luck there. Guess I can't help you.

0
 

Author Comment

by:myleseven2
ID: 10817936
Hey it was a while ago that we found the component and it is a little difficult to track down. Below is the code for the component is this any help for you...

unit Ex_Image_component;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  ExTImage = class (TImage)
  private
    { Private declarations }
    FOnMouseLeave: TNotifyEvent;
    FOnMouseEnter: TNotifyEvent;
    procedure CMMouseEnter(var msg: TMessage);
      message CM_MOUSEENTER;
    procedure CMMouseLeave(var msg: TMessage);
      message CM_MOUSELEAVE;
  protected
    { Protected declarations }
    procedure DoMouseEnter; dynamic;
    procedure DoMouseLeave; dynamic;
  public
    { Public declarations }
  published
    { Published declarations }
    property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
    property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  end;

procedure Register;

implementation

{ TImageEx }

procedure ExTImage.CMMouseEnter(var msg: TMessage);
begin
  DoMouseEnter;
end;

procedure ExTImage.CMMouseLeave(var msg: TMessage);
begin
  DoMouseLeave;
end;

procedure ExTImage.DoMouseEnter;
begin
  if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;

procedure ExTImage.DoMouseLeave;
begin
  if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;


procedure Register;
begin
  RegisterComponents('Samples', [ExTImage]);
end;

end.
0
 
LVL 9

Accepted Solution

by:
Cayce earned 250 total points
ID: 10818111
This is my guess:

On the original (parent) form you assigned a procedure for both the OnMouseEnter and OnMouseLeave events.
Then you inherited the form, and that code is not being called on the descendant form. That's because events assignment to procedures doesn't happen really until the application runs and they're loaded (from the executable embedded dfm), this won't happen on inherited forms (because the dfm contains the data on the descendant form, not the parent's).

This can be solved by using templates (I guess, can't test) instead of inheriting  or by assiging the code on the constructor of the parent form like this:

constructor TParentForm.Create( AOwner: TComponent );
begin
  { Whatever the constructor already does }
  Self.ExImage.OnMouseEnter = ParentFormOnMouseEnter;
  Self.ExImage.OnMouseLeave = ParentFormOnMouseLeave;
end;

procedure TParentForm.ParentFormOnMouseEnter(Source: TObject);
begin
  { Make the rollover happen }
end;

procedure TParentForm.ParentFormOnMouseLeave(Source: TObject);
begin
  { Make the rollover happen }
end;

As I said this is just my guess. I need to test it. However I don't use Delphi (just BCB). Although BCB compiles Delphi, so I'll test, then post my results.
0
 

Author Comment

by:myleseven2
ID: 10818373
Hi Cayce,

Thanks for your help
I have discovered now what I think might have been the problem. Image in the scenario

frmParent has a ExTImage component called imButtonImage
frmChild inherits from BaseForm

If you load an image into frmChild.imButtonImage then this appears to sever the inherit connection of imButtonImage to the parent form. Thus if you load up an image into  frmParent.imButtonImage it will not display in frmChild.imButtonImage.

Well thanks for all your help, I hope the component is wuseful for you in the future :), if you have any new thoughts on this component I would love to hear them...
Thanks again Have a good day
Myles
0
 
LVL 9

Expert Comment

by:Cayce
ID: 10818572
Good for you!!!

Here's my updated component anyway. This one does the roll over automatically.

unit ExImage;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TExImage = class (TImage)
  private
    { Private declarations }
    FOnMouseLeave: TNotifyEvent;
    FOnMouseEnter: TNotifyEvent;
    FMouseEnterPicture: TPicture;
    FMouseLeavePicture: TPicture;
    procedure CMMouseEnter(var msg: TMessage);
      message CM_MOUSEENTER;
    procedure CMMouseLeave(var msg: TMessage);
      message CM_MOUSELEAVE;
  protected
    { Protected declarations }
    procedure DoMouseEnter; dynamic;
    procedure DoMouseLeave; dynamic;
    procedure SetMouseEnterPicture(Value: TPicture);
    procedure SetMouseLeavePicture(Value: TPicture);
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
    property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
    property MouseEnterPicture: TPicture read FMouseEnterPicture write SetMouseEnterPicture;
    property MouseLeavePicture: TPicture read FMouseLeavePicture write SetMouseLeavePicture;
  end;

procedure Register;

implementation

{ TExImage }

procedure Register;
begin
  RegisterComponents('Samples', [TExImage]);
end;

procedure TExImage.SetMouseEnterPicture(Value: TPicture);
begin
  FMouseEnterPicture.Assign(Value);
end;

procedure TExImage.SetMouseLeavePicture(Value: TPicture);
begin
  Picture := Value;
  FMouseLeavePicture.Assign(Value);
end;

destructor TExImage.Destroy;
begin
  FMouseEnterPicture.Free;
  FMouseLeavePicture.Free;
  inherited Destroy;
end;

constructor TExImage.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FMouseEnterPicture := TPicture.Create;
  FMouseLeavePicture := TPicture.Create;
end;

procedure TExImage.CMMouseLeave(var msg: TMessage);
begin
  DoMouseLeave;
end;

procedure TExImage.DoMouseEnter;
begin
  Picture := FMouseEnterPicture;
  if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;

procedure TExImage.DoMouseLeave;
begin
  Picture :=  FMouseLeavePicture;
  if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;


procedure TExImage.CMMouseEnter(var msg: TMessage);
begin
  DoMouseEnter;
end;

end.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 55
How To Loop - Python 19 66
message box in access 4 33
passing a value with stream reader AFTER a ";" 3 41
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

708 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

16 Experts available now in Live!

Get 1:1 Help Now