Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Custom Control Inside Same Project



Permlink Replies: 5 - Last Post: Sep 18, 2017 10:50 PM Last Post By: Peter Below
Wanli Ma

Posts: 21
Registered: 12/6/05
Custom Control Inside Same Project
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2017 7:52 PM
Official way for using a custom control is to register it via a package. For a often changed control, it seesm better to keep it in the same project. But the dfm using this control cannot be opened, raising an error like "class not found". There are two ways of bypassing this issue: 1) Create the control dynamically in code. 2) Open the custom control first, then open the form containing it. Neither is convenient. Is there a third way? i.e. self registering inside the same project. Thanks!
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Custom Control Inside Same Project
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 17, 2017 7:36 AM   in response to: Wanli Ma in response to: Wanli Ma
Wanli Ma wrote:

Official way for using a custom control is to register it via a
package. For a often changed control, it seesm better to keep it in
the same project. But the dfm using this control cannot be opened,
raising an error like "class not found". There are two ways of
bypassing this issue: 1) Create the control dynamically in code. 2)
Open the custom control first, then open the form containing it.
Neither is convenient. Is there a third way? i.e. self registering
inside the same project. Thanks!

Unfortunately not, as far as i'm aware. The IDE needs the control to be
registered so it can get a class reference for it from the class name
read from the DFM file. Since no code in your form unit executes at
design-time you cannot handle the registration in code that is part of
the project.


--
Peter Below
TeamB

Wanli Ma

Posts: 21
Registered: 12/6/05
Re: Custom Control Inside Same Project
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 17, 2017 11:14 AM   in response to: Peter Below in response to: Peter Below
Thanks, Peter! If you say it is not possible, then I will believe it is certainly so. It is a nice to have feature though. As when the custom control is opened first, it is Ok, I would assume it is not too difficult at Embarcadero side. Delphi maker is responsible for making common controls, app developers usually make custom controls specific to one project -- hence custom control inside same project is a common use case. Unlike business logic at times it is harder to refactor aggregate controls on the main form into "dynamically" loaded custom control groups due to complicate aligning issue. In some cases I resort to using a base panel at the desired location on the main form to keep the alignment, loading the custom control dynamically with this base as parent. It seems to be a Ok solution.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Custom Control Inside Same Project
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 18, 2017 11:50 AM   in response to: Peter Below in response to: Peter Below
Peter Below wrote:

Unfortunately not, as far as i'm aware. The IDE needs the control to
be registered so it can get a class reference for it from the class
name read from the DFM file.

The DFM streaming system actually has ways of letting user code provide
class references for unknown class names. But I don't think it works
at design-time, only at runtime. Maybe you can make a custom IDE
OpenTools plugin to handle registration at design-time, though.

Since no code in your form unit executes at design-time

That is not true. The Form Designer hosts live objects, and component
code DOES run at design-time (otherwise components wouldn't need to
check their ComponentState property for the csDesigning flag, handle
the CM_DESIGNHITTEST message, etc). But it might be that the actual
Form itself is an IDE-provided stub object and not an instance of the
user's actual Form class, though. But the child controls are certainly
live components.

--
Remy Lebeau (TeamB)
Wanli Ma

Posts: 21
Registered: 12/6/05
Re: Custom Control Inside Same Project
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 18, 2017 7:15 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks, Remy. I do have a way to trick the IDE to take a custom control at design time without component registration. First place a base control of the custom control -- the first base inside TFrame, i.e. a panel, onto the main form at desired location. Then use another text editor open the main form .dfm, change the class from TPanel to TMyCustomControl. Now open the main form, as long as custom control is opened first, IDE is happy, the custom control shows correctly on the main form. It is this "as long as" that is kind of inconvenient. If there are more custom controls, one had to open them all before open the main form. Or else it will raise an error.

Unlike component providers, app developers usually make custom controls, mainly aggregates, only for one specific project. It is a quite common use case. Hopefully gurus will come up with a solution for the RAD.
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Custom Control Inside Same Project
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 18, 2017 10:50 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

That is not true. The Form Designer hosts live objects, and component
code DOES run at design-time (otherwise components wouldn't need to
check their ComponentState property for the csDesigning flag, handle
the CM_DESIGNHITTEST message, etc). But it might be that the actual
Form itself is an IDE-provided stub object and not an instance of the
user's actual Form class, though. But the child controls are
certainly live components.

The components dropped on the form, yes. The form itself is a dummy
container, though.

--
Peter Below
TeamB
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02