Browse Source

* Patches from Mattias Gaertner to include FPCanvas in LCL

michael 20 years ago
parent
commit
6c91e99415
6 changed files with 113 additions and 52 deletions
  1. 1 1
      fcl/image/fpbrush.inc
  2. 63 26
      fcl/image/fpcanvas.inc
  3. 28 15
      fcl/image/fpcanvas.pp
  4. 2 2
      fcl/image/fpcdrawh.inc
  5. 17 6
      fcl/image/fphelper.inc
  6. 2 2
      fcl/image/fpimgcanv.pp

+ 1 - 1
fcl/image/fpbrush.inc

@@ -32,7 +32,7 @@ begin
     self.Style := Style;
     self.Style := Style;
     self.Image := Image;
     self.Image := Image;
     end;
     end;
-  inherited;
+  inherited DoCopyProps(From);
 end;
 end;
 
 
 function TFPCustomBrush.CopyBrush : TFPCustomBrush;
 function TFPCustomBrush.CopyBrush : TFPCustomBrush;

+ 63 - 26
fcl/image/fpcanvas.inc

@@ -1,3 +1,4 @@
+{%MainUnit fpcanvas.pp}
 {
 {
     $Id$
     $Id$
     This file is part of the Free Pascal run time library.
     This file is part of the Free Pascal run time library.
@@ -30,17 +31,19 @@ end;
 destructor TFPCustomCanvas.Destroy;
 destructor TFPCustomCanvas.Destroy;
 begin
 begin
   FRemovingHelpers := True;
   FRemovingHelpers := True;
+  // first remove all helper references
+  RemoveHelpers;
+  // then free helpers
   FDefaultFont.Free;
   FDefaultFont.Free;
   FDefaultBrush.Free;
   FDefaultBrush.Free;
   FDefaultPen.Free;
   FDefaultPen.Free;
-  RemoveHelpers;
   FHelpers.Free;
   FHelpers.Free;
   FRemovingHelpers := False;
   FRemovingHelpers := False;
   inherited;
   inherited;
 end;
 end;
 
 
 procedure TFPCustomCanvas.CheckHelper (AHelper:TFPCanvasHelper);
 procedure TFPCustomCanvas.CheckHelper (AHelper:TFPCanvasHelper);
-var r : integer;
+// remove references to AHelper
 begin
 begin
   if AHelper = FPen then
   if AHelper = FPen then
     FPen := nil
     FPen := nil
@@ -57,9 +60,7 @@ begin
     else if AHelper = FDefaultBrush then
     else if AHelper = FDefaultBrush then
       FDefaultBrush := CreateDefaultBrush;
       FDefaultBrush := CreateDefaultBrush;
     end;
     end;
-  r := FHelpers.IndexOf (AHelper);
-  if (r >= 0) then
-    FHelpers.delete (r);
+  FHelpers.Remove (AHelper);
 end;
 end;
 
 
 procedure TFPCustomCanvas.RemoveHelpers;
 procedure TFPCustomCanvas.RemoveHelpers;
@@ -120,6 +121,11 @@ begin
     end;
     end;
 end;
 end;
 
 
+function TFPCustomCanvas.GetClipRect: TRect;
+begin
+  Result:=FClipRect;
+end;
+
 function TFPCustomCanvas.CreateFont : TFPCustomFont;
 function TFPCustomCanvas.CreateFont : TFPCustomFont;
 begin
 begin
   result := DoCreateDefaultFont;
   result := DoCreateDefaultFont;
@@ -147,9 +153,14 @@ procedure TFPCustomCanvas.SetFont (AValue:TFPCustomFont);
 begin
 begin
   if (AValue <> FFont) and AllowFont(AValue) then
   if (AValue <> FFont) and AllowFont(AValue) then
     begin
     begin
-    AValue.AllocateResources (self);
-    FFont := AValue;
-    AddHelper (AValue);
+      if FManageResources then
+        FFont.Assign(AValue)
+      else
+        begin
+          AValue.AllocateResources (self);
+          FFont := AValue;
+          AddHelper (AValue);
+        end;
     end;
     end;
 end;
 end;
 
 
@@ -178,9 +189,14 @@ procedure TFPCustomCanvas.SetBrush (AValue:TFPCustomBrush);
 begin
 begin
   if (AValue <> FBrush) and AllowBrush(AValue) then
   if (AValue <> FBrush) and AllowBrush(AValue) then
     begin
     begin
-    AValue.AllocateResources (self);
-    FBrush := AValue;
-    AddHelper (AValue);
+      if FManageResources then
+        FBrush.Assign(AValue)
+      else
+        begin
+          AValue.AllocateResources (self);
+          FBrush := AValue;
+          AddHelper (AValue);
+        end;
     end;
     end;
 end;
 end;
 
 
@@ -209,9 +225,14 @@ procedure TFPCustomCanvas.SetPen (AValue:TFPCustomPen);
 begin
 begin
   if (AValue <> FPen) and AllowPen (AValue) then
   if (AValue <> FPen) and AllowPen (AValue) then
     begin
     begin
-    AValue.AllocateResources (self);
-    FPen := AValue;
-    AddHelper (AValue);
+      if FManageResources then
+        FPen.Assign(AValue)
+      else
+        begin
+          AValue.AllocateResources (self);
+          FPen := AValue;
+          AddHelper (AValue);
+        end;
     end;
     end;
 end;
 end;
 
 
@@ -223,6 +244,16 @@ begin
     result := FDefaultPen;
     result := FDefaultPen;
 end;
 end;
 
 
+procedure TFPCustomCanvas.SetClipRect(const AValue: TRect);
+begin
+  FClipRect:=AValue;
+end;
+
+procedure TFPCustomCanvas.SetPenPos(const AValue: TPoint);
+begin
+  FPenPos:=AValue;
+end;
+
 function TFPCustomCanvas.DoAllowPen (APen : TFPCustomPen) : boolean;
 function TFPCustomCanvas.DoAllowPen (APen : TFPCustomPen) : boolean;
 begin
 begin
   result := false;
   result := false;
@@ -255,6 +286,11 @@ begin
     raise TFPCanvasException.Create (ErrNoLock);
     raise TFPCanvasException.Create (ErrNoLock);
 end;
 end;
 
 
+function TFPCustomCanvas.Locked: boolean;
+begin
+  Result:=FLocks>0;
+end;
+
 procedure TFPCustomCanvas.TextOut (x,y:integer;text:string);
 procedure TFPCustomCanvas.TextOut (x,y:integer;text:string);
 begin
 begin
   if Font is TFPCustomDrawFont then
   if Font is TFPCustomDrawFont then
@@ -293,19 +329,19 @@ end;
 
 
 procedure TFPCustomCanvas.DoLineTo (x,y:integer);
 procedure TFPCustomCanvas.DoLineTo (x,y:integer);
 begin
 begin
-  DoLine (FCurrent.X,FCurrent.y, x,y);
+  DoLine (FPenPos.X,FPenPos.y, x,y);
 end;
 end;
 
 
 procedure TFPCustomCanvas.MoveTo (x,y:integer);
 procedure TFPCustomCanvas.MoveTo (x,y:integer);
 begin
 begin
-  FCurrent.x := x;
-  FCurrent.y := y;
+  FPenPos.x := x;
+  FPenPos.y := y;
   DoMoveTo (x,y);
   DoMoveTo (x,y);
 end;
 end;
 
 
 procedure TFPCustomCanvas.MoveTo (p:TPoint);
 procedure TFPCustomCanvas.MoveTo (p:TPoint);
 begin
 begin
-  FCurrent := p;
+  FPenPos := p;
   DoMoveTo (p.x,p.y);
   DoMoveTo (p.x,p.y);
 end;
 end;
 
 
@@ -313,11 +349,11 @@ procedure TFPCustomCanvas.LineTo (x,y:integer);
 begin
 begin
   if Pen.Style <> psClear then
   if Pen.Style <> psClear then
     if Pen is TFPCustomDrawPen then
     if Pen is TFPCustomDrawPen then
-      TFPCustomDrawPen(Pen).DrawLine (FCurrent.x, FCurrent.y, x, y)
+      TFPCustomDrawPen(Pen).DrawLine (FPenPos.x, FPenPos.y, x, y)
     else
     else
       DoLineTo (x,y);
       DoLineTo (x,y);
-  FCurrent.x := x;
-  FCurrent.y := y;
+  FPenPos.x := x;
+  FPenPos.y := y;
 end;
 end;
 
 
 procedure TFPCustomCanvas.LineTo (p:TPoint);
 procedure TFPCustomCanvas.LineTo (p:TPoint);
@@ -332,11 +368,11 @@ begin
       TFPCustomDrawPen(Pen).DrawLine (x1,y1, x2,y2)
       TFPCustomDrawPen(Pen).DrawLine (x1,y1, x2,y2)
     else
     else
       DoLine (x1,y1, x2,y2);
       DoLine (x1,y1, x2,y2);
-  FCurrent.x := x2;
-  FCurrent.y := y2;
+  FPenPos.x := x2;
+  FPenPos.y := y2;
 end;
 end;
 
 
-procedure TFPCustomCanvas.Line (p1,p2:TPoint);
+procedure TFPCustomCanvas.Line (const p1,p2:TPoint);
 begin
 begin
   Line (p1.x,p1.y,p2.x,p2.y);
   Line (p1.x,p1.y,p2.x,p2.y);
 end;
 end;
@@ -354,7 +390,7 @@ begin
      TFPCustomDrawPen(Pen).Polyline (points,false)
      TFPCustomDrawPen(Pen).Polyline (points,false)
    else
    else
      DoPolyline (points);
      DoPolyline (points);
-  FCurrent := points[high(points)];
+  FPenPos := points[high(points)];
 end;
 end;
 
 
 procedure TFPCustomCanvas.Clear;
 procedure TFPCustomCanvas.Clear;
@@ -538,7 +574,8 @@ begin
     end;
     end;
 end;
 end;
 
 
-procedure TFPCustomCanvas.CopyRect (x,y:integer; canvas:TFPCustomCanvas; SourceRect:TRect);
+procedure TFPCustomCanvas.CopyRect (x,y:integer; canvas:TFPCustomCanvas;
+  SourceRect:TRect);
 var xx,r,t : integer;
 var xx,r,t : integer;
 begin
 begin
   SortRect (SourceRect);
   SortRect (SourceRect);

+ 28 - 15
fcl/image/fpcanvas.pp

@@ -32,8 +32,11 @@ type
 
 
   TFPCustomCanvas = class;
   TFPCustomCanvas = class;
 
 
+  { TFPCanvasHelper }
+
   TFPCanvasHelper = class(TPersistent)
   TFPCanvasHelper = class(TPersistent)
   private
   private
+    FDelayAllocate: boolean;
     FFPColor : TFPColor;
     FFPColor : TFPColor;
     FAllocated,
     FAllocated,
     FFixedCanvas : boolean;
     FFixedCanvas : boolean;
@@ -41,10 +44,10 @@ type
     FFlags : word;
     FFlags : word;
     FOnChange: TNotifyEvent;
     FOnChange: TNotifyEvent;
     FOnChanging: TNotifyEvent;
     FOnChanging: TNotifyEvent;
-    function GetAllocated : boolean;
     procedure NotifyCanvas;
     procedure NotifyCanvas;
   protected
   protected
     // flags 0-15 are reserved for FPCustomCanvas
     // flags 0-15 are reserved for FPCustomCanvas
+    function GetAllocated: boolean; virtual;
     procedure SetFlags (index:integer; AValue:boolean); virtual;
     procedure SetFlags (index:integer; AValue:boolean); virtual;
     function GetFlags (index:integer) : boolean; virtual;
     function GetFlags (index:integer) : boolean; virtual;
     procedure CheckAllocated (ValueNeeded:boolean);
     procedure CheckAllocated (ValueNeeded:boolean);
@@ -52,17 +55,18 @@ type
     procedure DoAllocateResources; virtual;
     procedure DoAllocateResources; virtual;
     procedure DoDeAllocateResources; virtual;
     procedure DoDeAllocateResources; virtual;
     procedure DoCopyProps (From:TFPCanvasHelper); virtual;
     procedure DoCopyProps (From:TFPCanvasHelper); virtual;
-    procedure SetFPColor (AValue:TFPColor); virtual;
+    procedure SetFPColor (const AValue:TFPColor); virtual;
     procedure Changing; dynamic;
     procedure Changing; dynamic;
     procedure Changed; dynamic;
     procedure Changed; dynamic;
     Procedure Lock;
     Procedure Lock;
     Procedure UnLock;
     Procedure UnLock;
   public
   public
     constructor Create; virtual;
     constructor Create; virtual;
-    destructor destroy; override;
+    destructor Destroy; override;
     // prepare helper for use
     // prepare helper for use
-    procedure AllocateResources (ACanvas : TFPCustomCanvas);
-    // free all resource used bby this helper
+    procedure AllocateResources (ACanvas : TFPCustomCanvas;
+                                 CanDelay: boolean = true);
+    // free all resource used by this helper
     procedure DeallocateResources;
     procedure DeallocateResources;
     property Allocated : boolean read GetAllocated;
     property Allocated : boolean read GetAllocated;
     // properties cannot be changed when allocated
     // properties cannot be changed when allocated
@@ -73,6 +77,7 @@ type
     property FPColor : TFPColor read FFPColor Write SetFPColor;
     property FPColor : TFPColor read FFPColor Write SetFPColor;
     property OnChanging: TNotifyEvent read FOnChanging write FOnChanging;
     property OnChanging: TNotifyEvent read FOnChanging write FOnChanging;
     property OnChange: TNotifyEvent read FOnChange write FOnChange;
     property OnChange: TNotifyEvent read FOnChange write FOnChange;
+    property DelayAllocate: boolean read FDelayAllocate write FDelayAllocate;
   end;
   end;
 
 
   TFPCustomFont = class (TFPCanvasHelper)
   TFPCustomFont = class (TFPCanvasHelper)
@@ -149,9 +154,12 @@ type
   end;
   end;
   TFPCustomBrushClass = class of TFPCustomBrush;
   TFPCustomBrushClass = class of TFPCustomBrush;
 
 
-  TFPCustomCanvas = class
+  { TFPCustomCanvas }
+
+  TFPCustomCanvas = class(TPersistent)
   private
   private
     FClipping,
     FClipping,
+    FManageResources: boolean;
     FRemovingHelpers : boolean;
     FRemovingHelpers : boolean;
     FDefaultFont,
     FDefaultFont,
     FFont : TFPCustomFont;
     FFont : TFPCustomFont;
@@ -159,7 +167,7 @@ type
     FBrush : TFPCustomBrush;
     FBrush : TFPCustomBrush;
     FDefaultPen,
     FDefaultPen,
     FPen : TFPCustomPen;
     FPen : TFPCustomPen;
-    FCurrent : TPoint;
+    FPenPos : TPoint;
     FClipRect : TRect;
     FClipRect : TRect;
     FHelpers : TList;
     FHelpers : TList;
     FLocks : integer;
     FLocks : integer;
@@ -183,12 +191,15 @@ type
     function  DoAllowFont (AFont : TFPCustomFont) : boolean; virtual;
     function  DoAllowFont (AFont : TFPCustomFont) : boolean; virtual;
     function  DoAllowPen (APen : TFPCustomPen) : boolean; virtual;
     function  DoAllowPen (APen : TFPCustomPen) : boolean; virtual;
     function  DoAllowBrush (ABrush : TFPCustomBrush) : boolean; virtual;
     function  DoAllowBrush (ABrush : TFPCustomBrush) : boolean; virtual;
-    procedure SetColor (x,y:integer; Value:TFPColor); Virtual; abstract;
+    procedure SetColor (x,y:integer; const Value:TFPColor); Virtual; abstract;
     function  GetColor (x,y:integer) : TFPColor; Virtual; abstract;    
     function  GetColor (x,y:integer) : TFPColor; Virtual; abstract;    
     procedure SetHeight (AValue : integer); virtual; abstract;
     procedure SetHeight (AValue : integer); virtual; abstract;
     function  GetHeight : integer; virtual; abstract;
     function  GetHeight : integer; virtual; abstract;
     procedure SetWidth (AValue : integer); virtual; abstract;
     procedure SetWidth (AValue : integer); virtual; abstract;
     function  GetWidth : integer; virtual; abstract;
     function  GetWidth : integer; virtual; abstract;
+    function  GetClipRect: TRect; virtual;
+    procedure SetClipRect(const AValue: TRect); virtual;
+    procedure SetPenPos(const AValue: TPoint); virtual;
     procedure DoLockCanvas; virtual;
     procedure DoLockCanvas; virtual;
     procedure DoUnlockCanvas; virtual;
     procedure DoUnlockCanvas; virtual;
     procedure DoTextOut (x,y:integer;text:string); virtual; abstract;
     procedure DoTextOut (x,y:integer;text:string); virtual; abstract;
@@ -218,6 +229,7 @@ type
     destructor destroy; override;
     destructor destroy; override;
     procedure LockCanvas;
     procedure LockCanvas;
     procedure UnlockCanvas;
     procedure UnlockCanvas;
+    function Locked: boolean;
     function CreateFont : TFPCustomFont;
     function CreateFont : TFPCustomFont;
     function CreatePen : TFPCustomPen;
     function CreatePen : TFPCustomPen;
     function CreateBrush : TFPCustomBrush;
     function CreateBrush : TFPCustomBrush;
@@ -243,7 +255,7 @@ type
     procedure LineTo (x,y:integer);
     procedure LineTo (x,y:integer);
     procedure LineTo (p:TPoint);
     procedure LineTo (p:TPoint);
     procedure Line (x1,y1,x2,y2:integer);
     procedure Line (x1,y1,x2,y2:integer);
-    procedure Line (p1,p2:TPoint);
+    procedure Line (const p1,p2:TPoint);
     procedure Line (const points:TRect);
     procedure Line (const points:TRect);
     // other procedures
     // other procedures
     procedure CopyRect (x,y:integer; canvas:TFPCustomCanvas; SourceRect:TRect);
     procedure CopyRect (x,y:integer; canvas:TFPCustomCanvas; SourceRect:TRect);
@@ -254,11 +266,12 @@ type
     property Pen : TFPCustomPen read GetPen write SetPen;
     property Pen : TFPCustomPen read GetPen write SetPen;
     property Brush : TFPCustomBrush read GetBrush write SetBrush;
     property Brush : TFPCustomBrush read GetBrush write SetBrush;
     property Colors [x,y:integer] : TFPColor read GetColor write SetColor;
     property Colors [x,y:integer] : TFPColor read GetColor write SetColor;
-    property ClipRect : TRect read FClipRect write FClipRect;
+    property ClipRect : TRect read GetClipRect write SetClipRect;
     property Clipping : boolean read FClipping write FClipping;
     property Clipping : boolean read FClipping write FClipping;
-    property PenPos : TPoint read FCurrent write FCurrent;
+    property PenPos : TPoint read FPenPos write SetPenPos;
     property Height : integer read GetHeight write SetHeight;
     property Height : integer read GetHeight write SetHeight;
     property Width : integer read GetWidth write SetWidth;
     property Width : integer read GetWidth write SetWidth;
+    property ManageResources: boolean read FManageResources write FManageResources;
   end;
   end;
 
 
   TFPCustomDrawFont = class (TFPCustomFont)
   TFPCustomDrawFont = class (TFPCustomFont)
@@ -280,12 +293,12 @@ type
   TFPCustomDrawPen = class (TFPCustomPen)
   TFPCustomDrawPen = class (TFPCustomPen)
   private
   private
     procedure DrawLine (x1,y1,x2,y2:integer);
     procedure DrawLine (x1,y1,x2,y2:integer);
-    procedure Polyline (points:array of TPoint; close:boolean);
+    procedure Polyline (const points:array of TPoint; close:boolean);
     procedure Ellipse (left,top, right,bottom:integer);
     procedure Ellipse (left,top, right,bottom:integer);
     procedure Rectangle (left,top, right,bottom:integer);
     procedure Rectangle (left,top, right,bottom:integer);
   protected
   protected
     procedure DoDrawLine (x1,y1,x2,y2:integer); virtual; abstract;
     procedure DoDrawLine (x1,y1,x2,y2:integer); virtual; abstract;
-    procedure DoPolyline (points:array of TPoint; close:boolean); virtual; abstract;
+    procedure DoPolyline (const points:array of TPoint; close:boolean); virtual; abstract;
     procedure DoEllipse (left,top, right,bottom:integer); virtual; abstract;
     procedure DoEllipse (left,top, right,bottom:integer); virtual; abstract;
     procedure DoRectangle (left,top, right,bottom:integer); virtual; abstract;
     procedure DoRectangle (left,top, right,bottom:integer); virtual; abstract;
   end;
   end;
@@ -298,12 +311,12 @@ type
     procedure Rectangle (left,top, right,bottom:integer);
     procedure Rectangle (left,top, right,bottom:integer);
     procedure FloodFill (x,y:integer);
     procedure FloodFill (x,y:integer);
     procedure Ellipse (left,top, right,bottom:integer);
     procedure Ellipse (left,top, right,bottom:integer);
-    procedure Polygon (points:array of TPoint);
+    procedure Polygon (const points:array of TPoint);
   public
   public
     procedure DoRectangle (left,top, right,bottom:integer); virtual; abstract;
     procedure DoRectangle (left,top, right,bottom:integer); virtual; abstract;
     procedure DoEllipse (left,top, right,bottom:integer); virtual; abstract;
     procedure DoEllipse (left,top, right,bottom:integer); virtual; abstract;
     procedure DoFloodFill (x,y:integer); virtual; abstract;
     procedure DoFloodFill (x,y:integer); virtual; abstract;
-    procedure DoPolygon (points:array of TPoint); virtual; abstract;
+    procedure DoPolygon (const points:array of TPoint); virtual; abstract;
   end;
   end;
 
 
   TFPEmptyBrush = class (TFPCustomBrush)
   TFPEmptyBrush = class (TFPCustomBrush)

+ 2 - 2
fcl/image/fpcdrawh.inc

@@ -20,7 +20,7 @@ begin
   DoDrawLine (x1,y1,x2,y2);
   DoDrawLine (x1,y1,x2,y2);
 end;
 end;
 
 
-procedure TFPCustomDrawPen.Polyline (points:array of TPoint; close:boolean);
+procedure TFPCustomDrawPen.Polyline (const points:array of TPoint; close:boolean);
 begin
 begin
   DoPolyLine (points, false);
   DoPolyLine (points, false);
 end;
 end;
@@ -52,7 +52,7 @@ begin
   DoEllipse (left,top,right,bottom);
   DoEllipse (left,top,right,bottom);
 end;
 end;
 
 
-procedure TFPCustomDrawBrush.Polygon (points:array of TPoint);
+procedure TFPCustomDrawBrush.Polygon (const points:array of TPoint);
 begin
 begin
   DoPolygon (points);
   DoPolygon (points);
 end;
 end;

+ 17 - 6
fcl/image/fphelper.inc

@@ -1,3 +1,4 @@
+{%MainUnit fpcanvas.pp}
 {
 {
     $Id$
     $Id$
     This file is part of the Free Pascal run time library.
     This file is part of the Free Pascal run time library.
@@ -36,17 +37,26 @@ begin
 end;
 end;
 
 
 procedure TFPCanvasHelper.NotifyCanvas;
 procedure TFPCanvasHelper.NotifyCanvas;
+// called to unbind from canvas
 begin
 begin
-  FCanvas.CheckHelper (self);
+  if FCanvas<>nil then
+    FCanvas.CheckHelper (self);
 end;
 end;
 
 
 procedure TFPCanvasHelper.CheckAllocated (ValueNeeded:boolean);
 procedure TFPCanvasHelper.CheckAllocated (ValueNeeded:boolean);
+
+  procedure RaiseErrAllocation;
+  begin
+    Raise TFPFontException.CreateFmt (ErrAllocation,
+                                      [EFont, ErrAlloc[ValueNeeded]]);
+  end;
+
 begin
 begin
   if (Allocated <> ValueNeeded) then
   if (Allocated <> ValueNeeded) then
-    Raise TFPFontException.CreateFmt (ErrAllocation, [EFont, ErrAlloc[ValueNeeded]]);
+    RaiseErrAllocation;
 end;
 end;
 
 
-procedure TFPCanvasHelper.SetFPColor (AValue:TFPColor);
+procedure TFPCanvasHelper.SetFPColor(const AValue:TFPColor);
 begin
 begin
   FFPColor := AValue;
   FFPColor := AValue;
 end;
 end;
@@ -92,12 +102,14 @@ begin
     result := FAllocated;
     result := FAllocated;
 end;
 end;
 
 
-procedure TFPCanvasHelper.AllocateResources (ACanvas : TFPCustomCanvas);
+procedure TFPCanvasHelper.AllocateResources (ACanvas : TFPCustomCanvas;
+  CanDelay: boolean);
 begin
 begin
   if FFixedCanvas and FAllocated then
   if FFixedCanvas and FAllocated then
     DeallocateResources;
     DeallocateResources;
+  FCanvas := ACanvas;
+  if DelayAllocate and CanDelay then exit;
   try
   try
-    FCanvas := ACanvas;
     DoAllocateResources;
     DoAllocateResources;
     FAllocated := True;
     FAllocated := True;
   except
   except
@@ -120,7 +132,6 @@ end;
 
 
 procedure TFPCanvasHelper.DoCopyProps (From:TFPCanvasHelper);
 procedure TFPCanvasHelper.DoCopyProps (From:TFPCanvasHelper);
 begin
 begin
-  FCanvas := nil;
   FPColor := from.FPColor;
   FPColor := from.FPColor;
 end;
 end;
 
 

+ 2 - 2
fcl/image/fpimgcanv.pp

@@ -25,7 +25,7 @@ type
   private
   private
     FImage : TFPCustomImage;
     FImage : TFPCustomImage;
   protected
   protected
-    procedure SetColor (x,y:integer; AValue:TFPColor); override;
+    procedure SetColor (x,y:integer; const AValue:TFPColor); override;
     function  GetColor (x,y:integer) : TFPColor; override;
     function  GetColor (x,y:integer) : TFPColor; override;
     procedure SetHeight (AValue : integer); override;
     procedure SetHeight (AValue : integer); override;
     function  GetHeight : integer; override;
     function  GetHeight : integer; override;
@@ -52,7 +52,7 @@ begin
   inherited destroy;
   inherited destroy;
 end;
 end;
 
 
-procedure TFPImageCanvas.SetColor (x,y:integer; AValue:TFPColor);
+procedure TFPImageCanvas.SetColor (x,y:integer; const AValue:TFPColor);
 begin
 begin
   if (x >= 0) and (x < width) and (y >= 0) and (y < height) then
   if (x >= 0) and (x < width) and (y >= 0) and (y < height) then
     if not clipping or PointInside (x,y, ClipRect) then
     if not clipping or PointInside (x,y, ClipRect) then