How does Delphi resolve overloaded functions with pointers to (impersonal) parameters?

Below are a few overloaded features. Try to guess which function will be called.

program Project2;
    {$APPTYPE CONSOLE}

uses
  Types, SysUtils;

procedure Some(const Buf); overload;
  begin
    Writeln('const-typeless')
  end;

//procedure Some(var Buf); overload;
//  begin
//    Writeln('var-typeless')
//  end;

//procedure Some(Buf :TByteDynArray); overload;
//  begin
//    Writeln('Byte dynamic array');
//  end;

procedure Some(Buf :array of Byte); overload;
  begin
    Writeln('Byte open array');
  end;

procedure Some(Buf :TArray<Byte>); overload;
  begin
    Writeln('TBytes AKA byte generic array');
  end;

//procedure Some(Buf :TBytes); overload;
//  begin
//    Writeln('TBytes AKA byte generic array');
//  end;

var p: pointer;

begin
  try
    { TODO -oUser -cConsole Main : Insert code here }
    WriteLn ('Calling overloaded procedure with Pointer parameter:');

    Write('  * nil: '); p := nil; Some(p);
    Write('  * garbage: '); p := Pointer(1); Some(p);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;

  ReadLn;
end.

In fact, the 1st number is called and issues AV to 2ndcall. Given that the old VCL pattern uses Pointer and Integer interchangeably (for example, TList and TStrings.Objects and TWinControl.Tag), which can cause unexpected AV requests on fairly regular code.

{$ T +} , Delphi , ^ Byte . p: PInteger; . / -, generic-array. - , , " " . , - .

/ , , , PInteger?

PS. QC 109019

+5
1

, , , , .

noeless , . , , . .

, .

  • , Pointer, , . , .
  • , . - .

, Pointer . , , , .

+5

All Articles