?
Solved

Adding a visual component to a non visual one

Posted on 1998-05-18
8
Medium Priority
?
169 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
[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
  • 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
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 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
 
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 400 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 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