Browse Source

* Merging revisions 1073,r1074,r1077,r1078,r1079 from trunk:
------------------------------------------------------------------------
r1073 | michael | 2021-02-10 12:55:12 +0100 (Wed, 10 Feb 2021) | 1 line

* Patch from Henrique Werlang to implement TJSCSSStyleDeclaration
------------------------------------------------------------------------
r1074 | michael | 2021-02-10 12:58:01 +0100 (Wed, 10 Feb 2021) | 1 line

* Patch from Henrique Werlang to implement TJSElement.Remove
------------------------------------------------------------------------
r1077 | michael | 2021-02-16 10:08:59 +0100 (Tue, 16 Feb 2021) | 1 line

* Fix uninitialized result warnings
------------------------------------------------------------------------
r1078 | svenbarth | 2021-02-19 16:31:28 +0100 (Fri, 19 Feb 2021) | 1 line

* correctly stream TStrings based properties
------------------------------------------------------------------------
r1079 | michael | 2021-02-19 16:38:36 +0100 (Fri, 19 Feb 2021) | 1 line

* Patch from Henrique Werlang to let datalink transmit events ony when active
------------------------------------------------------------------------

michael 4 years ago
parent
commit
5edc3be065
4 changed files with 110 additions and 62 deletions
  1. 56 59
      packages/fcl-db/db.pas
  2. 41 0
      packages/rtl/classes.pas
  3. 2 0
      packages/rtl/generics.collections.pas
  4. 11 3
      packages/rtl/web.pas

+ 56 - 59
packages/fcl-db/db.pas

@@ -90,7 +90,7 @@ type
     property OriginalException : Exception read FOriginalException;
     property PreviousError : Integer read FPreviousError;
   end;
-  
+
 
 { TFieldDef }
 
@@ -116,7 +116,7 @@ type
   protected
     function GetDisplayName: string; override;
     procedure SetDisplayName(const Value: string); override;
-  Public  
+  Public
     property DisplayName : string read GetDisplayName write SetDisplayName;
   published
     property Name : string read FName write SetDisplayName;
@@ -999,7 +999,7 @@ type
   end;
 
 { TDataSet }
-  
+
   TBookmarkFlag = (bfCurrent, bfBOF, bfEOF, bfInserted);
   TBookmark = record
     Data : JSValue;
@@ -1774,7 +1774,7 @@ Function ExtractFieldName(Const Fields: String; var Pos: Integer): String;
 // function SkipComments(var p: PChar; EscapeSlash, EscapeRepeat : Boolean) : boolean;
 
 // operator Enumerator(ADataSet: TDataSet): TDataSetEnumerator;
- 
+
 implementation
 
 uses DBConst,TypInfo;
@@ -1954,7 +1954,7 @@ end;
 { EUpdateError }
 constructor EUpdateError.Create(NativeError, Context : String;
                                 ErrCode, PrevError : integer; E: Exception);
-                                
+
 begin
   Inherited CreateFmt(NativeError,[Context]);
   FContext := Context;
@@ -2456,7 +2456,7 @@ var
   i: Integer;
   OldState: TDatasetState;
 begin
-  FCalcBuffer := Buffer; 
+  FCalcBuffer := Buffer;
   if FState <> dsInternalCalc then
   begin
     OldState := FState;
@@ -2548,7 +2548,7 @@ procedure TDataSet.DataEvent(Event: TDataEvent; Info: JSValue);
   begin
     if aField.FieldKind in [fkData, fkInternalCalc] then
       SetModified(True);
-      
+
     if State <> dsSetKey then begin
       if aField.FieldKind = fkData then begin
         if FInternalCalcFields then
@@ -2559,7 +2559,7 @@ procedure TDataSet.DataEvent(Event: TDataEvent; Info: JSValue);
       aField.Change;
     end;
   end;
-  
+
   procedure HandleScrollOrChange;
   var
     A: Integer;
@@ -2587,7 +2587,7 @@ begin
     deFieldChange   : HandleFieldChange(TField(Info));
     deDataSetChange,
     deDataSetScroll : HandleScrollOrChange;
-    deLayoutChange  : FEnableControlsEvent:=deLayoutChange;    
+    deLayoutChange  : FEnableControlsEvent:=deLayoutChange;
   end;
 
   if not ControlsDisabled and (FState <> dsBlockRead) then begin
@@ -3248,10 +3248,10 @@ end;
 
 function TDataSet.GetIndexDefs(IndexDefs: TIndexDefs; IndexTypes: TIndexOptions
   ): TIndexDefs;
-  
+
 var i,f : integer;
     IndexFields : TStrings;
-    
+
 begin
   IndexDefs.Update;
   Result := TIndexDefs.Create(Self);
@@ -3399,15 +3399,15 @@ begin
   FBlockReadSize := AValue;
   if AValue > 0 then
   begin
-    CheckActive; 
+    CheckActive;
     SetState(dsBlockRead);
-  end	
+  end
   else
   begin
-    //update state only when in dsBlockRead 
+    //update state only when in dsBlockRead
     if FState = dsBlockRead then
       SetState(dsBrowse);
-  end;	
+  end;
 end;
 
 procedure TDataSet.SetFieldDefs(AFieldDefs: TFieldDefs);
@@ -5750,7 +5750,7 @@ begin
   if not Assigned(FLookupDataSet) or (Length(FLookupKeyfields) = 0)
   or (Length(FLookupresultField) = 0) or (Length(FKeyFields) = 0) then
     Exit;
-    
+
   tmpActive := FLookupDataSet.Active;
   try
     FLookupDataSet.Active := True;
@@ -6661,7 +6661,7 @@ begin
     Fmt:=FDisplayFormat
   else
     Fmt:=FEditFormat;
-    
+
   Digits := 0;
   if not FCurrency then
     ff := ffGeneral
@@ -6705,7 +6705,7 @@ var f : Double;
 begin
   If (AValue='') then
     Clear
-  else  
+  else
     begin
     If not TryStrToFloat(AValue,F) then
       DatabaseErrorFmt(SNotAFloat, [AValue]);
@@ -7494,7 +7494,7 @@ procedure TFields.Clear;
 var
   AField: TField;
 begin
-  while FFieldList.Count > 0 do 
+  while FFieldList.Count > 0 do
     begin
     AField := TField(FFieldList.Last);
     AField.FDataSet := Nil;
@@ -7609,12 +7609,8 @@ Var
   B : Boolean;
 
 begin
-  B:=Assigned(DataSource) and Not (DataSource.State in [dsInactive,dsOpening]);
-  If B<>FActive then
-    begin
-    FActive:=B;
-    ActiveChanged;
-    end;
+  B:=Assigned(DataSource) and not (DataSource.State in [dsInactive, dsOpening]);
+  SetActive(B);
   B:=Assigned(DataSource) and (DataSource.State in dsEditModes) and Not FReadOnly;
   If B<>FEditing Then
     begin
@@ -7637,7 +7633,7 @@ begin
   else if DataSource.DataSet.FActiveRecord < FFirstRecord + Index then
     Result := DataSource.DataSet.FActiveRecord - (FFirstRecord + Index)
   else Result := 0;
-  
+
   Inc(FFirstRecord, Index + Result);
 end;
 
@@ -7663,30 +7659,31 @@ end;
 
 
 Procedure TDataLink.DataEvent(Event: TDataEvent; Info: JSValue);
-
-
 begin
-  Case Event of
-    deFieldChange, deRecordChange:
-      If Not FUpdatingRecord then
-        RecordChanged(TField(Info));
-    deDataSetChange: begin
-      SetActive(DataSource.DataSet.Active);
-      CalcRange;
-      CalcFirstRecord(Integer(Info));
-      DatasetChanged;
-    end;
-    deDataSetScroll: DatasetScrolled(CalcFirstRecord(Integer(Info)));
-    deLayoutChange: begin
-      CalcFirstRecord(Integer(Info));
-      LayoutChanged;
+  if Event = deUpdateState then
+    CheckActiveAndEditing
+  else if Active then
+    case Event of
+      deFieldChange, deRecordChange:
+        if not FUpdatingRecord then
+          RecordChanged(TField(Info));
+      deDataSetChange:
+      begin
+        SetActive(DataSource.DataSet.Active);
+        CalcRange;
+        CalcFirstRecord(Integer(Info));
+        DatasetChanged;
+      end;
+      deDataSetScroll: DatasetScrolled(CalcFirstRecord(Integer(Info)));
+      deLayoutChange:
+      begin
+        CalcFirstRecord(Integer(Info));
+        LayoutChanged;
+      end;
+      deUpdateRecord: UpdateRecord;
+      deCheckBrowseMode: CheckBrowseMode;
+      deFocusControl: FocusControl(Info);
     end;
-    deUpdateRecord: UpdateRecord;
-    deUpdateState: CheckActiveAndEditing;
-    deCheckBrowseMode: CheckBrowseMode;
-    deFocusControl:
-      FocusControl(Info);
-  end;
 end;
 
 
@@ -7728,7 +7725,7 @@ begin
   If Assigned(Datasource) then
     Result:=DataSource.DataSet
   else
-    Result:=Nil;  
+    Result:=Nil;
 end;
 
 
@@ -7923,7 +7920,7 @@ begin
     if Active and (FFields.Count > 0) then
       DoMasterChange
     else
-      DoMasterDisable;  
+      DoMasterDisable;
 end;
 
 
@@ -7954,7 +7951,7 @@ begin
   if (DataSource.State <> dsSetKey) and FDetailDataSet.Active and
      (FFields.Count > 0) and ((Field = nil) or
      (FFields.IndexOf(Field) >= 0)) then
-    DoMasterChange;  
+    DoMasterChange;
 end;
 
 procedure TMasterDatalink.SetFieldNames(const Value: string);
@@ -7967,14 +7964,14 @@ begin
     end;
 end;
 
-Procedure TMasterDataLink.DoMasterDisable; 
+Procedure TMasterDataLink.DoMasterDisable;
 
 begin
-  if Assigned(FOnMasterDisable) then 
+  if Assigned(FOnMasterDisable) then
     FOnMasterDisable(Self);
 end;
 
-Procedure TMasterDataLink.DoMasterChange; 
+Procedure TMasterDataLink.DoMasterChange;
 
 begin
   If Assigned(FOnMasterChange) then
@@ -7997,7 +7994,7 @@ begin
     P:=TParams(GetObjectProp(ADataset,'Params',TParams));
     if (P<>Nil) then
       Params:=P;
-    end;  
+    end;
 end;
 
 
@@ -8009,7 +8006,7 @@ begin
     RefreshParamNames;
 end;
 
-Procedure TMasterParamsDataLink.RefreshParamNames; 
+Procedure TMasterParamsDataLink.RefreshParamNames;
 
 Var
   FN : String;
@@ -8041,7 +8038,7 @@ begin
         end;
       end;
     end;
-  FieldNames:=FN;  
+  FieldNames:=FN;
 end;
 
 Procedure TMasterParamsDataLink.CopyParamsFromMaster(CopyBound : Boolean);
@@ -8051,7 +8048,7 @@ begin
     FParams.CopyParamValuesFromDataset(Dataset,CopyBound);
 end;
 
-Procedure TMasterParamsDataLink.DoMasterDisable; 
+Procedure TMasterParamsDataLink.DoMasterDisable;
 
 begin
   Inherited;
@@ -8059,7 +8056,7 @@ begin
   // If master dataset is reopened, relationship will be reestablished
 end;
 
-Procedure TMasterParamsDataLink.DoMasterChange; 
+Procedure TMasterParamsDataLink.DoMasterChange;
 
 begin
   Inherited;

+ 41 - 0
packages/rtl/classes.pas

@@ -272,7 +272,10 @@ type
     procedure SetLineBreak(const S : String);
     Function GetSkipLastLineBreak : Boolean;
     procedure SetSkipLastLineBreak(const AValue : Boolean);
+    procedure ReadData(Reader: TReader);
+    procedure WriteData(Writer: TWriter);
   protected
+    procedure DefineProperties(Filer: TFiler); override;
     procedure Error(const Msg: string; Data: Integer);
     function Get(Index: Integer): string; virtual; abstract;
     function GetCapacity: Integer; virtual;
@@ -2686,6 +2689,44 @@ begin
   FSkipLastLineBreak:=AValue;
 end;
 
+procedure TStrings.ReadData(Reader: TReader);
+begin
+  Reader.ReadListBegin;
+  BeginUpdate;
+  try
+    Clear;
+    while not Reader.EndOfList do
+      Add(Reader.ReadString);
+  finally
+    EndUpdate;
+  end;
+  Reader.ReadListEnd;
+end;
+
+procedure TStrings.WriteData(Writer: TWriter);
+var
+  i: Integer;
+begin
+  Writer.WriteListBegin;
+  for i := 0 to Count - 1 do
+    Writer.WriteString(Strings[i]);
+  Writer.WriteListEnd;
+end;
+
+procedure TStrings.DefineProperties(Filer: TFiler);
+var
+  HasData: Boolean;
+begin
+  if Assigned(Filer.Ancestor) then
+    // Only serialize if string list is different from ancestor
+    if Filer.Ancestor.InheritsFrom(TStrings) then
+      HasData := not Equals(TStrings(Filer.Ancestor))
+    else
+      HasData := True
+  else
+    HasData := Count > 0;
+  Filer.DefineProperty('Strings', @ReadData, @WriteData, HasData);
+end;
 
 function TStrings.GetLBS: TTextLineBreakStyle;
 begin

+ 2 - 0
packages/rtl/generics.collections.pas

@@ -1300,6 +1300,7 @@ end;
 function TDictionary<TKey, TValue>.ExtractPair(const Key: TKey): TMyPair;
 
 begin
+  Result:=Default(TMyPair);
   if FMap.Has(Key) then
     begin
     Result.Create(Key,TValue(FMap.get(key)));
@@ -1419,6 +1420,7 @@ Var
 
 begin
   A:=TJSValueDynArray(FVal.Value);
+  Result:=Default(TMyPair);
   Result.Create(TKey(A[0]),TValue(A[1]));
 end;
 

+ 11 - 3
packages/rtl/web.pas

@@ -267,6 +267,7 @@ TEventListenerEvent = class external name 'EventListener_Event' (TJSObject)
     function matches(aSelectorString : String) : Boolean;
     function querySelector(aSelectors : String) : TJSElement;
     function querySelectorAll(aSelectors : String) : TJSNodeList;
+    procedure remove;
     procedure releasePointerCapture(evID : JSValue);
     procedure removeAttribute(aName: string);
     procedure removeAttributeNS(aNameSpace,aName: string);
@@ -345,6 +346,8 @@ TEventListenerEvent = class external name 'EventListener_Event' (TJSObject)
     property origin : string read FOrigin;
   end;
   
+  TJSCSSStyleDeclaration = class; // forward
+
   TJSStyleSheet = class external name 'StyleSheet' (TJSEventTarget)
   Private
     FHRef : String; external name 'href';
@@ -361,7 +364,6 @@ TEventListenerEvent = class external name 'EventListener_Event' (TJSObject)
     property _type : String read FType;
   end;
 
-
   TJSCSSRule = class external name 'CSSRule'  (TJSObject)
   Private
     FCSSText : String; external name 'cssText';
@@ -372,6 +374,14 @@ TEventListenerEvent = class external name 'EventListener_Event' (TJSObject)
     property parentRule : TJSCSSRule read FparentRule;
     property parentStyleSheet : TJSCSSStyleSheet Read FParentStyleSheet;
   end;
+
+  TJSCSSStyleRule = class external name 'CSSStyleRule' (TJSCSSRule)
+  private
+    FStyle: TJSCSSStyleDeclaration; external name 'style';
+  public
+    selectorText: String;
+    property style: TJSCSSStyleDeclaration read FStyle;
+  end;
   
   TJSCSSRuleList = Class external name 'CSSRuleList'  (TJSObject)
   Private
@@ -1900,8 +1910,6 @@ TEventListenerEvent = class external name 'EventListener_Event' (TJSObject)
     property SearchParams : TJSURLSearchParams read FSearchParams;
   end;
 
-  TJSCSSStyleDeclaration = class; // forward
-
   TJSTimerCallBack = reference to procedure; safecall;
   Theader = Array [0..1] of String;
   THeaderArray = Array of Theader;