Solved

Adding a visual component to a non visual one

Posted on 1998-05-18
8
160 Views
Last Modified: 2010-04-06
Hi

I didn't get an answer to my last question, so I'm trying again from a different approach.  How can I add a visual component to a non visual component and make it visible at both design time and runtime?

I am talking about adding a TGauge to a TReport.

I have done the following:

type
  TJRptMeter = class(TReport)
  private
    { Private declarations }
    FGauge: TGauge;

etc etc...

constructor TJRptMeter.Create(AOwner: TComponent);
begin
     inherited Create(AOwner);
     FGauge := TGauge.Create(Self);
     FGauge.Parent := Self;
     FGauge.Visible := True;
     FGauge.Height := 25;
     FGauge.ForeColor := clRed;
end;

The line FGauge.Parent := Self produces the error "Type Mismatch".  Also the Gauge does not become visible even at runtime.  Any ideas about what I need to do???
0
Comment
Question by:jdthedj
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1346199
Hi

As you probably know, TReport inherits from TComponent.  That's why you can't assign the gauge's parent to the report.  A visible control's (the gauge) parent must be a visible control, not a TComponent.

Try setting FGauge.Parent := Self.Owner;

JB
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1346200
Hi JimBob - thanks for the reply.  I tried that, but I still get the Type Mismatch error.  Any other ideas??
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1346201
Try type-casting it to a TWinControl.

E.g.  FGauge.Parent := TWinControl(Self.Owner);

JB
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1346202
Thanks again JimBob

That one works OK, but it GPFs in Complib.dcl when I close the form.  Also is there a way to make it move when I move the TReport it's attached to.  TReport doesn't have Top and Left properties.  Or can I drag it (the TGauge part)?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:JimBob091197
ID: 1346203
Mmm...  Regarding the GPF, are you freeing the gauge in your report's destructor?  Try setting FGauge.Parent := nil before freeing the gauge.

Regarding the moving when you move the TReport, I don't have anything to suggest, except that you may only want to create the gauge at run-time (check "if (csDesigning in ComponentState) then ...").

The other alternative is not to have the gauge created & owned by the report, but to write a custom gauge which the report can link to.  I.e. have a property on the report called "Gauge" of type TGauge, which the report can use if the report's Gauge property <> nil.

JB
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1346204
Hi JimBob

I've spent some time experimenting after your last comments, and I've finally got things working.  I've had to compromise on some of it, but the main thing is it will do what I need.  I want to give you the points, so if you'd like to convert to an answer I'll gladly pass them on.

Thanks again for all your help.

JD
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1346205
Hi JD

Glad that you got it working.
Did you use "FGauge.Parent := TWinControl(Self.Owner)"?

Cheers,
JB
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1346206
Hi JimBob - yes, I did use the TWinControl method. Thanks again
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

18 Experts available now in Live!

Get 1:1 Help Now