Solved

Form Inheritance

Posted on 2004-04-12
10
544 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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 …
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 tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

623 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