Canvas.SetColor error: identifier idents no member "SetColor"? lazarus / 39-Graphics ---------------------------------------------------------------------- JoshM · 2013-07-03 20:05 Code: [Select]{$mode objfpc}{$h+} program demo; uses classes, sysutils,      FPImage, FPCanvas, FPImgCanv,      FPWritePNG, Graphics; var canvas : TFPCustomCanvas;     image : TFPCustomImage;     writer : TFPCustomImageWriter;     red, white : TFPColor;     x, y : integer; begin   { Create an image 100x100 pixels}   Red.red:=65535;   Red.green:=0;   Red.blue:=0;   Red.alpha:=65535;   white.red := 65535;   white.blue := 65535;   white.alpha :=65535;   white.green := 65535;   image := TFPMemoryImage.Create (100,100);   { Attach the image to the canvas }   Canvas := TFPImageCanvas.create(image);   { Create the writer }   Writer := TFPWriterPNG.Create;   for y := 0 to 100 do begin   for x := 0 to 100 do begin      If x DIV 2 = 0 then      Canvas.SetColor(x, y, red) //error here      else      Canvas.SetColor(x, y, white); //error here   end;   end;   { Save to file }   image.SaveToFile ('C:\Users\Josh.PC1\Desktop\DrawTest.png');   { Clean up! }   Canvas.Free;   image.Free;   writer.Free; end. Does anyone know what I'm doing wrong? It's my first time working with the canvas and I've literally just copied the basic code from here (http://wiki.freepascal.org/fcl-image#Basic_Canvas_Setup). Not sure if this will help, but when I type canvas. (ready for all the function/procedure suggestions to appear), SetColor does not when I think it should. At first I kept getting "Graphics unit not found" but I seem to have partly fixed that at least. Any help would be appreciated ---------------------------------------------------------------------- Blaazen · 2013-07-03 20:16 AFAIK Canvas has no method SetCanvas. Instead, you can use: Code: [Select]Canvas.Pixels[x, y] := clRed; But painting whole picture this way will be slow. Maybe, your algorithm can be substituted with vertical lines ? ---------------------------------------------------------------------- howardpc · 2013-07-03 21:41 SetColor is a protected method of TFPImageCanvas, which as Blaazen suspected simply uses the slow Pixels[] property. In order to get working code you have to adapt the example you found as follows. (The example is old and refers to earlier FPC/Lazarus versions which have since changed. The code nmtv posted differs from what is currently shown on the referenced wiki page). Code: [Select]{$mode objfpc} program demo; uses FPImage, FPWritePNG, FPImgCanv; type    { TFPImgCanvasEx }    TFPImgCanvasEx = class(TFPImageCanvas)    public      procedure SetColor(x, y: integer; const AValue: TFPColor); override;    end; var canvas : TFPImgCanvasEx;     image : TFPCustomImage;     writer : TFPCustomImageWriter;     red, white : TFPColor;     x, y : integer; { TFPImgCanvasEx } procedure TFPImgCanvasEx.SetColor(x, y: integer; const AValue: TFPColor); begin   inherited SetColor(x, y, AValue); end; begin   { Create an image 100x100 pixels}   Red.red:=65535;   Red.green:=0;   Red.blue:=0;   Red.alpha:=65535;   white.red := 65535;   white.blue := 65535;   white.alpha :=65535;   white.green := 65535;   image := TFPMemoryImage.Create (100,100);   { Attach the image to the canvas }   Canvas := TFPImgCanvasEx.create(image);   { Create the writer }   Writer := TFPWriterPNG.Create;   for y := 0 to 100 do begin   for x := 0 to 100 do begin      If x DIV 2 = 0 then      Canvas.SetColor(x, y, red) //there was an error here previously      else      Canvas.SetColor(x, y, white);   end;   end;   { Save to file }   image.SaveToFile ('DrawTest.png');   { Clean up! }   Canvas.Free;   image.Free;   writer.Free; end. ---------------------------------------------------------------------- JoshM · 2013-07-04 19:24 Thanks for the solution. I read about the SetColor procedure here: http://lazarus- ccr.sourceforge.net/docs/lcl/graphics/tcanvas.setcolor.html To me that looks as though I can type Canvas.SetColor It's probably just that I'm wrong, but maybe it could be an outdated article...?