Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 563
  • Last Modified:

Form Inheritance

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
myleseven2
Asked:
myleseven2
  • 5
  • 4
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
Do you mind telling which language you are using? (Everybody might not have heard of the ExTImage to figure that out).
0
 
CayceCommented:
I suppose you're either using Delphi/C++Builder/Kylix. However it would be great to know which one are you using.

Regards
0
 
myleseven2Author Commented:
Hi
I am using Delphi 7

thanks :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CayceCommented:
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
 
myleseven2Author Commented:
I will try and find it for you
0
 
CayceCommented:
I found it at: http://extimage.narod.ru/

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

0
 
myleseven2Author Commented:
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
 
CayceCommented:
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
 
myleseven2Author Commented:
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
 
CayceCommented:
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now