Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What base class to use when developing Delphi VCL component?

Tags:

delphi

vcl

If I want to replace a VCL component TXxx should I base my component on TXxx or TCustomXxx?

I am looking to make drop-in replacements for various text-editing components (TEdit, TMemo, etc.) to have WM_PASTE handlers to sanitize inputs to a back-end that is very picky about what it will accept (basically only 7-bit ASCII printable glyphs, spaces, and CR/LF pairs... even tab characters are not acceptable to it). These new components have to go into an existing application, and I want to not do anything I don't absolutely have to in order to make them work exactly the way the old ones did, except for the non-default paste behavior.

I've done one based on TMemo and it seems to work, but somehow or other I have the impression that the recommended approach would be to use TCustomMemo. Is there something I am missing?

like image 460
wades Avatar asked Jun 11 '12 22:06

wades


2 Answers

By convention, the difference between TSomething and TCustomSomething is that the latter has no or very few published properties so that you can pick which ones to publish yourself. Otherwise there should not be any difference.

like image 116
500 - Internal Server Error Avatar answered Nov 05 '22 02:11

500 - Internal Server Error


The way I've always understood the concept of having TSomething and TCustomSomething is when you create your own inheritance of, let's say TButton to your own called TMyBytton. Suppose you want to hide a property, such as Caption (assuming you might not want text). With the TButton, you cannot hide this property. But using a TCustomButton, you can publish which ever properties you want to be visible in the object inspector, and exclude those which you do not want to see. Once a property has been published, it cannot be un-published in further inherited classes.

like image 41
Jerry Dodge Avatar answered Nov 05 '22 02:11

Jerry Dodge