Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function with different parameter type in Delphi

Tags:

delphi

How can I write two functions with the same name with different parameter types like this:

  public
    { Public declarations }
    function MsgW(const Msg:String):Integer;
    function MsgW(const Msg:String;title:String):Integer;


function MsgW(const Msg:String;title:String):Integer;
Begin
  Result := MessageboxW(0,Pchar(Msg),Pchar(title),MB_OK);
End;

function MsgW(const Msg:String):Integer;
Begin
  Result := MessageboxW(0,Pchar(Msg),'MessageBoxW',MB_OK);
End;
like image 818
RepeatUntil Avatar asked Mar 04 '26 06:03

RepeatUntil


1 Answers

Use overload directive

function MsgW(const Msg:String):Integer; overload;
function MsgW(const Msg:String;title:String):Integer; overload;

Overloading Methods

like image 130
Dalija Prasnikar Avatar answered Mar 07 '26 11:03

Dalija Prasnikar