Skip to content

Commit 39509b8

Browse files
authored
Merge branch 'dev' into add_interface_support
2 parents 0a8f25f + 015b43a commit 39509b8

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "thirdparty/DUnitX"]
2+
path = thirdparty/DUnitX
3+
url = git@github.com:VSoftTechnologies/DUnitX.git

Sempare.Template.Tester.dproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
4646
<Icon_MainIcon>$(BDS)\bin\delphi_PROJECTICON.ico</Icon_MainIcon>
4747
<Icns_MainIcns>$(BDS)\bin\delphi_PROJECTICNS.icns</Icns_MainIcns>
48-
<DCC_UnitSearchPath>$(DUnitX);src;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
48+
<DCC_UnitSearchPath>thirdparty\DUnitX\Source;$(DUnitX);src;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
4949
<SanitizedProjectName>Sempare_Template_Tester</SanitizedProjectName>
5050
</PropertyGroup>
5151
<PropertyGroup Condition="'$(Base_Win32)'!=''">
52-
<DCC_UsePackage>DBXSqliteDriver;RESTComponents;vclFireDAC;tethering;FireDACADSDriver;vcltouch;vcldb;bindcompfmx;inetdb;fmx;FireDACIBDriver;fmxdae;vquery260;dacvcl260;dbexpress;vclx;dsnap;FireDACCommon;RESTBackendComponents;VCLRESTComponents;soapserver;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACMySQLDriver;FireDACCommonDriver;inet;bindcompdbx;vcl;ADODataProvider;dsnapcon;FireDACDataProvider;FireDACMSAccDriver;vclimg;FireDAC;DBXDataProvider;FireDACSqliteDriver;FireDACPgDriver;crcontrols260;soaprtl;DbxCommonDriver;xmlrtl;soapmidas;fmxobj;vclwinx;dac260;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;DOSCommandDR;bindcomp;appanalytics;bindcompvcl;dbxcds;adortl;dsnapxml;dbrtl;inetdbxpress;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
52+
<DCC_UsePackage>$(DCC_UsePackage)</DCC_UsePackage>
5353
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
5454
<BT_BuildType>Debug</BT_BuildType>
5555
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.5.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=ltd.sempare.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.5.0.0;Comments=</VerInfo_Keys>

src/Sempare.Template.Evaluate.pas

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ procedure TEvaluationTemplateVisitor.Visit(const AStmt: IForInStmt);
523523
RaiseErrorRes(AStmt, @SValueIsNotEnumerable);
524524
LEnumObj := LEnumValue.AsObject;
525525
try
526-
LLoopExprType := FContext.RttiContext.GetType(LEnumObj.ClassType);
526+
LLoopExprType := FContext.RttiContext().GetType(LEnumObj.ClassType);
527527
LEnumMoveNextMethod := LLoopExprType.GetMethod('MoveNext');
528528
LEnumCurrentProperty := LLoopExprType.getProperty('Current');
529529
LRaiseIfMissing := eoRaiseErrorWhenVariableNotFound in FContext.Options;
@@ -662,7 +662,7 @@ procedure TEvaluationTemplateVisitor.Visit(const AStmt: IForInStmt);
662662
try
663663
if not LLoopExpr.IsEmpty then
664664
begin
665-
LLoopExprType := FContext.RttiContext.GetType(LLoopExpr.TypeInfo);
665+
LLoopExprType := FContext.RttiContext().GetType(LLoopExpr.TypeInfo);
666666

667667
case LLoopExprType.TypeKind of
668668
tkInterface:
@@ -1114,7 +1114,8 @@ function TEvaluationTemplateVisitor.Invoke(const AExpr: IMethodCallExpr; const A
11141114
LMethod: TRttiMethod;
11151115
LIntf: IInterface;
11161116
begin
1117-
LObjType := FContext.RttiContext.GetType(AObject.TypeInfo);
1117+
LObjType := FContext.RttiContext().GetType(AObject.TypeInfo);
1118+
LMethod := LObjType.GetMethod(AExpr.Method);
11181119
LObject := AObject;
11191120
if LObject.Kind = tkInterface then
11201121
begin
@@ -1208,7 +1209,7 @@ procedure TEvaluationTemplateVisitor.Visit(const AStmt: IRequireStmt);
12081209
begin
12091210
if HasBreakOrContinue then
12101211
exit;
1211-
LInputType := FContext.RttiContext.GetType(FStackFrames.peek['_'].TypeInfo).Name.ToLower;
1212+
LInputType := FContext.RttiContext().GetType(FStackFrames.peek['_'].TypeInfo).Name.ToLower;
12121213
LExprs := ExprListArgs(AStmt.exprlist);
12131214
if length(LExprs) = 0 then
12141215
exit;

src/Sempare.Template.Functions.pas

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ procedure TTemplateFunctions.AddFunctions(const AClass: TClass);
139139
LClassType: TRttiType;
140140
LMethod: TRttiMethod;
141141
begin
142-
LClassType := FContext.RttiContext.GetType(AClass);
142+
LClassType := FContext.RttiContext().GetType(AClass);
143143
for LMethod in LClassType.GetMethods do
144144
Add(LMethod);
145145
end;
@@ -385,7 +385,11 @@ class procedure TInternalFuntions.SetVariable(const AStackFrames: TObjectStack<T
385385
begin
386386
if (AStackFrames = nil) or (AStackFrames.count = 0) or (AStackOffset > 0) or (-AStackOffset > AStackFrames.count) then
387387
exit;
388+
{$IFDEF DEFINE SUPPORT_STACK_LIST_PROPERTY}
388389
LStackFrame := AStackFrames.List[AStackFrames.count + AStackOffset];
390+
{$ELSE}
391+
LStackFrame := AStackFrames.ToArray[AStackFrames.count + AStackOffset];
392+
{$ENDIF}
389393
LStackFrame[AVariable] := AValue;
390394
end;
391395

@@ -532,7 +536,7 @@ class function TInternalFuntions.TypeOf(const AContext: ITemplateContext; const
532536
lpos: integer;
533537
begin
534538
try
535-
exit(AContext.RttiContext.GetType(AValue.AsType<TValue>.TypeInfo).QualifiedName);
539+
exit(AContext.RttiContext().GetType(AValue.AsType<TValue>.TypeInfo).QualifiedName);
536540
except
537541
on e: exception do
538542
begin
@@ -702,7 +706,11 @@ class function TInternalFuntions.GetVariable(const AStackFrames: TObjectStack<TS
702706
begin
703707
if (AStackFrames = nil) or (AStackFrames.count = 0) or (AStackOffset > 0) or (-AStackOffset > AStackFrames.count) then
704708
exit;
709+
{$IFDEF DEFINE SUPPORT_STACK_LIST_PROPERTY}
705710
LStackFrame := AStackFrames.List[AStackFrames.count + AStackOffset];
711+
{$ELSE}
712+
LStackFrame := AStackFrames.ToArray[AStackFrames.count + AStackOffset];
713+
{$ENDIF}
706714
exit(LStackFrame[AVariable]);
707715
end;
708716

@@ -829,7 +837,7 @@ class function TInternalFuntions.DomId(const AContext: ITemplateContext; const A
829837
end;
830838
if LIsRecord or LIsObject then
831839
begin
832-
LType := AContext.RttiContext.GetType(AValue.TypeInfo);
840+
LType := AContext.RttiContext().GetType(AValue.TypeInfo);
833841
LField := LType.GetField('id');
834842
LPtr := GetPtr;
835843
if LField <> nil then

src/Sempare.Template.Rtti.pas

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function Contains(const APosition: IPosition; const ALeft, ARight: TValue; const
209209
RaiseError(APosition, SValueIsNotEnumerable);
210210
LEnumObject := LValue.AsObject;
211211
try
212-
TRightType := AContext.RttiContext.GetType(LEnumObject.ClassType);
212+
TRightType := AContext.RttiContext().GetType(LEnumObject.ClassType);
213213
LEnumMoveNextMethod := TRightType.GetMethod('MoveNext');
214214
LEnumCurrentProperty := TRightType.GetProperty('Current');
215215
while LEnumMoveNextMethod.Invoke(LEnumObject, []).AsBoolean do
@@ -300,7 +300,7 @@ function Contains(const APosition: IPosition; const ALeft, ARight: TValue; const
300300
result := false;
301301
if not IsEnumerable(AContext, ARight) and not MatchMap(AContext, ARight) then
302302
RaiseError(APosition, SValueIsNotEnumerableOrMap);
303-
TRightType := AContext.RttiContext.GetType(ARight.TypeInfo);
303+
TRightType := AContext.RttiContext().GetType(ARight.TypeInfo);
304304
case TRightType.TypeKind of
305305
tkInterface:
306306
VisitInterface;
@@ -323,7 +323,7 @@ function IsEnumerable(const AContext: ITemplateContext; const AValue: TValue): b
323323
tkDynArray, tkArray:
324324
exit(true);
325325
tkClass, tkClassRef:
326-
exit(AContext.RttiContext.GetType(AValue.TypeInfo).GetMethod('GetEnumerator') <> nil);
326+
exit(AContext.RttiContext().GetType(AValue.TypeInfo).GetMethod('GetEnumerator') <> nil);
327327
else
328328
exit(false);
329329
end;
@@ -480,7 +480,7 @@ function AsString(const AValue: TValue; const AContext: ITemplateContext): strin
480480
if AValue.TypeInfo = TypeInfo(TValue) then
481481
exit(AsString(AValue.AsType<TValue>(), AContext))
482482
else
483-
exit(AContext.RttiContext.GetType(AValue.TypeInfo).Name);
483+
exit(AContext.RttiContext().GetType(AValue.TypeInfo).Name);
484484
else
485485
exit('');
486486
end;
@@ -515,7 +515,7 @@ function TryDerefTemplateVariables(const APosition: IPosition; const AObj: TValu
515515
begin
516516
// Ideally wuld like to use TryGetItem, but couldn't get it working
517517
// with TValue result...
518-
LObjectType := AContext.RttiContext.GetType(AObj.TypeInfo);
518+
LObjectType := AContext.RttiContext().GetType(AObj.TypeInfo);
519519
LContainsKeyMethod := LObjectType.GetMethod('ContainsKey');
520520
try
521521
if not LContainsKeyMethod.Invoke(AObj, [ADeref]).AsBoolean then
@@ -607,7 +607,7 @@ function TryDerefClass(const APosition: IPosition; const obj: TValue; const ADer
607607
end;
608608
end;
609609
end;
610-
exit(TryGetFieldOrProperty(obj.AsObject, AContext.RttiContext.GetType(obj.TypeInfo), ADeref, AContext, AResult));
610+
exit(TryGetFieldOrProperty(obj.AsObject, AContext.RttiContext().GetType(obj.TypeInfo), ADeref, AContext, AResult));
611611
end;
612612

613613
function TryDerefList(const APosition: IPosition; const AObj: TValue; const ADeref: TValue; const ARaiseIfMissing: boolean; const AContext: ITemplateContext; out AResult: TValue): boolean;
@@ -616,7 +616,7 @@ function TryDerefList(const APosition: IPosition; const AObj: TValue; const ADer
616616
LProperty: TRttiProperty;
617617
LIndexedProperty: TRttiIndexedProperty;
618618
begin
619-
LType := AContext.RttiContext.GetType(AObj.TypeInfo);
619+
LType := AContext.RttiContext().GetType(AObj.TypeInfo);
620620
try
621621
if IsIntLike(ADeref) then
622622
begin
@@ -656,7 +656,7 @@ function TryDerefDictionary(const APosition: IPosition; const AObj: TValue; cons
656656
LIndexedProperty: TRttiIndexedProperty;
657657
LDerefValue: TValue;
658658
begin
659-
LType := AContext.RttiContext.GetType(AObj.TypeInfo);
659+
LType := AContext.RttiContext().GetType(AObj.TypeInfo);
660660
try
661661
if IsStrLike(ADeref) then
662662
begin
@@ -868,7 +868,7 @@ function TryDeref(const APosition: IPosition; const AVar, ADeref: TValue; const
868868
LMax: int64;
869869
begin
870870
LIndex := AsInt(ADeref, AContext);
871-
LElementType := AContext.RttiContext.GetType(AObj.TypeInfo) as TRttiArrayType;
871+
LElementType := AContext.RttiContext().GetType(AObj.TypeInfo) as TRttiArrayType;
872872
LArrayDimType := LElementType.Dimensions[0];
873873
LMin := 0;
874874
if LArrayDimType <> nil then
@@ -908,7 +908,7 @@ function TryDeref(const APosition: IPosition; const AVar, ADeref: TValue; const
908908
exit(true);
909909
end;
910910

911-
exit(TryGetFieldOrProperty(LObj.GetReferenceToRawData, AContext.RttiContext.GetType(AObj.TypeInfo), ADeref, AContext, AResult));
911+
exit(TryGetFieldOrProperty(LObj.GetReferenceToRawData, AContext.RttiContext().GetType(AObj.TypeInfo), ADeref, AContext, AResult));
912912
end;
913913

914914
function TryDerefInterface(const AObj: TValue; const ADeref: TValue; out AResult: TValue): boolean;
@@ -1053,7 +1053,9 @@ function MatchJsonValue(const AContext: ITemplateContext; const ATypeInfo: PType
10531053
(ATypeInfo = TypeInfo(TJSONNull)) or //
10541054
(ATypeInfo = TypeInfo(TJSONNumber)) or //
10551055
(ATypeInfo = TypeInfo(TJSONString)) or //
1056+
{$IFDEF SUPPORT_JSON_BOOL}
10561057
(ATypeInfo = TypeInfo(TJSONBool)) or //
1058+
{$ENDIF}
10571059
(ATypeInfo = TypeInfo(TJSONTrue)) or //
10581060
(ATypeInfo = TypeInfo(TJSONFalse)) //
10591061
);
@@ -1122,7 +1124,7 @@ procedure PopulateStackFrameFromDictionary(const AContext: ITemplateContext; con
11221124
LMethod := ARttiType.GetMethod('GetEnumerator');
11231125
LEnumObject := LMethod.Invoke(LDictionary, []).AsObject;
11241126
try
1125-
LEnumType := AContext.RttiContext.GetType(LEnumObject.ClassType);
1127+
LEnumType := AContext.RttiContext().GetType(LEnumObject.ClassType);
11261128
LEnumMoveNextMethod := LEnumType.GetMethod('MoveNext');
11271129
LEnumCurrentProperty := LEnumType.GetProperty('Current');
11281130
LPairKeyField := nil;
@@ -1133,7 +1135,7 @@ procedure PopulateStackFrameFromDictionary(const AContext: ITemplateContext; con
11331135
LPairRecordPtr := LEnumPair.GetReferenceToRawData;
11341136
if LPairKeyField = nil then
11351137
begin
1136-
LEnumType := AContext.RttiContext.GetType(LEnumPair.TypeInfo);
1138+
LEnumType := AContext.RttiContext().GetType(LEnumPair.TypeInfo);
11371139
LPairKeyField := LEnumType.GetField('Key');
11381140
LPairValueField := LEnumType.GetField('Value');
11391141
end;
@@ -1162,7 +1164,7 @@ function IsDataSetEmpty(const AContext: ITemplateContext; const AObject: TObject
11621164
begin
11631165
if AObject = nil then
11641166
exit(true);
1165-
LType := AContext.RttiContext.GetType(AObject.ClassType);
1167+
LType := AContext.RttiContext().GetType(AObject.ClassType);
11661168
LCountProp := LType.GetProperty('RecordCount');
11671169
LCount := LCountProp.GetValue(AObject).AsInteger;
11681170
exit(LCount = 0);
@@ -1174,7 +1176,7 @@ function IsRecordCountEmpty(const AContext: ITemplateContext; const AObject: TVa
11741176
LCount: integer;
11751177
LCountProp: TRttiMethod;
11761178
begin
1177-
LType := AContext.RttiContext.GetType(AObject.TypeInfo);
1179+
LType := AContext.RttiContext().GetType(AObject.TypeInfo);
11781180
LCountProp := LType.GetMethod('GetCount');
11791181
LCount := LCountProp.Invoke(AObject, []).AsInteger;
11801182
exit(LCount = 0);
@@ -1188,7 +1190,7 @@ function IsGenericCollectionEmpty(const AContext: ITemplateContext; const AObjec
11881190
begin
11891191
if AObject = nil then
11901192
exit(true);
1191-
LType := AContext.RttiContext.GetType(AObject.ClassType);
1193+
LType := AContext.RttiContext().GetType(AObject.ClassType);
11921194
LCountProp := LType.GetProperty('Count');
11931195
LCount := LCountProp.GetValue(AObject).AsInteger;
11941196
exit(LCount = 0);

src/Sempare.Template.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ class procedure Template.EvalWithContext(const AContext: ITemplateContext; const
458458
);
459459
try
460460
LConfirmLicense.Position := 0;
461-
AStream.CopyFrom(LConfirmLicense);
461+
AStream.CopyFrom(LConfirmLicense, LConfirmLicense.Size);
462462
finally
463463
LConfirmLicense.Free;
464464
end;

thirdparty/DUnitX

Submodule DUnitX added at d9dca12

0 commit comments

Comments
 (0)