Recent

Author Topic: assign a function to a button-->error  (Read 4002 times)

slai

  • New Member
  • *
  • Posts: 25
assign a function to a button-->error
« on: February 14, 2007, 02:23:03 pm »
Hey there

I've got a problem, i don't know how i can assign a function to a button in an array.

my function:

Code: [Select]

                  iButtons := iButtons+1;
                  setlength(Buttons,length(Buttons)+1);
                  Buttons[iButtons] := TButton.Create(nil);
                  Buttons[iButtons].Caption := SLFeldListe[i];
                  Buttons[iButtons].Parent := panels[i];
                  Buttons[iButtons].Left := 200;
                  Buttons[iButtons].Top := round(((panels[i].Height)/2)-((Buttons[iButtons].Height)/2));
                  TButton(Buttons[iButtons]).OnClick := @ButtonVerkaufpreisClick;  

on the line

Code: [Select]
TButton(Buttons[iButtons]).OnClick := @ButtonVerkaufpreisClick;  

fbc gives me an error:
Unitdynamischedarstellung.pas(309,57) Error: Incompatible types: got "<address of local procedure(TObject);Register>" expected "<procedure variable type of procedure(TObject) of object;Register>"


what am i doing wrong?
thank you very much

greets andrew

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: assign a function to a button-->error
« Reply #1 on: February 14, 2007, 04:52:22 pm »
ButtonVerkaufpreisClick should be a method of an object for example the form.

slai

  • New Member
  • *
  • Posts: 25
RE: assign a function to a button-->error
« Reply #2 on: February 14, 2007, 05:23:01 pm »
thank you very much it works....

 

TinyPortal © 2005-2018