Autor Beitrag
Jakyll
Hält's aus hier
Beiträge: 12



BeitragVerfasst: Fr 01.08.03 04:44 
Wie kann ich aus einer Funktion mehrere Results bekommen..
Also

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
function xyz():Integer;
begin
//rechne
Result:=x;
//rechne
Result:=y;
end;


quasi so...! Aber so bekommt man ja nur Result=y raus.
hat da vielleicht jemand ne Idee?

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Fr 01.08.03 07:18 
Du mußt VAR Parameter benutzen, wie bei einer Prozedur, oder besser gleich eine Prozedur.

_________________
Gruß
Hansa
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Fr 01.08.03 08:11 
In deinem Fall wäre eine Lösung mit Var Parametern z.B.
ausblenden Delphi-Quelltext
1:
function Rechnen(var x: Integer; var y: Integer; Zahl1, Zahl2: Integer): Integer;					


Aufrufen kannst du das dann so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var
  x, y: Integer;
begin
  Rechnen(x, y, 2025);

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Fr 01.08.03 08:17 
alternativ ein Record für die Rückgabe verwenden

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
function Rechnen(Zahl1, Zahl2: Integer):Tpoint;
  begin
    result.x := zahl1+10;
    result.y := zahl2+10;
  end;

hängt halt davon ab, wie du dein Code beim Funktionsaufruf aussehen soll.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Fr 01.08.03 09:58 
Herr Doktor, so aber nicht. :lol:

derDoc hat folgendes geschrieben:
Aufrufen kannst du das dann so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var
  x, y: Integer;
begin
  Rechnen(x, y, 2025);


Der Funktion muß er trotzdem noch einen Wert zuweisen.

ausblenden Delphi-Quelltext
1:
2:
3:
var z : integer;

z := Rechnen(x, y, 2025);


Wie gesagt, bei mehr als einem Rückgabewert nimmt man besser gleich eine Prozedur, sonst kommt man leicht durcheinander. 8)

_________________
Gruß
Hansa
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Fr 01.08.03 10:02 
oder offene Arrays oder erstellt eine Klasse die das macht (Kapselung) und greift auf Eigenschaften (properties) zurück.

grez
msch
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Fr 01.08.03 10:17 
Also ich sehe keinen Bedarf einem Wert die Funtion zuzuweisen. Du rufst sie auf und sie schreibt dir ein paar Sachen in deine Variablen.
Du musst zwar einen Rückgabewerttyp festlegen, ihn aber nicht benutzen.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.