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?
相关问题
- Is there a Delphi 5 component that can handle .png
- How to use Control.FromHandle?
- Is there a way to install Delphi 2010 on Windows 2
- Is TWebBrowser dependant on IE version?
- iOS objective-c object: When to use release and wh
相关文章
- Best way to implement MVVM bindings (View <-> V
- Windows EventLog: How fast are operations with it?
- Difference between SuspendLayout and BeginUpdate
- How to force Delphi compiler to display all hints
- Coloring cell background on firemonkey stringgrid
- HelpInsight documentation in Delphi 2007
- Can RTTI interrogate types from project code at de
- What specifically causes EPrivilege to be raised?
In your form you can override the
ReadState
method 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: TButton
toButton1: MyUnit.TButton
will result in your button being created. Or perhaps the hack was to addMyUnit
to 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.I guess what you're trying to remember is an "interposer class": inheriting a class giving the same name as the ancestor, by prefixing the ancestor's unit name. Since the class name is not changed, the dfm streaming mechanism is not disturbed. Would only affect the unit the class is re-declared in, unless it is put in a separate unit and that unit is included in the uses section after the base class'es. Obviously, you cannot have published properties in an interposed class.