Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2023-06

Re: fpc-pascal Digest, Vol 228, Issue 17

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rafael Picanço

Hi Tomas,

On top of your suggestion, the only way to make FPC happy is to assign nil to the type constants and then assign the corresponding pointers to them somewhere:

unit eyelink.constants
interface
const
  EXTERNAL_DEV_NONE : TGetExButtonStatesFunction = nil;
  EXTERNAL_DEV_CEDRUS : TGetExButtonStatesFunction = nil;
  EXTERNAL_DEV_SYS_KEYBOARD : TGetExButtonStatesFunction = nil;
implementation
initialization
  EXTERNAL_DEV_NONE := TGetExButtonStatesFunction(Pointer(0));
  EXTERNAL_DEV_CEDRUS := TGetExButtonStatesFunction(Pointer(1));
  EXTERNAL_DEV_SYS_KEYBOARD := TGetExButtonStatesFunction(Pointer(2));
end.
program godcastsucks;
uses eyelink.constants;
  function enable_external_calibration_device(
    buttonStatesfcn: TGetExButtonStatesFunction
    {other arguments removed for simplicity}): Int32; cdecl;
  var
    Statesfcn : TGetExButtonStatesFunction;
  begin
    if buttonStatesfcn = nil then
    begin
      WriteLn('Function is nil');
    end else begin
      WriteLn('Function is not nil');
    end;
    Result := Int32(buttonStatesfcn);
    case Result of
      0 : { do something };
      1 : { do something };
      2 : { do something }
    else
      begin
        Statesfcn := TGetExButtonStatesFunction(buttonStatesfcn);
        Statesfcn(nil);
        Result := -1;
      end;
    end;
  end;
function ExButtonStatesFunction(accdbs: PCCDBS): Int32; cdecl;
begin
  WriteLn('God casts sucks');
end;
begin
WriteLn(enable_external_calibration_device(TGetExButtonStatesFunction(EXTERNAL_DEV_CEDRUS)));
  WriteLn(enable_external_calibration_device(@ExButtonStatesFunction));
  ReadLn;
end.

Best,
R

PS. If you find a better solution, please make me known!

Reply by email