We help IT Professionals succeed at work.

canvas to procedure

remcodek
remcodek asked
on
Medium Priority
293 Views
Last Modified: 2010-04-04
If I have a procedure which does some drawing on a canvas, how can I tell the procedure on WHICH canvas it should draw?
Comment
Watch Question

Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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?

Commented:
My mistake...I apologize...

type
   PCanvas = ^TCanvas;

I made a simple mistake in the declaration...should be TCanvas...not Canvas.  Sorry.

Commented:
Oops...also...

  cv: PCanvas;

should be

  pcv: PCanvas;

I gotta proofread my answers being clicking the submit button.

Author

Commented:
It's very simple:

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

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

works just fine.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.