Solved

Error: Incompatible types: regular procedure and method pointer

Posted on 2001-06-29
3
3,120 Views
Last Modified: 2012-06-21
I am getting an error (Incompatible types: regular procedure and method pointer) when using procedural types in the following maner:
TMyClass = class
  private
   function compare(a,b: integer): byte;
   procedure someProcedure;
end; {TMyClass}

procedure TMyClass.someProcedure;
begin
  mySort(compare);
end;

I have a unit called sort...

unit sort;
type
  compFunc = function (a,b: integer) : byte;

procedure mysort(compare: compFunc);
begin
  ...
end;

I can't figure out why I am getting this error message.
Thanks in advance
jeco
0
Comment
Question by:jeco
3 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6238318
Hi jeco,

it declared as function (a,b: Integer): byte  "of object".

you should declare
type
  compFunc = function (a,b: integer) : byte; of object;
and assign it not for standalone function, but for object method.

another way to pass address of function as parameter

type
  TMyClass = ...
  ...
   function compare(Proc: CompFunction);
  end;


function TMyClass.Compare(Proc: CompFunction);
begin
   if Proc(A, B) = 0 ...
....

-----
Igor.
0
 
LVL 3

Accepted Solution

by:
alzv earned 100 total points
ID: 6238325
You receive such message because you are trying to pass a method pointer as a parameter. But your procedure can only retrieve an entry point of regular function not a class method. If you want to pass a method into your procedure you need to modify CompFunc type declaration like this:

type
  CompFunc = function (a,b: integer) : byte of object;

Or if you want to pass both types of procedures (regular and methods) you need to overload your MySort procedure like this:

type
  CompFunc = function (a,b: integer) : byte;
  CompFuncMethod = function (a,b: integer) : byte of object;

procedure MySort(Compare: CompFunc); overload;
procedure MySort(Compare: CompFuncMethod); overload;

Best regards,
Alexey Zverev.
0
 

Author Comment

by:jeco
ID: 6239262
Thanks igor and Alexey for your answers. Both answers worked but since I ended up using overload procedures I will give the points to Alex
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now