Autor Beitrag
soisseteben
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

Win XP
D7
BeitragVerfasst: Mo 26.06.06 20:49 
ist es möglich eine Funktion o.ä. so zu gestalten, das sie mehrere Rückgabewerte liefert. Wenn ja, wie deklariert und nutz ich die dann?

danke im vorraus!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 26.06.06 20:54 
Der Rückgabewert eine Funktion ist nur einer.
Du kannst aber einen Parameter als Var-Parameter übergeben und dort die neunen Werte eintragen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Function Differenz (var Summe : Integer; Wert1, Wert2 : Integer) : Integer;
begin
  Result := Wert1-Wert2;
  Summe := Wert1+Wert2;
end;
soisseteben Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

Win XP
D7
BeitragVerfasst: Mo 26.06.06 21:00 
danke! und wie nutz ich 'summe' dann in der Prozedur, wo ich diese Funktion aufrufe (wie les ich den in eine Variable ein?)
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 26.06.06 21:03 
Die variable, die du der Funktion übergibst hat nach dem Aufruf automatisch den Wert, da ja by-reference übergeben wird.

_________________
Markus Kinzler.
root_at_localhost
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 191



BeitragVerfasst: Mo 26.06.06 21:06 
zum beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Function Differenz (var Summe : Integer; Wert1, Wert2 : Integer) : Integer;
begin
  Result := Wert1-Wert2;
  Summe := Wert1+Wert2;
end;

var
  a, b : integer;
begin
  a := Differenz(b, 21);
end.

Danach hast du in a die Differenz, also 1, und in b die Summe, also 3 stehen. Zu beachten bleibt halt, dass der erste Parameter von Differenz immer eine Variable sein muss, Konstanten wie Differenz(3, 2, 1) sind natürlich nicht möglich...
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 26.06.06 21:08 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
ErgebnisSumme, ErgebnisDifferenz, a, b : Integer;
begin
  a := 50;
  b := 180;
  ErgebnisDifferenz := Differenz(ErgebnisSumme, a, b);
  ShowMessage('Differenz: ' + IntToStr(ErgebnisDifferenz));
  ShowMessage('Summe: ' + IntToStr(ErgebnisSumme));
end;
soisseteben Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

Win XP
D7
BeitragVerfasst: Mo 26.06.06 21:48 
Danke an mkinzler, das macht Sinnn und klappt. (und natürlich auch Danke an die anderen, aber irgentwie waren eure Bsp nicht genau auf mein Problem zugeschnitten)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 27.06.06 08:56 
Natürlich nicht. Du hast ja auch eine sehr allgemeine Frage gestellt. Übertragen auf dein Problem, musst du es wohl selbst.