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!
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to