Solved

Form Inheritance

Posted on 2004-04-12
10
505 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:Mayank S
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 95
MS Access Form Control Background Color Change Depending On How Long The String Text Length Is 18 80
Adjust the position 3 60
Problem to Alipay 10 17
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

815 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

15 Experts available now in Live!

Get 1:1 Help Now