Solved

Error: Incompatible types: regular procedure and method pointer

Posted on 2001-06-29
3
3,157 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating manifest for my dll that called from activex 6 114
Delphi XE10, MySQL Query 4 143
Delphi selector screen 2 79
Controlled Assessment GCSE - desperate help needed 4 85
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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