Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: benohb on December 28, 2010, 12:19:21 am

Title: Mixing Between FCL and LCL
Post by: benohb 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]
var
LCLImg: 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  :-[
Title: Re: Mixing Between FCL and LCL
Post by: Marc 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.  
Title: Re: Mixing Between FCL and LCL
Post by: benohb on December 28, 2010, 11:19:02 pm
Thanks for the answer
I do not know how to put the color code just like you  :-X :-X

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


Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
LCLImg: 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   :o  :o  :o
Title: Re: Mixing Between FCL and LCL
Post by: Leledumbo 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.
Title: Re: Mixing Between FCL and LCL
Post by: benohb 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)

Public procedures....link to FPCanvas.inc line(583)
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

 :D Try copying TFPcustomCanvas  to  Tcanvas  or Tbitmap.canvas
 





Title: Re: Mixing Between FCL and LCL
Post by: Marc on December 29, 2010, 11:55:25 am
Thanks for the answer
I do not know how to put the color code just like you  :-X :-X


instead of '['code']' use  '['code=pascal']'

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)

Public procedures....link to FPCanvas.inc line(583)
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.

Anyway what you see here is method overloading.
(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.  



Title: Re: Mixing Between FCL and LCL
Post by: benohb 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.

Anyway what you see here is method overloading.
(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. Thank you

TinyPortal © 2005-2018