Sfoglia il codice sorgente

* Merging revisions r43654,r43662,r43663,r43664 from trunk:
------------------------------------------------------------------------
r43654 | michael | 2019-12-06 09:53:43 +0100 (Fri, 06 Dec 2019) | 1 line

* Fix bug #0035436
------------------------------------------------------------------------
r43662 | michael | 2019-12-08 21:05:14 +0100 (Sun, 08 Dec 2019) | 1 line

* Fix memleaks (bug ID 36408)
------------------------------------------------------------------------
r43663 | michael | 2019-12-08 21:05:53 +0100 (Sun, 08 Dec 2019) | 1 line

* Fix memleak in comparer, improve date recognition
------------------------------------------------------------------------
r43664 | michael | 2019-12-08 21:11:23 +0100 (Sun, 08 Dec 2019) | 1 line

* Fix lime color (bug ID 0036407)
------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@43666 -

michael 5 anni fa
parent
commit
2b52be98b5

+ 19 - 3
packages/fcl-db/src/json/fpjsondataset.pp

@@ -179,6 +179,7 @@ type
     Function Compare(aRowindex : integer) : Integer;
     Function Compare(aRowindex : integer) : Integer;
   Public
   Public
     Constructor Create(aDataset : TBaseJSONDataset; aFields : String; aValues : Variant; aOptions : TLocateOptions);
     Constructor Create(aDataset : TBaseJSONDataset; aFields : String; aValues : Variant; aOptions : TLocateOptions);
+    Destructor Destroy; override;
     Property Dataset : TBaseJSONDataset Read FDataset;
     Property Dataset : TBaseJSONDataset Read FDataset;
     property Items [Index : Integer] : TFieldComparer Read GetFieldComparer;
     property Items [Index : Integer] : TFieldComparer Read GetFieldComparer;
     Property Options : TLocateOptions Read FOptions Write FOptions;
     Property Options : TLocateOptions Read FOptions Write FOptions;
@@ -408,7 +409,10 @@ var
 
 
 begin
 begin
   S1:=GetFieldValue(Rowindex).AsString;
   S1:=GetFieldValue(Rowindex).AsString;
-  S2:=String(aValue);
+  if varIsNull(aValue) then
+    S2:=''
+  else
+    S2:=String(aValue);
   if loPartialKey in Options then
   if loPartialKey in Options then
     S1:=Copy(S1,1,Length(S2));
     S1:=Copy(S1,1,Length(S2));
   if loCaseInsensitive in options then
   if loCaseInsensitive in options then
@@ -543,6 +547,18 @@ begin
   ConstructItems(aFields);
   ConstructItems(aFields);
 end;
 end;
 
 
+destructor TRecordComparer.Destroy;
+
+Var
+  F : TFieldComparer;
+
+begin
+  For F in Fitems do
+     F.Free;
+  FItems:=Nil;
+  inherited Destroy;
+end;
+
 { TDefaultJSONIndex }
 { TDefaultJSONIndex }
 
 
 
 
@@ -1049,7 +1065,7 @@ begin
   end;
   end;
   If (Ptrn='') then
   If (Ptrn='') then
     Case F.DataType of
     Case F.DataType of
-      ftDate : Result:=StrToDate(S,'y/m/d');
+      ftDate : Result:=StrToDate(S,'y/m/d','-');
       ftTime : Result:=StrToTime(S);
       ftTime : Result:=StrToTime(S);
       ftDateTime : Result:=StrToDateTime(S);
       ftDateTime : Result:=StrToDateTime(S);
     end
     end
@@ -1077,7 +1093,7 @@ begin
   end;
   end;
   If (Ptrn='') then
   If (Ptrn='') then
     Case F.DataType of
     Case F.DataType of
-      ftDate : Result:=DateToStr(DT);
+      ftDate : Result:=FormatDateTime('yyyy/mm/dd',DT);
       ftTime : Result:=TimeToStr(DT);
       ftTime : Result:=TimeToStr(DT);
       ftDateTime : Result:=DateTimeToStr(DT);
       ftDateTime : Result:=DateTimeToStr(DT);
     end
     end

+ 16 - 11
packages/fcl-db/tests/testjsondataset.pp

@@ -1,15 +1,15 @@
-program devds;
+program testjsondataset;
 
 
 {$DEFINE TESTCALCFIELDS}
 {$DEFINE TESTCALCFIELDS}
 {$DEFINE TESTLOOKUPFIELDS}
 {$DEFINE TESTLOOKUPFIELDS}
 
 
-uses variants, varutils, sysutils, db, fpjson , fpjsondataset, ExtJSDataset, types;
+uses classes, variants, varutils, sysutils, db, fpjson , fpjsondataset, ExtJSDataset, types;
 
 
 Type
 Type
 
 
   { TApp }
   { TApp }
 
 
-  TApp = Class(TObject)
+  TApp = Class(TComponent)
   private
   private
     DS : TExtJSJSONObjectDataSet;
     DS : TExtJSJSONObjectDataSet;
     DC : TExtJSJSONObjectDataSet;
     DC : TExtJSJSONObjectDataSet;
@@ -70,7 +70,7 @@ Var
 
 
 begin
 begin
   Writeln('Creating dataset');
   Writeln('Creating dataset');
-  DS:=TExtJSJSONObjectDataSet.Create(Nil);
+  DS:=TExtJSJSONObjectDataSet.Create(Self);
   DS.MetaData:=GetJSON('{ "fields" : [ '+
   DS.MetaData:=GetJSON('{ "fields" : [ '+
                                           ' { "name": "firstname"}, '+
                                           ' { "name": "firstname"}, '+
                                           ' { "name": "lastname"}, '+
                                           ' { "name": "lastname"}, '+
@@ -85,7 +85,7 @@ begin
                                   '  {"firstname" : "Bruno", "lastname" : "Fierens", "children" : 3, "birthday" : "1970-07-09", "business" : true, "weight": 77.3, "country": "BE"  },'+
                                   '  {"firstname" : "Bruno", "lastname" : "Fierens", "children" : 3, "birthday" : "1970-07-09", "business" : true, "weight": 77.3, "country": "BE"  },'+
                                   '  {"firstname" : "Detlef", "lastname" : "Overbeek", "children" : 2, "birthday" : "1950-07-08", "business" : true, "weight": 78.8, "country": "NL"  }'+
                                   '  {"firstname" : "Detlef", "lastname" : "Overbeek", "children" : 2, "birthday" : "1950-07-08", "business" : true, "weight": 78.8, "country": "NL"  }'+
                                   ' ]') as TJSONArray;
                                   ' ]') as TJSONArray;
-  DC:=TExtJSJSONObjectDataSet.Create(Nil);
+  DC:=TExtJSJSONObjectDataSet.Create(Self);
   DC.MetaData:=GetJSON('{ "fields" : [ '+
   DC.MetaData:=GetJSON('{ "fields" : [ '+
                                        ' { "name": "code"}, '+
                                        ' { "name": "code"}, '+
                                        ' { "name": "name"} '+
                                        ' { "name": "name"} '+
@@ -174,7 +174,7 @@ begin
   Writeln('Modified before  (expect False): ',DS.Modified);
   Writeln('Modified before  (expect False): ',DS.Modified);
   DumpRecord(DS);
   DumpRecord(DS);
   DS.FieldByName('firstname').AsString:='Florian';
   DS.FieldByName('firstname').AsString:='Florian';
-  Writeln('Old value of field first name (expect null): ', DS.FieldByName('firstname').OldValue);
+  Writeln('Old value of field first name (expect null): ', varisNull(DS.FieldByName('firstname').OldValue) );
   DS.FieldByName('lastname').AsString:='Klaempfl';
   DS.FieldByName('lastname').AsString:='Klaempfl';
   DS.FieldByName('children').AsInteger:=1;
   DS.FieldByName('children').AsInteger:=1;
   DS.FieldByName('birthday').AsDateTime:=EncodeDate(1980,5,4);
   DS.FieldByName('birthday').AsDateTime:=EncodeDate(1980,5,4);
@@ -288,7 +288,7 @@ begin
   DSS:=Nil;
   DSS:=Nil;
   t:=TDataLink.Create;
   t:=TDataLink.Create;
   try
   try
-    DSS:=TDatasource.Create(Nil);
+    DSS:=TDatasource.Create(self);
     DSS.DataSet:=DS;
     DSS.DataSet:=DS;
     Writeln('Buffercount');
     Writeln('Buffercount');
     t.BufferCount := 10;
     t.BufferCount := 10;
@@ -323,6 +323,7 @@ begin
   DSS:=Nil;
   DSS:=Nil;
   t:=TDataLink.Create;
   t:=TDataLink.Create;
   try
   try
+    DSS:=TDatasource.Create(Self);
     DSS.DataSet:=DS;
     DSS.DataSet:=DS;
     DSS.DataSet:=DS;
     DSS.DataSet:=DS;
     t.DataSource := DSS;
     t.DataSource := DSS;
@@ -421,9 +422,9 @@ begin
 
 
     DC.Open;
     DC.Open;
     DS.Open;
     DS.Open;
-//    TestLocate;
+    TestLocate;
     TestLookup;
     TestLookup;
-    exit;
+//    exit;
     TestNavigation;
     TestNavigation;
     TestAppend;
     TestAppend;
     TestEdit;
     TestEdit;
@@ -444,7 +445,11 @@ begin
 end;
 end;
 
 
 begin
 begin
-  With Tapp.Create do
-    Run;
+  With Tapp.Create(nil) do
+    try
+      Run;
+    finally
+      Free;
+    end;  
 end.
 end.
 
 

+ 1 - 1
packages/fcl-image/src/fpcolors.inc

@@ -43,7 +43,7 @@ const
   colPurple     : TFPColor = (Red: $8000; Green: $0000; Blue: $8000; Alpha: alphaOpaque);
   colPurple     : TFPColor = (Red: $8000; Green: $0000; Blue: $8000; Alpha: alphaOpaque);
   colTeal       : TFPColor = (Red: $0000; Green: $8000; Blue: $8000; Alpha: alphaOpaque);
   colTeal       : TFPColor = (Red: $0000; Green: $8000; Blue: $8000; Alpha: alphaOpaque);
   colSilver     : TFPColor = (Red: $c000; Green: $c000; Blue: $c000; Alpha: alphaOpaque);
   colSilver     : TFPColor = (Red: $c000; Green: $c000; Blue: $c000; Alpha: alphaOpaque);
-  colLime       : TFPColor = (Red: $0000; Green: $ffff; Blue: $0000; Alpha: alphaOpaque);
+  colLime       : TFPColor = (Red: $bfbf; Green: $ffff; Blue: $0000; Alpha: alphaOpaque);
   colFuchsia    : TFPColor = (Red: $ffff; Green: $0000; Blue: $ffff; Alpha: alphaOpaque);
   colFuchsia    : TFPColor = (Red: $ffff; Green: $0000; Blue: $ffff; Alpha: alphaOpaque);
   colAqua       : TFPColor = (Red: $0000; Green: $ffff; Blue: $ffff; Alpha: alphaOpaque);
   colAqua       : TFPColor = (Red: $0000; Green: $ffff; Blue: $ffff; Alpha: alphaOpaque);
 
 

+ 11 - 27
packages/fcl-web/src/base/restbase.pp

@@ -730,7 +730,7 @@ Var
   D : TJSONEnum;
   D : TJSONEnum;
   O : TObjectArray;
   O : TObjectArray;
   I : Integer;
   I : Integer;
-  PA : ^pdynarraytypeinfo;
+  PTD : PTypeData;
   ET : PTypeInfo;
   ET : PTypeInfo;
   LPN,AN : String;
   LPN,AN : String;
   AP : Pointer;
   AP : Pointer;
@@ -760,10 +760,8 @@ begin
     begin
     begin
     // Get array value
     // Get array value
     AP:=GetObjectProp(Self,P);
     AP:=GetObjectProp(Self,P);
-    i:=Length(P^.PropType^.name);
-    PA:=@(pdynarraytypeinfo(P^.PropType)^.elesize)+i;
-    PA:=@(pdynarraytypeinfo(P^.PropType)^.eletype)+i;
-    ET:=PTYpeInfo(PA^);
+    PTD:=GetTypeData(P^.PropType);
+    ET:=PTD^.ElType2;
     if (ET^.Kind=tkClass) then
     if (ET^.Kind=tkClass) then
       begin
       begin
       // get object type name
       // get object type name
@@ -814,7 +812,6 @@ Var
   I : Integer;
   I : Integer;
   L : TBaseObjectList;
   L : TBaseObjectList;
   NL : TBaseNamedObjectList;
   NL : TBaseNamedObjectList;
-  PA : ^pdynarraytypeinfo;
 
 
 begin
 begin
   if P^.PropType^.Kind=tkDynArray then
   if P^.PropType^.Kind=tkDynArray then
@@ -822,12 +819,9 @@ begin
     A:=GetDynArrayProp(P);
     A:=GetDynArrayProp(P);
     For I:=0 to Length(TObjectArray(A))-1 do
     For I:=0 to Length(TObjectArray(A))-1 do
       FreeAndNil(TObjectArray(A)[i]);
       FreeAndNil(TObjectArray(A)[i]);
-    // Writeln(ClassName,' (Object) Setting length of array property ',P^.Name,'(type: ',P^.PropType^.Name,')  to ',AValue.Count,' (current: ',Length(TObjectArray(A)),')');
     SetLength(TObjectArray(A),AValue.Count);
     SetLength(TObjectArray(A),AValue.Count);
-    i:=Length(P^.PropType^.name);
-    PA:=@(pdynarraytypeinfo(P^.PropType)^.elesize)+i;
-    PA:=@(pdynarraytypeinfo(P^.PropType)^.eletype)+i;
-    AN:=PTYpeInfo(PA^)^.Name;
+    T:=GetTypeData(P^.PropType);
+    AN:=T^.ElType2^.Name;
     I:=0;
     I:=0;
     For D in AValue do
     For D in AValue do
       begin
       begin
@@ -841,15 +835,6 @@ begin
       end;
       end;
     // Writeln(ClassName,' Done with array ',P^.Name,', final array length: ', Length(TObjectArray(A)));
     // Writeln(ClassName,' Done with array ',P^.Name,', final array length: ', Length(TObjectArray(A)));
     SetDynArrayProp(P,A);
     SetDynArrayProp(P,A);
-    {
-      For I:=0 to Length(TObjectArray(A))-1 do
-        if IsPublishedProp(TObjectArray(A)[i],'name') then
-    SetDynArrayProp(P,AP);
-      //   Writeln(ClassName,'.',P^.name,'[',i,'] : ',getStrProp(TObjectArray(A)[I],'name'));
-      B:=GetDynArrayProp(P);
-      If Pointer(B)<>Pointer(A) then
-      //  Writeln(ClassName,': Array ',P^.Name,'was not set correctly');
-    }
     Exit;
     Exit;
     end;
     end;
   if Not (P^.PropType^.Kind=tkClass) then
   if Not (P^.PropType^.Kind=tkClass) then
@@ -987,8 +972,8 @@ function TBaseObject.GetArrayProperty(P: PPropInfo): TJSONData;
 Var
 Var
   AO : TObject;
   AO : TObject;
   I : Integer;
   I : Integer;
-  PA : ^pdynarraytypeinfo;
   ET : PTypeInfo;
   ET : PTypeInfo;
+  PTD : PTypeData;
   AP : Pointer;
   AP : Pointer;
   A : TJSONArray;
   A : TJSONArray;
   O : TJSONObject;
   O : TJSONObject;
@@ -998,9 +983,8 @@ begin
   Result:=A;
   Result:=A;
   // Get array value type
   // Get array value type
   AP:=GetObjectProp(Self,P);
   AP:=GetObjectProp(Self,P);
-  i:=Length(P^.PropType^.name);
-  PA:=@(pdynarraytypeinfo(P^.PropType)^.eletype)+i;
-  ET:=PTYpeInfo(PA^);
+  PTD:=GetTypeData(P^.PropType);
+  ET:=PTD^.ElType2;
   // Fill in all elements
   // Fill in all elements
   Case ET^.Kind of
   Case ET^.Kind of
   tkClass:
   tkClass:
@@ -1069,7 +1053,7 @@ var
   P : PPropInfo;
   P : PPropInfo;
   i,j,count,len:integer;
   i,j,count,len:integer;
   A : pointer;
   A : pointer;
-  PA : ^pdynarraytypeinfo;
+  PTD : PTypeData;
   O : TObject;
   O : TObject;
 
 
 begin
 begin
@@ -1091,8 +1075,8 @@ begin
           if (ctArray in ChildTypes) then
           if (ctArray in ChildTypes) then
             begin
             begin
             len:=Length(P^.PropType^.Name);
             len:=Length(P^.PropType^.Name);
-            PA:=@(pdynarraytypeinfo(P^.PropType)^.eletype)+len;
-            if PTYpeInfo(PA^)^.Kind=tkClass then
+            PTD:=GetTypeData(P^.PropType);
+            if PTD^.ElType2^.Kind=tkClass then
               begin
               begin
               A:=GetDynArrayProp(P);
               A:=GetDynArrayProp(P);
 {$IFDEF DUMPARRAY}              
 {$IFDEF DUMPARRAY}