Solved

Form Inheritance

Posted on 2004-04-12
10
514 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

820 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