Default Parameters



Default Parameters
Pas2JS pascal source code
type TTest = class FInteger: Integer; FString: String; FFloat: Float; FBoolean: Boolean; constructor CreateInt(i: Integer = 123); constructor CreateStr(s: String = 'ABC'); constructor CreateFloat(f: Float = 12.3); constructor CreateBoolean(b: Boolean = True); procedure SetInt(i: Integer = 456); procedure SetStr(s: String = 'DEF'); procedure SetFloat(f: Float = 4.56); procedure SetBoolean(b: Boolean = True); procedure WriteLnOut; end; constructor TTest.CreateInt(i: Integer = 123); begin FInteger := i; end; constructor TTest.CreateStr(s: String = 'ABC'); begin FString := s; end; constructor TTest.CreateFloat(f: Float = 12.3); begin FFloat := f; end; constructor TTest.CreateBoolean(b: Boolean = True); begin FBoolean := b; end; procedure TTest.SetInt(i: Integer = 456); begin FInteger := i; end; procedure TTest.SetStr(s: String = 'DEF'); begin FString := s; end; procedure TTest.SetFloat(f: Float = 4.56); begin FFloat := f; end; procedure TTest.SetBoolean(b: Boolean = True); begin FBoolean := b; end; procedure TTest.WriteLnOut; begin WriteLn(IntToStr(FInteger) + ',' + FString + ',' + FloatToStr(FFloat) + ',' + BoolToStr(FBoolean)); end; procedure WriteLnInt(i: Integer = 789); begin WriteLn(IntToStr(i)); end; procedure WriteLnStr(s: String = 'IJK'); begin WriteLn(s); end; procedure WriteLnFloat(f: Float = 78.9); begin WriteLn(FloatToStr(f)); end; procedure WriteLnBoolean(b: Boolean = True); begin WriteLn(BoolToStr(b)); end; { main.pas } var t: TTest; Begin TTest.CreateInt(1).WriteLnOut; TTest.CreateInt.WriteLnOut; TTest.CreateStr('zzz').WriteLnOut; TTest.CreateStr.WriteLnOut; TTest.CreateFloat(3.14).WriteLnOut; TTest.CreateFloat.WriteLnOut; TTest.CreateBoolean(False).WriteLnOut; TTest.CreateBoolean(True).WriteLnOut; TTest.CreateBoolean.WriteLnOut; WriteLn(''); WriteLn('---'); WriteLn(''); t := TTest.Create; t.WriteLnOut; t.SetInt; t.WriteLnOut; t.SetInt(2); t.WriteLnOut; t.SetStr; t.WriteLnOut; t.SetStr('aaa'); t.WriteLnOut; t.SetFloat; t.WriteLnOut; t.SetFloat(2.5); t.WriteLnOut; t.SetBoolean; t.WriteLnOut; t.SetBoolean(False); t.WriteLnOut; WriteLn(''); WriteLn('---'); WriteLn(''); WriteLnInt; WriteLnInt(1); WriteLnStr; WriteLnStr('bbb'); WriteLnFloat; WriteLnFloat(1.5); WriteLnBoolean; WriteLnBoolean(True); WriteLnBoolean(False); { <<<<<<<<<<<< CONSOLE OUTPUTS >>>>>>>>>>>>>>>>>>> 1,,0,False 123,,0,False 0,zzz,0,False 0,ABC,0,False 0,,3.14,False 0,,12.3,False 0,,0,False 0,,0,True 0,,0,True --- 0,,0,False 456,,0,False 2,,0,False 2,DEF,0,False 2,aaa,0,False 2,aaa,4.56,False 2,aaa,2.5,False 2,aaa,2.5,True 2,aaa,2.5,False --- 789 1 IJK bbb 78.9 1.5 True True False }