Autor Beitrag
Yacoon
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72



BeitragVerfasst: Di 18.02.03 21:59 
Hi zusammen!
Ich habe einen einen Record, z. B.
ausblenden Quelltext
1:
2:
3:
TMyType = record
  strName : String;
end;


Es ist kein Problem einen Array von dem Typ zu deklarieren
ausblenden Quelltext
1:
aryMyType : Array of TMyType;					


Wie aber schaffe ich es, das ich eine Funktion schreibe, deren Rückgabewert vom Typ TMyType ist?
Oder geht das mit Delphi gar nicht?

Gruß
Fred Ferkel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 87



BeitragVerfasst: Di 18.02.03 22:30 
hier nur ein kleiner schnipsel aber das sollte alles sagen..;)
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
TMyType = record
  strName : String;
end;


var
  Form1: TForm1;

implementation

{$R *.DFM}

function myfunc():TMyType;
begin
  result.strName:='TEST';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage(myfunc().strName);
end;

cya
Yacoon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72



BeitragVerfasst: Mi 19.02.03 07:15 
naja der code behebt nicht mein Problem. Das Ergebnis sollte vom Typ array of TMyType sein.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
TMyType = record 
  strName : String; 
end; 


var 
  Form1: TForm1; 

implementation 

{$R *.DFM} 

function myfunc():Array of TMyType; 
begin 
  result.strName:='TEST'; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  showmessage(myfunc().strName); 
end;


Ich habe den Code einfach mal geändert. Wenn du jetzt diesen Code nimmst, dann bringt er den Fehler "Bezeichner erwartet aber Array gefunden"?
Tower
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99



BeitragVerfasst: Mi 19.02.03 08:32 
Du musst vorher noch einen eigenen Typ für das Array erstellen:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
TMyType = record 
  strName : String; 
end; 
TMyArray = Array of TMyType;

var 
  Form1: TForm1; 

implementation 

{$R *.DFM} 

function myfunc():TMyArray; 
begin 
  result.strName:='TEST'; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  showmessage(myfunc().strName); 
end;


Dann funktioniert's.
Yacoon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72



BeitragVerfasst: Do 20.02.03 10:52 
Ah cool, danke, das funktioniert