Components in Components

I'm finishing up on a component that I've been creating at run-time but thought I'd go ahead and compile it and add it to my palette.  The component contains a number of TPersistent components and a couple of TComponents.  It's working well, and it compiles OK, but in the Object Inspector each of the TComponent properties has a drop-down control next to it, as if I was supposed to pick a component from a list.  What is going on with this?  Do I need to define the owner differently, or specify a parent-lik
e object?  I'd rather it just list the name of the class, like how it is done with the axes and other components in a TChart.

Here's a screen shot of my object inspector:  [http://www.kstreetstudio.com/files/misc/CNi-01.jpg] 

Note the properties in red and the text next to them that says "CNiSeries1."

Here's typically what I do in the Create procedure of the main component:

  FRamp:=TCNiRamp.Create(Self);
  with FRamp do
  begin
    FRamp.FEnabled:=false;
    FRamp.FTime:=0;
    FSoak.FEnabled:=false;
    FSoak.FTime:=0;
  end;

And here is another, but it is an Indy component (I did not write this one).

  // Create the TCP/IP client component
  FTCPPort:=TIdTCPClient.Create(self);
  with FTCPPort do
  begin
    Port:=2000;
    Host:='192.168.1.200';
  end;

Thanks.  (Again).
Mike
0
Mike
6/19/2009 12:45:07 AM
public.delphi.vcl.writing 510 articles. 0 followers. Follow

13 Replies
1432 Views

Similar Articles

[PageSpeed] 48

On Thu, 18 Jun 2009 17:45:07 -0700, Mike Meier wrote:

> I'm finishing up on a component that I've been creating at run-time but thought I'd go ahead and compile it and add it to my palette.  The component contains a number of TPersistent components and a couple of TComponents.  It's working well, and it compiles OK, but in the Object Inspector each of the TComponent properties has a drop-down control next to it, as if I was supposed to pick a component from a list.  What is going on with this?  Do I need to define the owner differently, or specify a parent-l
ik
> e object?  I'd rather it just list the name of the class, like how it is done with the axes and other components in a TChart.

By default the IDE assumes that a property with a component type
should refer to another component on your form. You can change this by
calling the SetSubComponent method.

-- 
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com
0
Marc
6/19/2009 2:04:35 AM
<Mike Meier> wrote in message news:129325@forums.codegear.com...

> It's working well, and it compiles OK, but in the Object Inspector
> each of the TComponent properties has a drop-down control next
> to it, as if I was supposed to pick a component from a list.  What
> is going on with this?

In order to embed a TComponent inside of another TComponent and have it be 
available to the Object Inspector correctly, you have to call the embedded 
component's SetSubComponent() method, ie:

{code:delphi}
FRamp := TCNiRamp.Create(Self);
FRamp.SetSubComponent(True);
....
FTCPPort := TIdTCPClient.Create(self);
FTCPPort.SetSubComponent(True);
{code}

-- 
Remy Lebeau (TeamB)
0
Remy
6/19/2009 2:14:30 AM
Thanks.  I had completely forgotten about SetSubcomponent.  I guess I don't do this often enough.

But, it didn't do the job.  After more fiddling and reading I did figure out that part of the problem was that I had not declared these as read-only properties.  When I did that the drop-down list disappeared, but the the name of the owner is still listed.  If that is normal, I guess I'll go with that.  But I was hoping, for tidiness sake, that they the class name would be displayed instead, like it is for the TPersistent component/properties.
0
Mike
6/19/2009 9:37:27 PM
<Mike Meier> wrote in message news:129680@forums.codegear.com...

> But, it didn't do the job.

Then please show your actual code.  You don't have it set up correctly yet.

> After more fiddling and reading I did figure out that part of the
> problem was that I had not declared these as read-only properties.

They don't need to be.  In fact, if they are, they won't appear in the OI by 
default, as it only displays read/write properties.

-- 
Remy Lebeau (TeamB)
0
Remy
6/19/2009 11:02:34 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> 
> Then please show your actual code.  You don't have it set up correctly yet.
> 

The whole thing is over 4500 lines and still growing, but here are some snippets.

*Declaring TCNiRamp component:*

const   CNi_Ramp=               $08;    // 00001000b    Enable control ramping
        CNi_Soak=               $10;    // 00010000b    Enable soak time

type TCNiRampSoak = class(TPersistent)
  private
    FEnabled:boolean;
    FTime:integer;
  protected
    procedure Assign(Source: TPersistent); override;
  public
  published
    property Enabled:boolean read FEnabled write FEnabled;
    property Time:integer read FTime write FTime;
  end;

type TCNiRamp = class (TComponent)
  private
    FRamp:TCNiRampSoak;
    FSoak:TCNiRampSoak;
    procedure FSetRamp(Value:TCNiRampSoak);
    procedure FSetSoak(Value:TCNiRampSoak);
  protected
    procedure Assign(Source: TPersistent); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Ramp:TCNiRampSoak read FRamp write FSetRamp;
    property Soak:TCNiRampSoak read FSoak write FSetSoak;
  end;


*The create procedure for TCNiRamp:*

constructor TCNiRamp.Create(AOwner: TComponent);
// create component
begin
  inherited Create(AOwner);
  FRamp:=TCNiRampSoak.Create;
  FSoak:=TCNiRampSoak.Create;
end;


*The main custom and final component:*

type
  TCustomCNiSeries = class(TComponent)
  private { Private declarations }
..
..
..
    FOutput1:TCNiOutput1;       // Output 1 settings
    FOutput2:TCNiOutput2;       // Output 2 settings
    FRamp:TCNiRamp;             // Ramp settings
    FID:TCNiID;                 // Security ID settings
    FComm:TCNiComm;             // Serial port communications parameters
    FColor:TCNiColor;           // Color settings;

    // I/O port variables
    FPortType:TCNiPortType;     // Port type (TCP/IP or serial port)
    FTCPPort:TIdTCPClient;      // Indy TCP/IP client component
    FComPort: TComPort;         // TComPort serial port component
..
..
..
  public { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
..
..
..
    // Ports properties
    property PortType:TCNiPortType read FPortType write FSetPortType;
    property ComPort:TComPort read FComPort;
    property TCPPort:TIdTCPClient read FTCPPort;
    property Output1:TCNiOutput1 read FOutput1;
    property Output2:TCNiOutput2 read FOutput2;
    property Ramp:TCNiRamp read FRamp;
    property Comm:TCNiComm read FComm;
end;


type TCNiSeries=class(TCustomCNiSeries)
    property CJCValue;
    property Retries;
    property TimeOut;
    property PortType;
    property ComPort;
    property TCPPort;
    property ErrorNr;           // Describes the error
    property SetPoint1;         // Controller's setpoint 1
    property SetPoint2;         // Controller's setpoint 2
    property PercentLow;        // Minimum power output
    property PercentHigh;       // Maximum power output
    property Input;             // Sensor characteristics
    property Reading;           // Reading options
//    property Alarm1;            // Alarm 1's settings
//    property Alarm2;            // Alarm 2's settings
//    property Loop;              // Loop settings
    property Self;
    property Output1;           // Output 1's settings
    property Output2;           // Output 2's settings
    property Ramp;              // Ramp and soak settings
//    property ID;                // Security ID
    property Comm;              // Communications parameters
    property Color;
  end;


*The Create procedure for the custom component:*

constructor TCustomCNiSeries.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
..
..
..
  FOutput1:=TCNiOutput1.Create(Self);
  FOutput1.SetSubComponent(True);
  with FOutput1 do
  begin
    FControlMode:=cmOnOff;
    FActionType:=atReverse;
    FAnalogControl:=false;
  end;

  FOutput2:=TCNiOutput2.Create(Self);
  FOutput2.SetSubComponent(True);
  with FOutput2 do
  begin
    FControlMode:=cmOnOff;
    FActionType:=atReverse;
  end;

  FRamp:=TCNiRamp.Create(Self);
  FRamp.SetSubComponent(True);
  with FRamp do
  begin
    FRamp.FEnabled:=false;
    FRamp.FTime:=0;
    FSoak.FEnabled:=false;
    FSoak.FTime:=0;
  end;

*And finally, Register:*

procedure Register;

implementation

uses Forms;

procedure Register;
begin
  RegisterComponents('K Street', [TCNiSeries]);
end;
0
Mike
6/20/2009 12:44:27 AM
> > After more fiddling and reading I did figure out that part of the
> > problem was that I had not declared these as read-only properties.
> 
> They don't need to be.  In fact, if they are, they won't appear in
> the OI by default, as it only displays read/write properties.

Actually, it has since D6, the same time SetSubComponent was
introduced...

-- 
Chris Rolliston
http://delphihaven.wordpress.com/
0
Chris
6/21/2009 4:10:41 PM
> The whole thing is over 4500 lines and still growing, but here are
> some snippets.

As you've already figured out, make the sub-component properties
read-only. Also, don't forget to set each sub-component's Name property
to something sensible, typically the name of the propery it provides
the value for.

-- 
Chris Rolliston
http://delphihaven.wordpress.com/
0
Chris
6/21/2009 4:15:24 PM
A little more code.  Could be that I'm not handling the assign issue correctly

*For a TPersistent component:*

procedure TCNiSelfControl.Assign(Source: TPersistent);
begin
procedure TCNiRampSoak.Assign(Source: TPersistent);
begin
  if Source is TCNiRampSoak then
  begin
    FEnabled:=TCNiRampSoak(Source).Enabled;
    FTime:=TCNiRampSoak(Source).Time;
  end;
  inherited Assign(Source);
end;

*Oops, here's something. I was passing a TPersistent in a TComponent.Assign method.*

procedure TCNiRamp.Assign(Source: TPersistent);
begin
  if Source is TCNiRamp then
  begin
    FRamp:=TCNiRamp(Source).Ramp;
    FSoak:=TCNiRamp(Source).Soak;
  end;
  inherited Assign(Source);
end;

*Here's the rest as it concerns this part of my custom component*

type
  TCustomCNiSeries = class(TComponent)
  private { Private declarations }
..
..
    FRamp:TCNiRamp;             // Ramp settings
..
..
  published
    property Ramp:TCNiRamp read FRamp;

*And in the final component:*
type TCNiSeries=class(TCustomCNiSeries)
    property Ramp;

*Do I need an AssignTo method in my TComponents?*


Mike
0
Mike
6/21/2009 10:29:45 PM
<Mike Meier> wrote in message news:129726@forums.codegear.com...

> type TCNiRampSoak = class(TPersistent)

You said you were having problems using inner Components.  TPeristent is not 
a TComponent descendant.

>  protected
>    procedure Assign(Source: TPersistent); override;

Assign() has to be public, not protected.

>    property ComPort:TComPort read FComPort;
>    property TCPPort:TIdTCPClient read FTCPPort;
>    property Output1:TCNiOutput1 read FOutput1;
>    property Output2:TCNiOutput2 read FOutput2;
>    property Ramp:TCNiRamp read FRamp;
>    property Comm:TCNiComm read FComm;

Published properties need to be declared as read/write.  Give all of those 
properties setter methods that call Assign() internally.

-- 
Remy Lebeau (TeamB)
0
Remy
6/22/2009 6:33:08 PM
"Chris Rolliston" <spam@gmail.com> wrote in message 
news:130048@forums.codegear.com...

> Also, don't forget to set each sub-component's Name property
> to something sensible, typically the name of the propery it
> provides the value for.

Sub-components do not need to be named.

-- 
Remy Lebeau (TeamB)
0
Remy
6/22/2009 6:33:36 PM
<Mike Meier> wrote in message news:130125@forums.codegear.com...

> A little more code.  Could be that I'm not handling the assign issue 
> correctly

Do not call the inherited Assign() for types you recognize, unless you know 
for a fact that the base class has also overriden Assign() (or AssignTo()) 
for those same types.  Otherwise, you will get a runtime error when 
TPersistent.Assign() is called.

> *Oops, here's something. I was passing a TPersistent in a 
> TComponent.Assign
> method.*

Yes, because that is how Assign() is declared in TPersistent.  All 
descendants must have the same signature.  There is no Assign() that takes a 
TComponent parameter.

> *Do I need an AssignTo method in my TComponents?*

Usually, if you have overriden Assign(), then you do not need to override 
AssignTo(), and vice versa.  Assign() and AssignTo() have different 
purposes.

-- 
Remy Lebeau (TeamB)
0
Remy
6/22/2009 6:37:17 PM
> > Also, don't forget to set each sub-component's Name property
> > to something sensible, typically the name of the propery it
> > provides the value for.
> 
> Sub-components do not need to be named.

If you mean 'sub-components still work if they aren't named' you are
correct, but they look a bit odd in the object inspector if they aren't
- see attachments.

-- 
Chris Rolliston
http://delphihaven.wordpress.com/
0
Chris
6/22/2009 9:06:34 PM
I see now that by 'sub-components', the OP didn't actually mean
sub-components in the sense of properties with types descending from
TComponent, so the 'you should indeed name sub-components' point is a
bit academic for the thread, but anyhow, it still stands...

-- 
Chris Rolliston
http://delphihaven.wordpress.com/
0
Chris
6/22/2009 9:10:31 PM
Reply:

Similar Artilces:

.net component to Delphi component ?
Hello, Is there a way to use .net component inside Delphi ? Thanks On Tue, 18 Nov 2008 13:16:37 -0800, isaac sam wrote: > Is there a way to use .net component inside Delphi ? http://www.managed-vcl.com/ has some libraries for this. -- Marc Rohloff [TeamB] marc -at- marc rohloff -dot- com Marc Rohloff wrote: > On Tue, 18 Nov 2008 13:16:37 -0800, isaac sam wrote: > >> Is there a way to use .net component inside Delphi ? > > http://www.managed-vcl.com/ has some libraries for this. > I was hoping for a free tool but thanks On Tue, 18 Nov 2008...

Component to host VCL component
In the old days, when FireMonkey was still VGScene, we had a nice component that would host any good old VCL component. Very practical. How is this achieved with FireMonkey? I'm not interested in any cross-platform stuff, just want to use it on Windows. ...

ANN: Bricksoft IM VCL Component v8.2 released. All components support Delphi 2009!
All components support Delphi 2009! Please download the trial version(http://www.imcomponents.com/bsimtrial.zip) if you like. -- Bricksoft Support Bricksoft IM(MSN+YAHOO+AIM+ICQ+Jabber/GTalk) SDK For NET/VCL/COM/SOAP - http://www.imcomponents.com/ "Jianmin Wu" <nospam@nospam.com> wrote in message news:72535@forums.codegear.com... > All components support Delphi 2009! with D2009 support, do you still require TNT controls for unicode ? Also do you have any plans to support emoticons ? Regards, Danny Component and demo for D2009 don't need TNT cont...

Components calling other components
Hi, I have a Java component that calls methods on other Java components inside Jaguar (2.0 on NT). To do that I had to insert the Jaguar iiop address in the calling component code. Is there any other way to do that? Maybe some function that gets the current environment (Name Server)? thanks Eduardo Kamada On intercomponent calls, and you can see SVU for an example. You dont need to create a Manager and Session for an intercomponent call, as the in process orb can verify user credentials that were passed to the root component. The intercomponent call would look like ...

problem with a component that has other components
Hi ! I am writing a component that has multiple elements inside (edit, buttons etc). I started with TWinControl and then created inside TEdit and other elements. The problem: when window below my component is updated, the Edit does not repaint (looks transparent). Apparently I violate the paint message propagation ... Please help me! Also let me know if there are better ways to make such a control. Boris <Boris Epel> wrote in message news:310889@forums.embarcadero.com... > I started with TWinControl Consider deriving your main component from TPanel or TFrame or some other...

Delphi XE6 How to link FastReport components to FireDAC components?
Hi to all. I'm wondering on how to link FastReport componets to FireDAC components. A Delphi XE article "Creating Reports with FastReport (FireDAC)" tells about some misterious component called "TfrxComponents" that is used to do de job but I can't find it nowhere. FastReport demos uses ADOTables and ADOQuerys but no FDQueys neither FDTables. Is there any source code example for doing this? I'll appreciate any link than can help me to best understand my trouble. Regards, Hernando. Please, contact FastReports company regarding FireDAC / FastRepor...

Component to component method call passing a component reference.
From all investigation this seems like something I should be able to do, but.... I have a stateless component named "n_manager" that through createinstance() gets references to three stateful components named "n_comtest1", "n_comtest2", and "n_comtester". I then wish to call a method on the instance of "n_comtester" passing the references to "n_comtest1" and "n_comtest2". The IDL generated for the "of_test" function I'm calling is: interface n_comtester : n_combase { string of_test...

How to do a component containing other components
Hello, I try to create a Component from TPanel that contains a tool bar and other components my problem is to access to the tool bar at design time mainly to edit the menu allowing to add a button and after that to access the button itself here's my first version: class PACKAGE TPan_Viewer : public TPanel { private: TToolBar *ToolBar1; TButton* Bout1; protected: public: void __fastcall OnClickButton(TObject *Sender); __fastcall TPan_Viewer(TComponent* Owner); __published: __property TButton* Button={read=Bout1,write=Bout1}; __property TTool...

Delphi XE6 How to link FastReport components to FireDAC components?
Hi to all. I'm wondering on how to link FastReport componets to FireDAC components. A Delphi XE article "Creating Reports with FastReport (FireDAC)" tells about some misterious component called "TfrxComponents" that is used to do de job but I can't find it nowhere. FastReport demos uses ADOTables and ADOQuerys but no FDQueys neither FDTables. Is there any source code example for doing this? I'll appreciate any link than can help me to best understand my trouble. Regards, Hernando. First of all, FastReports has a propensity to uninstall itself. S...

Component toolbar in Delphi XE4 missing tabs and components
I installed my custom components package in the RAD Studio XE4 "personality" (both Delphi and C++Builder). It seemed to work fine and I could create a VCL test app for both Delphi and C++Builder with one of the components dropped on a form. But now I am investigating this further and I find that a lot of components are missing.. :-( I managed to get the components displayed as a tabbed ribbon across the top similar to in Delphi7 by going to View/Toolbars/Components. Then I could also drag it to a place on the screen where it could use the full width of the IDE. I then...

Database Query and other components inside complex Delphi component
Hi! I am trying to develop Delphi DB component for displaying and editing customer data. Many tables (like, carts) in my database references customer using foreign key (like carts.fk_customer) and users want to see a lot of data about customer in diferent forms. So - I am planning to make the component (apparently - derived from TPanel) with the usual properties - DataSource, DataField (for FK_CUSTOMER) and this component should process the changes of its data field (usually fk_customer) by reading addional d ata from the query (component has DataSource property, so, this is possible to fi...

How to uninstall a VCL Component in Delphi 2007?
Guys How do I uninstall a VCL Component in Delphi 2007? Mark Moss Nevermind I figured out how to do it. Mark Moss "Mark Moss" <markemoss@comcast.net> wrote in message news:245205@forums.embarcadero.com... > Guys > > > How do I uninstall a VCL Component in Delphi 2007? > > > Mark Moss ...

MAC OS-style VCL components for Delphi?
Hi all, I saw an application that I am interested in porting from C to Delphi (http://thirdcog.eu/apps/cfxr) and found it comes with a win32 version, using IMHO yucky controls, and a nice shiny native MAC version (Coca, etc). I really like the look, of the Mac port...I was wondering if there are any VCL controls (preferably free) that can make nice buttons, sliders, etc. like in that MAC screenshot? I'm not worried if they don't operate exactly like MAC ones, I mainly like the look :) I have tried googling but no luck so far :( cheers, Paul www.alphaskins...

skin component for VCL.NET Delphi 2007 ?
I'm trying to find out a component which skin forms automatically. It needs to be VCL.Net component for Delphi 2007. I tried to find one on the web with no success. There are many for VCL but not for VCL.Net. Thanks, Rumen ...

Web resources about - Components in Components - public.delphi.vcl.writing

Component - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

AirAsia disaster: Indonesia cites faulty component, crew response in crash
Pilots appear to have reset the computer system's circuit breaker, leading to a series of failures that caused them to lose control of the plane ...

Samsung announces big profits for Q3 2015, driven by components business
... So beneficial was the weakened won that it translated to quarterly gains of approximately 800 billion won ($705 million), primarily from component ...

Teardown of iPad Pro reveals revamped component layout
... Apple device teardown on the iPad Pro on Wednesday, revealing a reworked internal design dominated by massive batteries and bespoke audio components. ...

Corvette Stingray gets optional Z06 components
Filed under: Chevrolet , Coupe , Performance Chevrolet announces a series of upgrades available for the Corvette Stingray derived from the equipment ...

Samsung reportedly lost key iPhone 7 component business
... for Samsung , which is ironic considering the two companies are fierce rivals in the mobile business. The Korean giant produces various components ...

Crew, faulty component caused AirAsia crash
Indonesian investigators said crew action and a faulty component caused the AirAsia jet crash in the Java Sea last year, killing 162 passengers. ...

IDG Contributor Network: Four critical patches for November Patch Tuesday update core Windows and Office ...
Microsoft's November Patch Tuesday brings us four critical updates and eight important patches that attempt to resolve 54 reported vulnerabilities ...

Immigration Law Enforcement: A Vital Component Of National Security And Counterterrorism
While the administration claims that these refugees are being vetted, there is no way to actually screen these people

Taiwan panel makers calling on China government for component tariff reductions
Panel makers in Taiwan are calling on the China government to allow for zero tariffs on panel components due to Taiwan's weakening panel supply ...

Resources last updated: 12/15/2015 7:10:23 AM