Board index » delphi » Why am I getting this error?

Why am I getting this error?

Hi all

HELP!!!    Why am I getting this error?

        Incompatible types: method pointer and regular procedure

Here is the relevant (hopefully all of it) code:

{INTERFACE}

type
 TKleurgate = array[1..4] of Tshape;
  procedure SitPenIn(Sender: TObject; Button: TMouseButton;
     Shift: TShiftState; X, Y: Integer);

type
  TKleingate = array[1..4] of Tshape;

type
  SlideType = Record
   Paneel: Tpanel;
   Kleurgate: TKleurgate;
   Kleingate: TKleingate;
  end;

var
  Slide: array[1..11] of SlideType;

{IMPLEMENTATION}

 for telkleurgate := 1 to 4 do
      begin
      slide[i].Kleurgate[telkleurgate] := Tshape.Create(BordVorm);
        slide[i].Kleurgate[telkleurgate].Shape := stCircle;
        slide[i].Kleurgate[telkleurgate].Top := -11;
        slide[i].Kleurgate[telkleurgate].Left := (telkleurgate*32)+19;
        slide[i].Kleurgate[telkleurgate].Width := 28;
        slide[i].Kleurgate[telkleurgate].Parent := slide[i].Paneel;
        slide[i].Kleurgate[telkleurgate].OnMouseDown := SitPenIn;   {ERROR OCCURS HERE}
        end;

{HERE IS THE PROCEDURE I WANT TO ASSIGN TO THE OnMouseDown event of the slide[].Kleurgate[] object}

procedure TKleurgate.SitPenIn(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  var
 Houer: Tshape;
 begin
   Houer := Tshape(Sender);
   Houer.Brush.Color := Kieskleur.Brush.Color;
 end;

 

Re:Why am I getting this error?


Looking at your type definition, you've declared TKleurgate as an array
of TShape,
SitPenIn is just an ordinary procedure (in your definition) and not an
object method of TKleurgate,  which is why you are getting the error
when you try to assign 1 to the other.
The difference between an object method and a regular procedure pointer:
an object method pointer points to an 8 byte value (4 byte instance of
an object & 4 byte location of method) while a regular procedural
pointer points to a 4 byte value (4 byte location of procedure).

perhaps declare your object as ( Ive only put in the code relevant to
your sample, you'll have to work on constructor, destructor etc)
follows. SitPenIn will then be a method rather than a regular procedure.

type TObjArray = Array[1..4] of TShape;

type TKleurgate = class(TObject)
  private
    ShapeArray : TObjArray;
  public
    procedure SitPenIn(Sender: TObject; Button: TMouseButton;
                       Shift: TShiftState; X, Y: Integer);
end;

In article <6e64vb$b4...@news01.iafrica.com>, Jeanne Louw
<kaml...@iafrica.com> writes

Quote
>Hi all

>HELP!!!    Why am I getting this error?

>        Incompatible types: method pointer and regular procedure

>Here is the relevant (hopefully all of it) code:

>{INTERFACE}

>type
> TKleurgate = array[1..4] of Tshape;
>  procedure SitPenIn(Sender: TObject; Button: TMouseButton;
>     Shift: TShiftState; X, Y: Integer);

>type
>  TKleingate = array[1..4] of Tshape;

>type
>  SlideType = Record
>   Paneel: Tpanel;
>   Kleurgate: TKleurgate;
>   Kleingate: TKleingate;
>  end;

>var
>  Slide: array[1..11] of SlideType;

>{IMPLEMENTATION}

> for telkleurg:= 1 to 4 do
>      begin
>      slide[i].Kleurgate[telkleurgate] := Tshape.Create(BordVorm);
>        slide[i].Kleurgate[telkleurgate].Shape := stCircle;
>        slide[i].Kleurgate[telkleurgate].Top := -11;
>        slide[i].Kleurgate[telkleurgate].Left := (telkleurgate*32)+19;
>        slide[i].Kleurgate[telkleurgate].Width := 28;
>        slide[i].Kleurgate[telkleurgate].Parent := slide[i].Paneel;
>        slide[i].Kleurgate[telkleurgate].OnMouseDown := SitPenIn;   {ERROR
>OCCURS HERE}
>        end;

>{HERE IS THE PROCEDURE I WANT TO ASSIGN TO THE OnMouseDown event of the
>slide[].Kleurgate[] object}

>procedure TKleurgate.SitPenIn(Sender: TObject; Button: TMouseButton;
>  Shift: TShiftState; X, Y: Integer);
>  var
> Houer: Tshape;
> begin
>   Houer := Tshape(Sender);
>   Houer.Brush.Color := Kieskleur.Brush.Color;
> end;

Kind Regards
Claire, c...@HallworthHome.demon.co.uk

Re:Why am I getting this error?


In article <6e64vb$b4...@news01.iafrica.com>, Jeanne Louw
<kaml...@iafrica.com> writes

Quote
>Hi all

>HELP!!!    Why am I getting this error?

>        Incompatible types: method pointer and regular procedure

>Here is the relevant (hopefully all of it) code:

>{INTERFACE}

>type
> TKleurgate = array[1..4] of Tshape;
>  procedure SitPenIn(Sender: TObject; Button: TMouseButton;
>     Shift: TShiftState; X, Y: Integer);

>type
>  TKleingate = array[1..4] of Tshape;

>type
>  SlideType = Record
>   Paneel: Tpanel;
>   Kleurgate: TKleurgate;
>   Kleingate: TKleingate;
>  end;

>var
>  Slide: array[1..11] of SlideType;

>{IMPLEMENTATION}

> for telkleurg:= 1 to 4 do
>      begin
>      slide[i].Kleurgate[telkleurgate] := Tshape.Create(BordVorm);
>        slide[i].Kleurgate[telkleurgate].Shape := stCircle;
>        slide[i].Kleurgate[telkleurgate].Top := -11;
>        slide[i].Kleurgate[telkleurgate].Left := (telkleurgate*32)+19;
>        slide[i].Kleurgate[telkleurgate].Width := 28;
>        slide[i].Kleurgate[telkleurgate].Parent := slide[i].Paneel;
>        slide[i].Kleurgate[telkleurgate].OnMouseDown := SitPenIn;   {ERROR
>OCCURS HERE}

I think all you need to do is use the AT operator (Thats @, if it
displays correctly on this message) before the function name this has
something to do with letting the program know that is isn't actually a
call to the function. So the line should read:

slide[i].Kleurgate[telkleurgate].OnMouseDown := @SitPenIn;

- Show quoted text -

Quote
>        end;

>{HERE IS THE PROCEDURE I WANT TO ASSIGN TO THE OnMouseDown event of the
>slide[].Kleurgate[] object}

>procedure TKleurgate.SitPenIn(Sender: TObject; Button: TMouseButton;
>  Shift: TShiftState; X, Y: Integer);
>  var
> Houer: Tshape;
> begin
>   Houer := Tshape(Sender);
>   Houer.Brush.Color := Kieskleur.Brush.Color;
> end;

--
Ian Dunn                     I...@polyhedron.com

Polyhedron Software Ltd.        
Programs for Programmers - QA, Compilers, Graphics

************ Visit our Web site on http://www.polyhedron.co.uk/ ************

Re:Why am I getting this error?


The OnMouseDown procedure NEEDS a procedure defined thus:

        ProcX := procedure(Value: Type) of Object

The *of object* bit is most important.

Quote
> Hi all

> HELP!!!    Why am I getting this error?

>         Incompatible types: method pointer and regular procedure

> Here is the relevant (hopefully all of it) code:

> {INTERFACE}

> type
> TKleurgate = array[1..4] of Tshape;
>   procedure SitPenIn(Sender: TObject; Button: TMouseButton;
>      Shift: TShiftState; X, Y: Integer);

> type
>   TKleingate = array[1..4] of Tshape;

> type
>   SlideType = Record
>    Paneel: Tpanel;
>    Kleurgate: TKleurgate;
>    Kleingate: TKleingate;
>   end;

> var
>   Slide: array[1..11] of SlideType;

> {IMPLEMENTATION}

> for telkleurgate := 1 to 4 do
>       begin
>       slide[i].Kleurgate[telkleurgate] := Tshape.Create(BordVorm);
>         slide[i].Kleurgate[telkleurgate].Shape := stCircle;
>         slide[i].Kleurgate[telkleurgate].Top := -11;
>         slide[i].Kleurgate[telkleurgate].Left := (telkleurgate*32)+19;
>         slide[i].Kleurgate[telkleurgate].Width := 28;
>         slide[i].Kleurgate[telkleurgate].Parent := slide[i].Paneel;
>         slide[i].Kleurgate[telkleurgate].OnMouseDown := SitPenIn;
> {ERROR OCCURS HERE}
>         end;

Re:Why am I getting this error?


In article <350C06E5.2...@bellsouth.net>, Jim Jensen <astro...@bellsouth.net>
writes:

Quote
>The OnMouseDown procedure NEEDS a procedure defined thus:

>    ProcX := procedure(Value: Type) of Object

>The *of object* bit is most important.

The problem is not that the procedure has not been DEFINED as "of object" but
that the procedure is NOT A METHOD of an object.
The parameters of OnMouseDown are originally correctly specified as (Sender:
TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) - not as
ProcX above, but TKleurgate is not an object containing the procedure code as a
method, and hence there is not an instance of an object with the SitPenIn()
method which can be referenced by your code.

Alan Lloyd
alangll...@aol.com

Quote
>> Hi all

>> HELP!!!    Why am I getting this error?

>>         Incompatible types: method pointer and regular procedure

>> Here is the relevant (hopefully all of it) code:

>> {INTERFACE}

>> type
>> TKleurgate = array[1..4] of Tshape;
>>   procedure SitPenIn(Sender: TObject; Button: TMouseButton;
>>      Shift: TShiftState; X, Y: Integer);

>> type
>>   TKleingate = array[1..4] of Tshape;

>> type
>>   SlideType = Record
>>    Paneel: Tpanel;
>>    Kleurgate: TKleurgate;
>>    Kleingate: TKleingate;
>>   end;

>> var
>>   Slide: array[1..11] of SlideType;

>> {IMPLEMENTATION}

>> for telkleurgate := 1 to 4 do
>>       begin
>>       slide[i].Kleurgate[telkleurgate] := Tshape.Create(BordVorm);
>>         slide[i].Kleurgate[telkleurgate].Shape := stCircle;
>>         slide[i].Kleurgate[telkleurgate].Top := -11;
>>         slide[i].Kleurgate[telkleurgate].Left := (telkleurgate*32)+19;
>>         slide[i].Kleurgate[telkleurgate].Width := 28;
>>         slide[i].Kleurgate[telkleurgate].Parent := slide[i].Paneel;
>>         slide[i].Kleurgate[telkleurgate].OnMouseDown := SitPenIn;
>> {ERROR OCCURS HERE}
>>         end;

Other Threads