Einzelnen Beitrag anzeigen

Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.006 Beiträge
 
Delphi 12 Athens
 
#17

AW: Optionale (= vorbelegte) FunktionsParameter vom Type Record - Wie geht das?

  Alt 6. Jun 2021, 14:21
Auch ein overload hilft hier leider nicht weiter.
Eins nicht - sechs schon.
Um das mal zu verdeutlichen:
Delphi-Quellcode:
Function Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, c2, c3, c4, c5, c6: DoubleDouble): DoubleDouble; overload;
VAR
  Z: DoubleDouble;
Begin
  Z := c1*(Power(Re, c2) - c3);
  Z := Z*(c4*Power(Pr, c5) - c6);
  Z := Z*(1 + Power(d_i/L, 2/3));
  Result:= Z*Power(Eta/Eta_W, 0.14);
End;

Function Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, c2, c3, c4, c5: DoubleDouble): DoubleDouble; overload;
begin
  Result := Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, c2, c3, c4, c5, DoubleDouble(0.80));
end;

Function Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, c2, c3, c4: DoubleDouble): DoubleDouble; overload;
begin
  Result := Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, c2, c3, c4, DoubleDouble(0.3));
end;

Function Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, c2, c3: DoubleDouble): DoubleDouble; overload;
begin
  Result := Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, c2, c3, DoubleDouble(1.80));
end;

Function Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, c2: DoubleDouble): DoubleDouble; overload;
begin
  Result := Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, c2, DoubleDouble(230));
end;

Function Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1: DoubleDouble): DoubleDouble; overload;
begin
  Result := Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, c1, DoubleDouble(0.80));
end;

Function Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W: DoubleDouble): DoubleDouble; overload;
begin
  Result := Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, DoubleDouble(0.0235));
end;
Und die entsprechende Aufrufsequenz wäre dann in etwas so aus:
Delphi-Quellcode:
var
  Re: DoubleDouble;
  Pr: DoubleDouble;
  d_i: DoubleDouble;
  L: DoubleDouble;
  Eta: DoubleDouble;
  Wta_W: DoubleDouble;
begin
  Re := DoubleDouble(75270.7430748079);
  Pr := DoubleDouble(3.01);
  d_i := DoubleDouble(0.05);
  L := DoubleDouble(8.0);
  Eta := DoubleDouble(0.000469874);
  Eta_W:= DoubleDouble(0.000354);

  Nu:= Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W);
  WriteLn('Nu_Standard = ', Nu.ToString(TMPFloatFormat.Fixed, 4));

  Nu:= Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W, DoubleDouble(0.037), DoubleDouble(0.75), DoubleDouble(180), DoubleDouble(1), DoubleDouble(0.42), DoubleDouble(0));
  WriteLn('Nu_Variante 1 = ', Nu.ToString(TMPFloatFormat.Fixed, 4));
Sollten allerdings die optionalen Parameter eh immer mit Double- bzw. Extended-Literalen übergeben werden, dann kann man die auch gleich als Double bzw. Extended deklarieren und die Umwandlung innerhalb der Funktion machen:
Delphi-Quellcode:
Function Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W: DoubleDouble;
                                                   c1: Extended = 0.0235;
                                                   c2: Extended = 0.80;
                                                   c3: Extended = 230;
                                                   c4: Extended = 1.80;
                                                   c5: Extended = 0.3;
                                                   c6: Extended = 0.80): DoubleDouble; overload;
begin
  Result := Nu_Rohr_Turbulent(Re, Pr, d_i, L, Eta, Eta_W,
      DoubleDouble(c1), DoubleDouble(c2), DoubleDouble(c3), DoubleDouble(c4), DoubleDouble(c5), DoubleDouble(c6));
end;
Übrigens könnte man dem DoubleDouble für Win32 noch ein Explicit(Extended) spendieren.
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat