Skip to content

Commit fd2dbea

Browse files
Merge Changes from Irwin. Correct changed case of keywords.
Merged some changes from Robert too
1 parent a7fbef9 commit fd2dbea

File tree

15 files changed

+998
-973
lines changed

15 files changed

+998
-973
lines changed

src/Runtime/MacroCompiler/MacroCompiler.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<RunCodeAnalysis>false</RunCodeAnalysis>
3737
<SignAssembly>true</SignAssembly>
3838
<DelaySign>false</DelaySign>
39-
<NoWarn>1591</NoWarn>
39+
<NoWarn>1591</NoWarn>
4040
</PropertyGroup>
4141
<ItemGroup>
4242
<Compile Include="..\..\Common\CommonAssemblyInfo.cs">

src/Runtime/XSharp.Core/State/EnumSet.prg

Lines changed: 514 additions & 516 deletions
Large diffs are not rendered by default.

src/Runtime/XSharp.Core/State/Set.prg

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ FUNCTION SetAmPm() AS LOGIC
2424

2525
/// <include file="VoFunctionDocs.xml" path="Runtimefunctions/setampm/*" />
2626
FUNCTION SetAmPm(lNewSetting AS LOGIC) AS LOGIC
27-
SETSTATE LOGIC Set.AmPm lNewSetting
27+
LOCAL lOld AS LOGIC
28+
lOld := RuntimeState.GetValue<LOGIC>(Set.AmPm)
29+
XSharp.RuntimeState.SetValue<LOGIC>(Set.AmPm, lNewSetting)
30+
RuntimeState.SetValue<LONG>(Set.Hours, IIF(lNewSetting, 12, 24))
31+
return lOld
32+
2833

2934
/// <include file="VoFunctionDocs.xml" path="Runtimefunctions/setansi/*" />
3035
FUNCTION SetAnsi() AS LOGIC
@@ -154,19 +159,19 @@ FUNCTION SetDefault(cPathSpec AS STRING) AS STRING
154159
SetPathArray(NULL)
155160
IF XSharp.RuntimeState.Dialect == XSharpDialect.FoxPro
156161
VAR cTemp := cPathSpec:Trim()
157-
IF !String.IsNullOrEmpty(cTemp)
162+
if !String.IsNullOrEmpty(cTemp)
158163
IF cTemp:EndsWith(System.IO.Path.DirectorySeparatorChar:ToString())
159164
cTemp := cTemp:Substring(0, cTemp:Length-1)
160165
ENDIF
161166
IF ! System.IO.Directory.Exists(cTemp)
162-
VAR err := Error.VOError(EG_ARG, __FUNCTION__, nameof(cPathSpec),1, <OBJECT>{cPathSpec})
167+
var err := Error.VOError(EG_ARG, __FUNCTION__, nameof(cPathSpec),1, <OBJECT>{cPathSpec})
163168
err:Description := "Directory not found: '"+cPathSpec+"'"
164169
THROW err
165170
ENDIF
166-
ENDIF
171+
endif
167172
ELSEIF XSharp.RuntimeState.Dialect == XSharpDialect.VO .or. XSharp.RuntimeState.Dialect == XSharpDialect.Vulcan
168173
IF cPathSpec:Length > 0
169-
VAR cLast := cPathSpec[cPathSpec:Length-1]
174+
var cLast := cPathSpec[cPathSpec:Length-1]
170175
SWITCH cLast
171176
CASE c':'
172177
CASE c'\\'
@@ -601,8 +606,12 @@ FUNCTION SetHours() AS LONG
601606

602607
/// <include file="VoFunctionDocs.xml" path="Runtimefunctions/sethours/*" />
603608
FUNCTION SetHours(tnHours AS LONG) AS LONG
604-
LOCAL nOld := RuntimeState.GetValue<LONG>(Set.Hours) AS LONG
605-
RuntimeState.SetValue<LONG>(Set.Hours, tnHours)
609+
LOCAL nOld := RuntimeState.GetValue<LONG>(Set.Hours) AS LONG
610+
IF tnHours != 12 .AND. tnHours != 24
611+
THROW Error.ArgumentError(__ENTITY__, NAMEOF(tnHours), "Invalid hours setting: "+tnHours:ToString())
612+
ENDIF
613+
RuntimeState.SetValue<LONG>(Set.Hours, tnHours)
614+
RuntimeState.SetValue<LOGIC>(Set.AmPm, tnHours == 12)
606615
RETURN nOld
607616

608617
/// <summary>Get/Set seconds display</summary>

src/Runtime/XSharp.Core/State/State.prg

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,13 @@ CLASS XSharp.RuntimeState
767767
IF format:EndsWith("TT")
768768
SELF:_SetThreadValue(Set.AmExt, "AM")
769769
SELF:_SetThreadValue(Set.PmExt, "PM")
770-
SELF:_SetThreadValue(Set.AmPm, TRUE)
770+
SELF:_SetThreadValue(Set.AmPm, TRUE)
771+
SELF:_SetThreadValue(Set.Hours, 12L)
771772
ELSE
772773
SELF:_SetThreadValue(Set.AmExt, "")
773774
SELF:_SetThreadValue(Set.PmExt, "")
774-
SELF:_SetThreadValue(Set.AmPm, FALSE)
775+
SELF:_SetThreadValue(Set.AmPm, FALSE)
776+
SELF:_SetThreadValue(Set.Hours, 24L)
775777
ENDIF
776778
SELF:_SetThreadValue(Set.Timesep, Asc(SubStr3(format, 3,1)))
777779
SELF:_SetThreadValue(Set.Timeformat, format)
@@ -821,8 +823,10 @@ CLASS XSharp.RuntimeState
821823
SELF:_SetThreadValue(Set.Timesep, (DWORD) 0)
822824
ELSE
823825
SELF:_SetThreadValue(Set.Timesep, (DWORD) separator[0])
824-
ENDIF
825-
SELF:_SetThreadValue(Set.AmPm, dtInfo:ShortDatePattern:IndexOf("tt") != -1)
826+
ENDIF
827+
Var lAmPm := dtInfo:ShortDatePattern:IndexOf("tt") != -1
828+
SELF:_SetThreadValue(Set.AmPm, lAmPm)
829+
SELF:_SetThreadValue(Set.Hours, iif(lAmPm, 12L, 24L))
826830
SELF:_SetThreadValue(Set.Timeformat, dtInfo:LongTimePattern)
827831

828832
INTERNAL METHOD _SetDateFormatSystem() AS VOID

src/Runtime/XSharp.VFP.Tests/DateTests.prg

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
// Licensed under the Apache License, Version 2.0.
44
// See License.txt in the project root for license information.
55
//
6-
using System
7-
using System.Collections.Generic
8-
using System.Linq
9-
using System.Text
10-
using XUnit
6+
USING System
7+
USING System.Collections.Generic
8+
USING System.Linq
9+
USING System.Text
10+
USING XUnit
1111

1212

1313
// Array tests are not working correctly yet with the current build
14-
begin namespace XSharp.VFP.Tests
14+
BEGIN NAMESPACE XSharp.VFP.Tests
1515

16-
class DateTests
17-
static constructor
16+
CLASS DateTests
17+
STATIC CONSTRUCTOR
1818
XSharp.RuntimeState.Dialect := XSharpDialect.FoxPro
1919

2020
[Fact, Trait("Category", "Date and Time")];
21-
method ConversionTests() as void
22-
local d as date
23-
local dt as DateTime
21+
METHOD ConversionTests() AS VOID
22+
LOCAL d AS DATE
23+
LOCAL dt AS DateTime
2424
dt := DateTime{2020,1,1,11,12,13}
2525

2626
Assert.Equal(11, Hour(dt))
@@ -33,7 +33,7 @@ begin namespace XSharp.VFP.Tests
3333

3434

3535
[Fact, Trait("Category", "Date and Time")];
36-
method QuarterTests() as void
36+
METHOD QuarterTests() AS VOID
3737
Assert.Equal( Quarter ( ConDate ( 2020, 1 , 1 ) ) , 1 )
3838
Assert.Equal( Quarter ( ConDate ( 2020, 2 , 1 ) ) , 1 )
3939
Assert.Equal( Quarter ( ConDate ( 2020, 3 , 1 ) ) , 1 )
@@ -88,7 +88,7 @@ begin namespace XSharp.VFP.Tests
8888
Assert.Equal( Quarter ( 2020.04.20 ) , 2 )
8989

9090
[Fact, Trait("Category", "Date and Time")];
91-
method GoMonthTests() as void
91+
METHOD GoMonthTests() AS VOID
9292

9393
Assert.Equal(GoMonth ( NULL_DATE , -12 ) , NULL_DATE)
9494
Assert.Equal(GoMonth ( DateTime{} , -12 ) , NULL_DATE)
@@ -100,7 +100,7 @@ begin namespace XSharp.VFP.Tests
100100
Assert.Equal(GoMonth({^1998-12-31}, -2) , ConDate ( 1998 , 10 , 31 ) )
101101

102102
[Fact, Trait("Category", "Date and Time")];
103-
method WeekTests() as void
103+
METHOD WeekTests() AS VOID
104104
Assert.Equal(Week(1998.02.16) , 8)
105105
Assert.Equal(Week(1998.02.16,1,1) , 8)
106106
Assert.Equal(Week(2010.01.03,2,4) , 1)
@@ -113,7 +113,8 @@ begin namespace XSharp.VFP.Tests
113113
// ---------------------------------------------------------------- //
114114
[Fact, Trait("Category", "Date and Time")];
115115
method TToCTests as void
116-
local dt as DateTime
116+
local dt as DateTime
117+
SetHours(12) // set 12 hours format for time tests
117118
dt := DateTime{2025, 8, 13, 14, 30, 45}
118119

119120
// 0 - numeric format (same as param 1)
@@ -186,6 +187,7 @@ begin namespace XSharp.VFP.Tests
186187
[Fact, Trait("Category", "Date and Time")];
187188
method TToCEdgeCasesTests as void
188189
// midnight
190+
SetHours(12)
189191
local midnight := DateTime{2025, 8, 13, 0, 0, 0} as DateTime
190192
Assert.Equal("12:00:00 AM", TToC(midnight, 2))
191193

@@ -274,7 +276,7 @@ begin namespace XSharp.VFP.Tests
274276
method TToCDateOnlyTests as void
275277
// try DATE no time
276278
local d := DateTime{2025, 8, 13} as DateTime
277-
279+
SetHours(12)
278280
// numeric format with date and no time
279281
local numericResult := TToC(d, 1) as string
280282
Assert.True(numericResult:StartsWith("20250813"))

src/Runtime/XSharp.VFP.UI/XSharp/VFPProperties.xh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
METHOD RemoveProperty(cPropertyName AS STRING) AS LOGIC
5151
RETURN SELF:_RemoveProperty(cPropertyName)
5252

53+
METHOD HasProperty(cPropertyName AS STRING) AS LOGIC
54+
RETURN _Properties:HasProperty(cPropertyName)
5355
#endregion
5456

5557

src/Runtime/XSharp.VFP/ClassFunctions.prg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ function RemoveProperty( oObjectName as object, cPropertyName as string) as logi
2323
ENDIF
2424
RETURN TRUE
2525

26+
27+
/// <include file="VFPRuntimeDocs.xml" path="Runtimefunctions/getpem/*" />
28+
FUNCTION GETPEM( uObject as USUAL, cProperty as STRING) as USUAL
29+
if uObject is string var strObject
30+
return NIL
31+
endif
32+
return IVarGet(uObject, cProperty)
33+

src/Runtime/XSharp.VFP/Classes/Custom.prg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ begin namespace XSharp.VFP
4949

5050
#region Nested Items
5151

52-
method AddObject(cName as string , oObject as object) as logic
52+
method AddObject(cName as string , cClassName as string, cOleClass := "" as string, aInitParams PARAMS USUAL[]) as logic
53+
local oObject as Object
54+
oObject := CreateInstance(cClassName, aInitParams)
55+
if ! SELF:Properties:HasProperty(cName)
56+
self:_AddProperty(cName, oObject, PropertyVisibility.Public, "")
57+
endif
5358
self:NoIvarPut(cName, oObject)
5459
self:_Controls:Add(oObject, cName)
5560
return true

src/Runtime/XSharp.VFP/Classes/PropertyContainer.prg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ class XSharp.VFP.PropertyContainer IMPLEMENTS IEnumerable<NameValuePair>
201201
method IEnumerable.GetEnumerator() AS IEnumerator
202202
var props := SELF:GetProperties()
203203
return props:GetEnumerator()
204+
method HasProperty(cPropertyName as string) as logic
205+
return _Properties:ContainsKey(cPropertyName)
204206
end class
205207

206208
public class XSharp.VFP.PropertyDescriptor

0 commit comments

Comments
 (0)