Skip to content

FoxPro subclasses without INIT now forward CREATEOBJECT() args to parent#1988

Merged
RobertvanderHulst merged 1 commit into
devfrom
fix/vfp-subclass-init-inheritance
Jun 12, 2026
Merged

FoxPro subclasses without INIT now forward CREATEOBJECT() args to parent#1988
RobertvanderHulst merged 1 commit into
devfrom
fix/vfp-subclass-init-inheritance

Conversation

@Irwin1985

Copy link
Copy Markdown
Contributor

In VFP9, when a subclass does not define its own Init, the engine automatically calls the parent class's Init with all the arguments passes to CREATEOBJECT(). This is one of the most basic OOP patterns in FoxPro:

loDog = createobject("Dog", "Rex")
? loDog._name
return

define class Animal as Custom
    _name = ""
    procedure Init(tcName)
        this._name = tcName
    endproc
enddefine

define class Dog as Animal
    && no Init defined
enddefine

In XSharp, createConstructor (XSharpTreeTransformationFox.cs) only generated a constructor for a Fox class when that class itself defined Init (or AddObject / an existing ctor). Then a subclass had none of these, no constructor was generated at all, so .NET emitted a defalt parameterless constructor calling base(). Any arguments passed to CREATEOBJECT() where silently dropped, the parent's Init ran with NIL parameters, and properties initialized from those parameters stayed NIL, causing runtime errors.

@RobertvanderHulst RobertvanderHulst merged commit 02b19ff into dev Jun 12, 2026
1 check passed
@RobertvanderHulst RobertvanderHulst deleted the fix/vfp-subclass-init-inheritance branch June 12, 2026 08:36
RobertvanderHulst added a commit that referenced this pull request Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants