Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:55:13+00:00 2026-06-12T13:55:13+00:00

I have a big problem because i dont understand how the pointers really work

  • 0

I have a big problem because i dont understand how the pointers really work in delphi

First I take a function declaration from a dll.

FUNCTION:

type
  TMICRCallback   = function: Integer; stdcall;

Then I declare a Function in my code.

function CBMICRRead : Integer;stdcall;

The Function its really simple (This is an example)

function TCustomizedTenderPlugin.CBMICRRead : Integer; stdcall;
var
  SUCCESS:integer;
begin
   SUCCESS:=1;
   Result:= SUCCESS;
end;

I declare a varible like this

Respuesta : TMICRCallback;

when i try to assign this variable to my function the problem happens 🙁

Respuesta      := CBMICRRead;

This is my first time using pointers in delphi so maybe its a dumb question but please help me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:55:14+00:00Added an answer on June 12, 2026 at 1:55 pm

    TCustomizedTenderPlugin.CBMICRRead is an instance method. Which means that in order to call it you must have an instance on which to invoke it.

    On the other hand, TMICRCallback is a function pointer. It is compatible with plain functions rather than instance methods.

    They are simply not compatible. In order for TCustomizedTenderPlugin.CBMICRRead to be compatible with TMICRCallback you need to define it as:

    TMICRCallback = function: Integer of object; stdcall;
    

    The of object indicates that this type is compatible with instance methods. A variable of type TMICRCallback (as defined in this answer) holds both a function pointer and an instance pointer. It is sometimes referred to as a two pointer function type.

    Before you proceed I recommend that you read carefully the documentation.


    I note that you are using stdcall calling convention for these function pointers. This usually indicates that you are attempting interop with external modules. That’s not something that is reliable with instance methods. What I mean by this is that you cannot implement an of object instance method in a language other than Delphi. If this code is destined for use in an interop setting then you should refrain from using of object.

    For an interop setting you would normally include the instance pointer as a separate parameter. In which case the Delphi declaration would look like this:

    type
      TMICRCallback = function(Data: Pointer): Integer; stdcall;
    

    You would then implement such a function like this

    type
      TPlugin = class
        function CBMICRRead: Integer;
      end;
    
    .....
    
    function PluginCBMICRReadCallback(Data: Instance): Integer; stdcall;
    begin
      Result := TPlugin(Data).CBMICRRead;
    end;
    
    function TPlugin.CBMICRRead: Integer;
    begin
      Result := ....
    end;
    

    Finally, the function in the external module that is passed the callback would need to be passed both PluginCBMICRReadCallback and the instance pointer for the TPlugin instance. Perhaps a little like this:

    procedure RegisterCallback(Callback: TMICRCallback; Data: Pointer); stdcall;
    

    which you would call like this:

    var
      Plugin: TPlugin;
    ....
    Plugin := ...;//get this instance from somewhere
    RegisterCallback(PluginCBMICRReadCallback, Plugin);
    

    Having looked at the C++ code at the related question it seems that the C++ side of the interface looks like this:

    int WINAPI BiMICRSetReadBackFunction(int    nHandle, 
                                         int    (CALLBACK *pMicrCB)(void),
                                         LPBYTE pReadBuffSize,   
                                         LPBYTE readCharBuff,    
                                         LPBYTE pStatus,         
                                         LPBYTE pDetail); 
    

    This callback doesn’t even admit a data pointer so you cannot use an instance method at all. Quite how you are meant to implement callbacks for multiple instances is beyond me! Anyway, you can declare this function in Delphi like this:

    type
      TMICRCallback = function: Integer; stdcall;
    
    function BiMICRSetReadBackFunction(
      nHandle: Integer;
      MicrCB: TMICRCallback;
      pReadBuffSize: PByte;
      readCharBuff: PByte;
      pStatus: PByte;
      pDetail: PByte
    ): Integer; stdcall; external dllname;
    

    To call it you’ll need this:

    function MICRCallback: Integer; stdcall;//not the method of a class
    begin
      Result := ....
    end;
    .....
    retval := BiMICRSetReadBackFunction(..., MICRCallback, ....);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have big problem because i dont uderstand properly how make my homework. Well
I have got very big problem because I would like to get more information
I'm using editor from Kendo UI, so I have big problem. I don't know
I have a big problem. I use excel auto filter function, at the end
I have a big problem. I want to extract text from html table that
I have a (big) problem that all of you that work with Webforms might
I have this big function (1300+ lines of code) that takes data from the
I have big problem when I am trying to deploy my app over clickonce.
I have a big problem that a recursive treeview doesn't update any childs if
I have a big problem with my app as it crashes often but never

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.