### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Mixing Between FCL and LCL  (Read 7195 times)

#### benohb

• Full Member
• Posts: 198
##### Mixing Between FCL and LCL
« on: December 28, 2010, 12:19:21 am »
Hello
How is it going
I meet I'm computer screen without a result

Problem
Code: [Select]
`varLCLImg: TBitmap;Fcanvas : TFPcustomCanvas;image : TFPCustomImage;begin.....................................................LCLImg.Canvas.CopyRect(x,y,Fcanvas,Trect);  <--is not work , procedure existing in the list... :-\.............end.`
I know the object is derived
TCanvas = class(TFPCustomCanvas)
I hope you help me to copy TFPCustomCanvas to TCanvas Without use TFPCustomImageWriter or loops

At least the possibility

#### Marc

• Hero Member
• Posts: 2512
##### Re: Mixing Between FCL and LCL
« Reply #1 on: December 28, 2010, 11:40:03 am »
TRect is a type, you need to pass a variable of type TRect, like

Code: Pascal  [Select][+][-]
1. var
2.   R: TRect;
3. begin
4.   ...
5.   R := Rect(1,2,3,4);
6.   LCLImg.Canvas.CopyRect(x,y,Fcanvas,R);
7.   // or directly
8.   LCLImg.Canvas.CopyRect(x,y,Fcanvas,Rect(1,2,3,4));
9.   ...
10. end;
11.
//--
{\$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

#### benohb

• Full Member
• Posts: 198
##### Re: Mixing Between FCL and LCL
« Reply #2 on: December 28, 2010, 11:19:02 pm »
I do not know how to put the color code just like you

Quote
TRect is a type, you need to pass a variable of type TRect, like
I do....?

Code: [Select]
`procedure TForm1.Button1Click(Sender: TObject);varLCLImg: TBitmap;FCLcanvas : TFPcustomCanvas;FCLimg: TFPCustomImage;R: TRect;begin   R := Rect(1,2,3,4);  {FCL}  FCLimg := TFPMemoryImage.Create (100,100);  FCLcanvas := TFPImageCanvas.Create (FCLimg);  {LCL}  LCLImg := TBitmap.Create;  LCLImg.Width:=100;  LCLImg.Height:=100;  FCLcanvas.Ellipse (10,10, 90,90);  {Compiler stops here}  LCLImg.Canvas.CopyRect(0,0,FCLcanvas,Rect(1,2,3,4));  {I tried   CopyRect(0,0,FCLcanvas,R);  }  FCLcanvas.Free;  FCLimg.Free;  LCLImg.Free;end;              `
Compiler message

Code: [Select]
`unit1.pas(51,46) Warning: Constructing a class "TFPImageCanvas" with abstract method "DoCopyRect"unit1.pas(51,46) Warning: Constructing a class "TFPImageCanvas" with abstract method "DoDraw"unit1.pas(61,54) Error: Wrong number of parameters specified for call to "CopyRect"canvas.inc(110,19) Hint: Found declaration: TCanvas.CopyRect(const TRect,TCanvas,const TRect);unit1.pas(76) Fatal: There were 1 errors compiling module, stopping`
The problem is in the transfer of TFPcustomCanvas type to Timage.canvas  and Contrary
Any solutions

#### Leledumbo

• Hero Member
• Posts: 8273
• Programming + Glam Metal + Tae Kwon Do = Me
##### Re: Mixing Between FCL and LCL
« Reply #3 on: December 29, 2010, 04:40:13 am »
Quote
Hint: Found declaration: TCanvas.CopyRect(const TRect,TCanvas,const TRect);
Isn't that clear enough? Compare with your code:
Code: [Select]
`LCLImg.Canvas.CopyRect(0,0,FCLcanvas,Rect(1,2,3,4));`You pass 4 arguments, while it expects 3 with the first one being a TRect as well as the third.

#### benohb

• Full Member
• Posts: 198
##### Re: Mixing Between FCL and LCL
« Reply #4 on: December 29, 2010, 07:24:05 am »
I'm with you on this

Quote
You pass 4 arguments, while it expects 3 with the first one being a TRect as well as the third.

The menu that appears when you type the dots after the  Tbitmap.Canvas.<--
There are two types of procedure

1-LCL
In unit "Graphics" at line (961) a new class Named  TCanvas Derived from TFPCustomCanvas

Public procedures
Code: [Select]
`procedure CopyRect(const Dest: TRect; SrcCanvas: TCanvas; const Source: TRect); virtual; `
Here requires 3 arguments.......

2-FCL
In unit "FPCanvas" at line (192) You will find there TFPCustomCanvas = class(TPersistent)

Code: [Select]
`procedure CopyRect (x,y:integer; canvas:TFPCustomCanvas; SourceRect:TRect);`
Here requires 4 arguments.......
1-X,
2-Y,
3-TFPCustomCanvas
4-TRect

I've changed the coordinates x,y With ' Tpoint ' , Of course,the compiler does not accept

The comma Between X and Y is the problem ...

,

And more clarity

Try copying TFPcustomCanvas  to  Tcanvas  or Tbitmap.canvas

« Last Edit: December 29, 2010, 07:40:33 am by benohb »

#### Marc

• Hero Member
• Posts: 2512
##### Re: Mixing Between FCL and LCL
« Reply #5 on: December 29, 2010, 11:55:25 am »
I do not know how to put the color code just like you

I'm with you on this

Quote
You pass 4 arguments, while it expects 3 with the first one being a TRect as well as the third.

The menu that appears when you type the dots after the  Tbitmap.Canvas.<--
There are two types of procedure

1-LCL
In unit "Graphics" at line (961) a new class Named  TCanvas Derived from TFPCustomCanvas

Public procedures
Code: [Select]
`procedure CopyRect(const Dest: TRect; SrcCanvas: TCanvas; const Source: TRect); virtual; `
Here requires 3 arguments.......

2-FCL
In unit "FPCanvas" at line (192) You will find there TFPCustomCanvas = class(TPersistent)

Code: [Select]
`procedure CopyRect (x,y:integer; canvas:TFPCustomCanvas; SourceRect:TRect);`
Here requires 4 arguments.......
1-X,
2-Y,
3-TFPCustomCanvas
4-TRect

I've changed the coordinates x,y With ' Tpoint ' , Of course,the compiler does not accept

The comma Between X and Y is the problem ...

Putting random parameters to functions won't help you. Why a TPoint ? if you look at the first declaration you see as first parameter "Dest: TRect;" thats not a Tpoint, but a TRect.

(I was trying to explain what happens, but removed that text since what you do should work imo)

Since you use TFPImageCanvas, the compiler should find the overloaded TFPCustomCanvas.CopyRect and use that, but somehow it refuses to find it. (in objfpc mode you don't need the overload directive)
Does the following work:
Code: Pascal  [Select][+][-]
1. ...
2. TFPCustomCanvas(LCLImg.Canvas).CopyRect(0,0,FCLcanvas,R);
3. ...
4.

//--
{\$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

#### benohb

• Full Member
• Posts: 198
##### Re: Mixing Between FCL and LCL
« Reply #6 on: December 30, 2010, 05:36:01 am »
Quote
Putting random parameters to functions won't help you. Why a TPoint ? if you look at the first declaration you see as first parameter "Dest: TRect;" thats not a Tpoint, but a TRect.