passing a picturebox as an argument - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

passing a picturebox as an argument

I'm trying to learn some Delphi
I know how to code in VisualBasic6

I just want to write down some routines that I might use again and again.

In VB6 I would write

sub drawGrid(pict as picturebox, x as integer, y as integer)
code to draw the grid overhere (just y+1 horizontal and x+1 vertical lines)

In delphi
I managed to draw a grid within a unit that belongs to the form itself, but now i want to write down the same code in a general way
So I want to pass the object were I draw on as an argument.

next I want to write doen
pict.canvas. etcetera to draw the grid

but it just didn't work.

Hope this question is clear and hope someopne is able to explain what I should do. Lots of thanks to those helpfull

Comments

  • zibadianzibadian Posts: 6,349Member
    : I'm trying to learn some Delphi
    : I know how to code in VisualBasic6
    :
    : I just want to write down some routines that I might use again and again.
    :
    : In VB6 I would write
    :
    : sub drawGrid(pict as picturebox, x as integer, y as integer)
    : code to draw the grid overhere (just y+1 horizontal and x+1 vertical lines)
    :
    : In delphi
    : I managed to draw a grid within a unit that belongs to the form itself, but now i want to write down the same code in a general way
    : So I want to pass the object were I draw on as an argument.
    :
    : next I want to write doen
    : pict.canvas. etcetera to draw the grid
    :
    : but it just didn't work.
    :
    : Hope this question is clear and hope someopne is able to explain what I should do. Lots of thanks to those helpfull
    :
    You should write the code in a procedure, and pass the box as a parameter of that procedure. Here is an example, which changes the Caption of a label:
    [code]
    procedure ChangeCaption(Label: TLabel);
    begin
    Label.Caption := 'Something else';
    end;
    [/code]
    You can now call that procedure using a normal statement:
    [code]
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    ChangeCaption(Label1); // Changes caption of Label1
    end;
    [/code]

Sign In or Register to comment.