为何OldCreateOrder属性持续自动恢复为True?
OldCreateOrder keep resetting to True in my inherited Delphi service class? Let me break down what's happening here and how to fix it:
The Root Cause
When you use the inherited keyword in your subclass's DFM file (like inherited GuardianService: TGuardianService), Delphi's Form/Component Editor has a quirk with published properties that aren't explicitly overridden in the child DFM.
OldCreateOrder is a property of TComponent with a default value of True. Even though your parent class sets it to False, the editor doesn't automatically inherit this value in the child unless you explicitly declare it in the subclass's DFM. When you open the unit, the editor checks for missing published properties and fills in the default value (True) automatically, overriding the implicit inheritance you might expect.
How to Fix It
You need to explicitly add the OldCreateOrder = False line to your subclass's DFM file, right alongside your DisplayName override:
inherited GuardianService: TGuardianService OldCreateOrder = False DisplayName = 'Guardian' end
Once you add this explicit declaration, the editor will respect the value and stop resetting it to True when you open the unit.
If you're still seeing issues (common in older Delphi versions like Delphi 7), try editing the DFM file directly with a plain text editor, saving it, then reloading your project. This bypasses any editor-specific caching that might be causing the problem.
内容的提问来源于stack exchange,提问作者vostock

