I know I’ve seen an example somewhere of a hack to define a custom version of an existing VCL component, like TButton or TEdit, with the same class name and do something to make it so that the DFM streamer will instantiate your version instead of the original. Unfortunately, I’m in a situation where I need to be able to do that and I can’t find the write-up. Does anyone know where to find information on how to accomplish this?
I know I’ve seen an example somewhere of a hack to define a custom
Share
In your form you can override the
ReadStatemethod like so:There are likely numerous other ways to do this, but this is how I do it!
EDIT: Inspecting
TReader.GetFieldClass(Instance: TObject; const ClassName: string)suggests the hack that Mason recalls. The first line setsClassType := Instance.ClassType. So I suspect that by changing the declaration in the pas file fromButton1: TButtontoButton1: MyUnit.TButtonwill result in your button being created. Or perhaps the hack was to addMyUnitto the uses clause right at the end so that your version of TButton is the one that is in scope. However, none of this sounds very practical.