Autor Beitrag
FriFra
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 07.10.02 21:01 
Wie deklariere ich eigentlich eine function, wenn ich einige Parameter nur Optional haben will??

MyFunction([MyParam1],[MyParam2],[MyParam3])
patmann2001
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 201

Windows 7 Prof.
Delphi XE2
BeitragVerfasst: Mo 07.10.02 21:44 
Hallo
Der Befehl dazu heißt "overload".
Das Beispiel aus der Hilfe von Delphi:
ausblenden Quelltext
1:
2:
3:
4:
function Func(X: Real; Y: Integer): Real; overload;
...
function Func(X: Integer; Y: Real): Real; overload;
...

Wie du siehst, sind hier verschiedene Variablenzuweisungen gemacht worden.

cu Patmann
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 07.10.02 22:07 
Danke :D

Da hab ich mal wieder was dazugelernt...
Alibi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458

Win2K SP3
Delphi 6 Ent
BeitragVerfasst: Mo 07.10.02 22:14 
function blubb(a: integer; b: String = "bla");

Wenn Parameter b nun nicht gegeben wurde wird "bla" verwendet.
Wie bei Inc und Dec.
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Mo 07.10.02 23:48 
Hallo,
Alibi hat folgendes geschrieben:
function blubb(a: integer; b: String = "bla");

wenn du einfache Quotes verwendest und einen Rügabewert angibst bin ich einverstanden ;)
ausblenden Quelltext
1:
function blubb(a: integer; b: String = 'bla') : Real;					


Gruß
Klabautermann
SMI
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 106

Win95-2003 / Debian / Suse
D1/D3/D6/D7
BeitragVerfasst: Di 08.10.02 17:09 
Einen Kritikpunkt habe ich, dein Beispiel mit dec und inc ist schlecht, da diese Befehle wie die Casts, die Grundrechenarten und eigentlich alle reservierten Worte vom Präprocessor gestellt werden.
Leider ist hier die Delphi Hilfe fehlerhaft, die beschreibt, dass man Dec und Inc als Funktionen in der Unit System wiederfinden, in VC würde man sie besser und passenderweise als Macros bezeichnen.
Pascal und Objekt Pascal konnte bis einschließlich Delphi 3 nicht überladen, und INC sowie Dec standen seit den ersten Pascal Versionen zur Verfügung, also lange bevor Delphi, das Licht der Welt erblickte.

SMI

_________________
Wenn es im Jahre 1879 schon Computer gegeben hätte, würden diese vorausgesagt haben, daß man infolge der Zunahme von Pferdewagen im Jahre 1979 im Pferdemist ersticken würde.
(John C. Edwards, brit. Zukunftsforscher)