浏览代码

fixed SetParent nil, toString returns Name and ClassName

mattias 1 年之前
父节点
当前提交
8ccaffbaa8
共有 3 个文件被更改,包括 41 次插入10 次删除
  1. 27 0
      src/base/fresnel.classes.pas
  2. 7 3
      src/base/fresnel.dom.pas
  3. 7 7
      src/base/fresnel.forms.pas

+ 27 - 0
src/base/fresnel.classes.pas

@@ -118,12 +118,16 @@ type
   Protected
     Class Procedure DoLog(aType: TeventType; Const Msg : string);
     Class Procedure DoLog(aType: TeventType; Const Fmt : string; Const Args : Array of const);
+  Public
+    function ToString: RTLString; override;
   end;
   TFLComponent = TFresnelComponent;
 
 Procedure FLLog(aType: TEventType; Const Msg : string);
 Procedure FLLog(aType: TEventType; Const Fmt : string; Const Args : Array of const);
 Procedure FLLog(aType: TEventType; const args : Array of string);
+function DbgSName(const p: TObject): string; overload;
+function DbgSName(const p: TClass): string; overload;
 
 
 implementation
@@ -151,6 +155,24 @@ begin
   FLLog(aType,Msg);
 end;
 
+function DbgSName(const p: TObject): string;
+begin
+  if p=nil then
+    Result:='nil'
+  else if p is TComponent then
+    Result:=TComponent(p).Name+':'+p.ClassName
+  else
+    Result:=p.ClassName;
+end;
+
+function DbgSName(const p: TClass): string;
+begin
+  if p=nil then
+    Result:='nil'
+  else
+    Result:=p.ClassName;
+end;
+
 { TFresnelPoint }
 
 class function TFresnelPoint.Zero: TFresnelPoint;
@@ -579,5 +601,10 @@ begin
     _LogHook(aType,SafeFormat(Fmt,Args));
 end;
 
+function TFresnelComponent.ToString: RTLString;
+begin
+  Result:=Name+':'+ClassName;
+end;
+
 end.
 

+ 7 - 3
src/base/fresnel.dom.pas

@@ -3285,18 +3285,22 @@ procedure TFresnelElement.SetParentComponent(Value: TComponent);
 var
   aStreamRoot: IFresnelStreamRoot;
 begin
-  DoLog(etDebug,'TFresnelElement.SetParentComponent Self=%s NewParent=%s',[Self.ToString,Value.Tostring]);
+  DoLog(etDebug,'TFresnelElement.SetParentComponent Self=%s NewParent=%s',[DbgSName(Self),DbgSName(Value)]);
   if Value=nil then
+  begin
     Parent:=nil
+  end
   else if Value is TFresnelElement then
+  begin
     Parent:=TFresnelElement(Value)
+  end
   else if Supports(Value,IFresnelStreamRoot,aStreamRoot) then
   begin
-    DoLog(etDebug,'TFresnelElement.SetParentComponent Self=%s redirecting to viewport',[Self.ToString]);
+    DoLog(etDebug,'TFresnelElement.SetParentComponent Self=%s redirecting to viewport',[ToString]);
     Parent:=aStreamRoot.GetViewport;
   end
   else
-    raise EFresnel.CreateFmt('TFresnelElement.SetParentComponent Self=%s NewParentComponent=%s',[Self.ToString,Value.ToString]);
+    raise EFresnel.CreateFmt('TFresnelElement.SetParentComponent Self=%s NewParentComponent=%s',[Name+':'+ClassName,Value.Name+':'+Value.ClassName]);
 end;
 
 procedure TFresnelElement.DoRender(aRenderer: IFresnelRenderer);

+ 7 - 7
src/base/fresnel.forms.pas

@@ -361,7 +361,7 @@ begin
   if AValue.Bottom<AValue.Top then
     AValue.Bottom:=AValue.Top;
   if FFormBounds=AValue then exit;
-  FLLog(etDebug,['TFresnelCustomForm.SetFormBounds ',Self.ToString,' ',AValue.ToString]);
+  FLLog(etDebug,['TFresnelCustomForm.SetFormBounds ',ToString,' ',AValue.ToString]);
   FFormBounds:=AValue;
   if Designer<>nil then
     Designer.SetDesignerFormBounds(Self,FFormBounds.GetRect)
@@ -407,7 +407,7 @@ end;
 
 procedure TFresnelCustomForm.Loaded;
 begin
-  FLLog(etDebug,['TFresnelCustomForm.Loaded ',Self.ToString]);
+  FLLog(etDebug,['TFresnelCustomForm.Loaded ',ToString]);
   inherited Loaded;
   if Visible then
     Show
@@ -513,7 +513,7 @@ end;
 
 procedure TFresnelCustomForm.Hide;
 begin
-  FLLog(etDebug,'TFresnelCustomForm.Hide '+Self.ToString);
+  FLLog(etDebug,'TFresnelCustomForm.Hide '+ToString);
   if (Designer<>nil)
       or ([csLoading,csDesigning]*ComponentState<>[])
       or not WSFormAllocated then
@@ -524,7 +524,7 @@ end;
 
 procedure TFresnelCustomForm.Show;
 begin
-  FLLog(etDebug,'TFresnelCustomForm.Show '+Self.ToString);
+  FLLog(etDebug,'TFresnelCustomForm.Show '+ToString);
   if (Designer<>nil) or ([csLoading,csDesigning,csDestroying]*ComponentState<>[]) then
     FVisible:=true
   else
@@ -557,7 +557,7 @@ begin
   if csDestroying in ComponentState then exit;
 
   // consistency checks
-  FLLog(etDebug,['TFresnelCustomForm.CreateWSForm ',Self.ToString]);
+  FLLog(etDebug,['TFresnelCustomForm.CreateWSForm ',ToString]);
   if Designer<>nil then
     raise Exception.Create('TFresnelCustomForm.CreateWSForm Designer<>nil');
   if Parent = Self then
@@ -587,7 +587,7 @@ procedure TFresnelCustomForm.WSResize(const NewFormBounds: TFresnelRect;
   NewWidth, NewHeight: TFresnelLength);
 begin
   if (FFormBounds=NewFormBounds) and (Width=NewWidth) and (Height=NewHeight) then exit;
-  FLLog(etDebug,['TFresnelCustomForm.WSResize ',Self.ToString,' OldForm=',FFormBounds.ToString,' NewForm=',NewFormBounds.ToString,' OldWH=',FloatToStr(Width),',',FloatToStr(Height),' NewWH=',FloatToStr(NewWidth),',',FloatToStr(NewHeight)]);
+  FLLog(etDebug,['TFresnelCustomForm.WSResize ',ToString,' OldForm=',FFormBounds.ToString,' NewForm=',NewFormBounds.ToString,' OldWH=',FloatToStr(Width),',',FloatToStr(Height),' NewWH=',FloatToStr(NewWidth),',',FloatToStr(NewHeight)]);
   FFormBounds:=NewFormBounds;
   Width:=NewWidth;
   Height:=NewHeight;
@@ -612,7 +612,7 @@ begin
   end else begin
     WSData.ControlPos:=PageToContentPos(El,X,Y);
   end;
-  FLLog(etDebug,'TFresnelCustomForm.WSMouseXY El=%s PagePos=%s ControlPos=%s',[el.ToString, WSData.PagePos.ToString, WSData.ControlPos.ToString]);
+  FLLog(etDebug,'TFresnelCustomForm.WSMouseXY El=%s PagePos=%s ControlPos=%s',[El.ToString, WSData.PagePos.ToString, WSData.ControlPos.ToString]);
   case MouseEventId of
   evtMouseDown:
     fMouseDownElement:=El;