Recent

Author Topic: Mode Delphi  (Read 3384 times)

typo

  • Hero Member
  • *****
  • Posts: 3051
Mode Delphi
« on: June 21, 2013, 10:07:57 am »
I am porting a Delphi code which runs fine on Delphi mode, but what the correspondent way on ObjectFP mode?

The code is:

Code: [Select]
  function StrLComp(const S1, S2: PChar; MaxLen: Integer): Integer;
  begin
    Result := SysUtils.StrLComp(S1, S2, MaxLen);
  end;

var
  Compare: function(const S1, S2: PChar; MaxLen: Integer): Integer; 
begin
    @Compare := @StrLComp;   // now compiler refuses compilation with the message "Can't assign to an adress", but it runs OK on Delphi mode
end;

Leledumbo

  • Hero Member
  • *****
  • Posts: 8244
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Mode Delphi
« Reply #1 on: June 21, 2013, 04:12:51 pm »
Code: [Select]
Compare := @StrLComp;

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Mode Delphi
« Reply #2 on: June 21, 2013, 04:26:00 pm »
I have already tried this, but the message is:

Code: [Select]
unit1.pas(841,19) Error: Incompatible types: got "<address of function(PChar,PChar,LongInt):LongInt;Register>" expected "<procedure variable type of function(const PChar,const PChar,LongInt):LongInt;Register>"

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Mode Delphi
« Reply #3 on: June 21, 2013, 04:31:15 pm »
Oh, of course, function parameters are declared as constants. I commented out this and now it compiles. Thanks.

 

TinyPortal © 2005-2018