In-depth method (10)-default parameters

// Point 10: Both procedures and functions can have one or more default parameters; but they must be behind non-default parameters 
function MyFun (s1: string ; s2: string = ' good guy ' ): string ;
 begin 
  Result: = s1 + s2 ;
 end ;

{ Call } 
procedure TForm1.Button1Click (Sender: TObject);
 var 
  str1, str2: string ;
 begin 
  str1: = ' in case ' ;
  str2: = ' bad guy ' ;

  ShowMessage (MyFun (str1));       {In case of good people }

  ShowMessage (MyFun (str1, str2)); {In case of badass } 
end ;

 

Guess you like

Origin www.cnblogs.com/fansizhe/p/12729700.html