Newbie Question: Create a component using other components
Posted on 2004-11-11
I have spent countless hours trying to learn how to create a new component, and am coming up short. I'm sure this question is easy for the experts, but I'm getting frustrated with the lack of answers out there.
I have found several tutorials on creating new components. Many of them mention my problem but never get into details.
I'm creating a component that is a TPanel. Within that Panel there is a edit box and a label. I would like to present to the object inspector only certain properties of the panel, and selected properties of the edit and the label.
I have figured out that if you want to "hide" some of the parameters, then you have to use a "TCustomPanel" and only publish the properties of the panel that I want (however, some of them like top/left/help still remain!?!?). However, I can't for the life of me figure out how to publish the properties of the edit box or the label as properties of the new component.
Ideally, what I would like to do is call the component "MyComponent". Within the object inspector, I would like to see:
"Heading" (string referring to "label.caption")
"Data" (string referring to "editbox.text")
I figured out that when I publish the properties, I can pass the entire object as a property, and I can see it as a sub item in object inspector. When I change the value of it in the object inspector, I can see the values updated in the form, HOWEVER when I run the program, the values are reset to the defaults (only on the sub components!)
TDataField = class (TCustomPanel)
constructor Create(AOwner:TComponent); override;
property Heading: TLabel read fLabel write fLabel;
property Data: TEditBox read fData write fData;
property DataType: String read fDataType write fDataType;
property Digits: Integer read fDigits write fDigits default 0;
property Decimals: Integer read fDecimals write fDecimals default 2;
property Expression: String read fExpression write fExpression;
I create my Label/Editbox in the constructor and give them the default values, but it doesn't appear at runtime the program is passing in the values from the object inspector....but this is only the case with the label/editbox. Values on the object inspector are correctly applied to the parent panel.
There may be something wrong with my constructor statement.
Anyways, any help would be appreciated!