Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

canvas to procedure

If I have a procedure which does some drawing on a canvas, how can I tell the procedure on WHICH canvas it should draw?
0
remcodek
Asked:
remcodek
  • 3
  • 2
1 Solution
 
mheacockCommented:
You could pass a pointer to the canvas to the procedure...

type
  PCanvas = ^Canvas;

procedure Draw (i_pCanvas: PCanvas);
begin
   ...
   i_pCanvas^.Method(...);
   ...
end;

var
  cv: PCanvas;
begin
  pcv := @Form1.Canvas;
  Draw(pcv);
end;

Or something like this...test this out before grading me.
If you have further questions, feel free to comment.
0
 
remcodekAuthor Commented:
It looks like an elegant solution, yet Delphi won't swallow the type-declaration. On PCanvas=^canvas it replies Undeclared Identifier:'canvas'. What did I do wrong?
0
 
mheacockCommented:
My mistake...I apologize...

type
   PCanvas = ^TCanvas;

I made a simple mistake in the declaration...should be TCanvas...not Canvas.  Sorry.
0
 
mheacockCommented:
Oops...also...

  cv: PCanvas;

should be

  pcv: PCanvas;

I gotta proofread my answers being clicking the submit button.
0
 
remcodekAuthor Commented:
It's very simple:

procedure(x,y:integer;wCanvas:TCanvas);

begin
  wcanvas.pixels[x,y]:=.....
end;

works just fine.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now