From 8ddbeb04a524f12f6d64214c6940956939bc3aa7 Mon Sep 17 00:00:00 2001 From: Irwin Rodriguez Date: Sun, 5 Jul 2026 19:17:16 +0200 Subject: [PATCH] Implement NEWOBJECT() for basic cases --- src/Runtime/XSharp.VFP.Tests/CommandTests.prg | 18 ++++++++++ src/Runtime/XSharp.VFP/Functions.prg | 36 +++++++++++++++++++ src/Runtime/XSharp.VFP/ToDo-NOP.prg | 7 ---- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/Runtime/XSharp.VFP.Tests/CommandTests.prg b/src/Runtime/XSharp.VFP.Tests/CommandTests.prg index b23d63265d..718a55983e 100644 --- a/src/Runtime/XSharp.VFP.Tests/CommandTests.prg +++ b/src/Runtime/XSharp.VFP.Tests/CommandTests.prg @@ -393,6 +393,24 @@ BEGIN NAMESPACE XSharp.VFP.Tests RELEASE WINDOWS Assert.True(TRUE) END METHOD + + [Fact, Trait("Category", "NewObject")]; + METHOD NewObjectBasicTest AS VOID + VAR o := NEWOBJECT("Custom") + Assert.NotNull(o) + Assert.True(o IS Custom) + END METHOD + + [Fact, Trait("Category", "NewObject")]; + METHOD NewObjectWithEmptyModuleTest AS VOID + VAR o := NEWOBJECT("Custom", "") + Assert.NotNull(o) + END METHOD + + [Fact, Trait("Category", "NewObject")]; + METHOD NewObjectWithModuleThrows AS VOID + Assert.Throws({ => NEWOBJECT("Custom", "algo.vcx") }) + END METHOD END CLASS END NAMESPACE diff --git a/src/Runtime/XSharp.VFP/Functions.prg b/src/Runtime/XSharp.VFP/Functions.prg index 747a74284a..f87d7c968b 100644 --- a/src/Runtime/XSharp.VFP/Functions.prg +++ b/src/Runtime/XSharp.VFP/Functions.prg @@ -13,6 +13,42 @@ FUNCTION CreateObject(cClassName, _args ) AS OBJECT CLIPPER // The pseudo function _ARGS() returns the Clipper arguments array RETURN CreateInstance(_ARGS()) +/// +[FoxProFunction("NEWOBJECT", FoxFunctionCategory.ClassAndObject, FoxEngine.LanguageCore, FoxFunctionStatus.Partial, FoxCriticality.High)]; +FUNCTION NewObject(cClassName, _args) AS OBJECT CLIPPER + VAR nCount := PCount() + + IF nCount >= 2 + VAR uModule := _GetFParam(2) + IF IsString(uModule) .AND. !Empty(uModule) + THROW NotImplementedException{"NEWOBJECT with cModule (.vcx/.app) is not supported"} + ENDIF + ENDIF + + IF nCount >= 3 + VAR uApp := _GetFParam(3) + IF IsString(uApp) .AND. !Empty(uApp) + THROW NotImplementedException{"NEWOBJECT with cInApplication (.vcx/.app) is not supported"} + ENDIF + ENDIF + + // Init params start after cClassName, skipping cModule/cInApp if present + VAR nInitStart := IIF(nCount >= 3, 4, IIF(nCount >= 2, 3, 2)) + VAR nInitCount := nCount - nInitStart + 1 + + IF nInitCount <= 0 + RETURN CreateInstance(cClassName) + ENDIF + + VAR uArgs := USUAL[]{nInitCount + 1} + uArgs[0] := cClassName + FOR VAR i := 1 TO nInitCount + uArgs[i] := _GetFParam(nInitStart + i - 1) + NEXT + + RETURN CreateInstance(uArgs) +END FUNCTION + /// [FoxProFunction("CREATEOBJECTEX", FoxFunctionCategory.ClassAndObject, FoxEngine.Interop, FoxFunctionStatus.Full, FoxCriticality.High)]; FUNCTION CreateObjectEx(cClsIdOrcProgId, cComputerName , cIID ) AS OBJECT CLIPPER diff --git a/src/Runtime/XSharp.VFP/ToDo-NOP.prg b/src/Runtime/XSharp.VFP/ToDo-NOP.prg index 568f492da1..d994298d7e 100644 --- a/src/Runtime/XSharp.VFP/ToDo-NOP.prg +++ b/src/Runtime/XSharp.VFP/ToDo-NOP.prg @@ -7,13 +7,6 @@ #pragma options("vo15", on) -/// -- todo -- -/// -[FoxProFunction("NEWOBJECT", FoxFunctionCategory.ClassAndObject, FoxEngine.LanguageCore, FoxFunctionStatus.Stub, FoxCriticality.High)]; -FUNCTION NewObject( cClassName ,_args) AS OBJECT - THROW NotImplementedException{} - // RETURN NULL_OBJECT - /// -- todo -- /// [FoxProFunction("OLDVAL", FoxFunctionCategory.CursorAndTable, FoxEngine.WorkArea, FoxFunctionStatus.Stub, FoxCriticality.High)];