Jump to content
dormky

Visually edit a custom component

Recommended Posts

Posted (edited)

Hello,

 

I have a series of 4 numbers describing current atmospheric conditions, currently shown in a TGroupBox with each number in a TEdit.

I'd like to encapsulate the behavior related to these numbers (color changes) into a component so I can re-use it in multiple places.

I've created a new component based on TGroupBox, but when opening it there's no Design tab, and I don't want to use code to describe the UI as this runs opposite to what is generally done in Delphi (where you use a graphic UI editor). How can I get my custom TGroupBox component in a Design tab so I can edit it (with a .dfm) ?

Edited by dormky

Share this post


Link to post

You may want to look at frames.  https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Working_with_Frames

Different functionality and usage than creating a real component but may be what you are looking for.  I have never used frames myself, but have several custom components to combine TEdit's, TComboBox's and TButton's into a TPanel that are added to a TScrollbox on the fly with different data in each.

Share this post


Link to post

You cannot, subcomponents in a custom component are created in an overridden constructor. But there is an alternative: Create a new frame in the designer and place groupbox and edits on it. Save the frame unit (after changing the Name property of the frame to something descriptive), best into a folder where you stash code units you want to reuse in other projects. To use the frame in another project just add its unit to the project.

A frame behaves much like a component, you can drop multiple instances of it on forms, panels or other containers. But it can also hold code like a form, in event handlers or methods, and this code is shared between all frame instances. You can modify properties of the controls on the frame in the designer for each instance separately.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×