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 8586395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:18:03+00:00 2026-06-11T22:18:03+00:00

Below are few overloaded functions. Try to guess which function of those would get

  • 0

Below are few overloaded functions.
Try to guess which function of those would get 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 2nd one is called and throws AV on its 2nd call.
Given old VCL pattern of using Pointer and Integer interchangeably (such as TList and TStrings.Objects and TWinControl.Tag) that may cause unexpected AVs on a rather regular code.

{$T+} does not change the behavior, so it was not that Delphi thinks ^Byte is Pointer.

However declaring p: PInteger; fixes it. Also the open-array variant is not called for pointer, and is treated/name-mangled differently than generic-array variant. Dynamic array is name-mangled differently from generic array, so both can be used, yet at the call site ambiguous overload error would happen if both uncommented. However, if to compile with generic array disabled and dinamic array uncommented – the same weird behavior happens.

Why does the compiler resolve to dynamic/generic array when parameter is a Pointer, and resolve to constant typeless when parameter is PInteger ?

  • Related: How does Delphi resolve overloaded functions with integral parameters?
  • Related: why two aliases to "array of string" treated differently?
  • Related: QC 108978
  • Code from: http://www.sql.ru/forum/actualthread.aspx?tid=970289

PS. Opened QC 109019

  • 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-11T22:18:04+00:00Added an answer on June 11, 2026 at 10:18 pm

    There’s no documentation for this, so the best we can do is poke at the compiler and try to guess the reasoning behind its behaviour.

    Now, a procedure with a typeless parameter can be passed any parameter, irrespective of its type. So, any sane overload resolution scheme has to consider the typeless parameter last, only when it has exhausted all other possible candidates. Otherwise it would always be chosen.

    So with that, the behaviour can be explained.

    • When your parameter is of type, Pointer, that is assignment compatible with a dynamic array. Which means that the dynamic array overload can be selected.
    • When your parameter is any other pointer type, it is not assignment compatible with a dynamic array. And so the overload resolution falls back to the final possible candidate, the typeless parameter.

    Ultimately this behaviour comes down to the fact that the compiler considers Pointer to be assignment compatible with any dynamic array. That this statement is fact is easy to confirm by experiment, however, I cannot find documentation for it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a few overloaded methods which accept a Func parameter.
Below is my shell script from which I am trying to invoke few hive
I'd like to trim these purchase order file names (a few examples below) so
The below code works when there are a few element in the To list
I created few user defined types in my database as below CREATE TYPE [dbo].[StringID]
So im stuck on a few things in each part below, they are pretty
I have a table part with a few demo data as below in Oracle
I've spent quite a few hours trying to solve the problem described below: I've
I have a few hundred words in arrays in a plist, somewhat like below:
I have a few asp:textbox controls in a form on a webpage, below is

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.