Solved

Adding a visual component to a non visual one

Posted on 1998-05-18
8
162 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 89
Is anyone willing to have a look through this code and help debug? 25 75
Delphi...Split view - idea? 1 68
Graphics32 under Delphi 10.1 Berlin 2 66
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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