Solved

Adding a visual component to a non visual one

Posted on 1998-05-18
8
161 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

14 Experts available now in Live!

Get 1:1 Help Now