Autor Beitrag
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Fr 26.10.07 15:41 
Hallo,

in C++ ist es ja möglich eine Funktion zu definieren, der man beliebig viele Parameter gleichen Typs mitgeben kann.

Oder auch bei Delphi die Procedure Write().

Wie deklariere ich bei Delphi so eine Funktion?

Ich hoffe ihr könnt mir helfen, das wäre nähmlich grade echt praktisch.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 26.10.07 15:46 
Jein. man kann zwar keine Prozeduren/Funktionen mit variabler anzahl Parameter schreiben, man kann Parameter aber mit Defaultwerten belegen, dann muss man diese beim Aufruf nicht übergeben.

_________________
Markus Kinzler.
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Fr 26.10.07 15:49 
Hoffe ich habe deine Frage richtig verstanden. Eigentlich sieht das so aus:
ausblenden Delphi-Quelltext
1:
procedure proc_name(Parameter1, Parameter2, ParameterX: Integer);					

Hoffe, ich konnte helfen.


Zuletzt bearbeitet von Jakob_Ullmann am Fr 26.10.07 15:51, insgesamt 1-mal bearbeitet
Jakob Schöttl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Fr 26.10.07 15:51 
ok, dann gebe ich mal vllt 10 Parameter mit Default-Werten an, oder ich mach ein Array...

Bisschen schade, weißt du wieso das dann bei dieser Write-Procedure geht? Wahrscheinlich ist die sozusagen eingebaut.
Jakob Schöttl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Fr 26.10.07 15:56 
user profile iconJakob_Ullmann hat folgendes geschrieben:
Hoffe ich habe deine Frage richtig verstanden. Eigentlich sieht das so aus:
ausblenden Delphi-Quelltext
1:
procedure proc_name(Parameter1, Parameter2, ParameterX: Integer);					

Hoffe, ich konnte helfen.

nein, ich meinte eben dass man, wenn die Procedure schon deklariert und implementiert und fertig ist, beliebig viele Parameter beim Aufruf angeben kann, ohne alle (zb) 100 in der Deklaration geschrieben zu haben.

Bei C++ sieht das glaub ich so aus, und dann kann man mit Hilfe von Makros mit den Parametern arbeiten:
ausblenden C#-Quelltext
1:
int func(int anzahl, ...) ;					
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 26.10.07 16:02 
Guck dir mal const Args: array of const an, wie es von der Funktion Format verwendet wird.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure Foobar(args: array of const);
begin
  ShowMessage(IntToStr(Length(args)));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Foobar(['Test1''Test2'42]);
end;
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 26.10.07 16:10 
Moin!

user profile iconalzaimar hat hier vor Kurzem eine Demo dazu gepostet. :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 27.10.07 21:37 
Alternativ kann man nen kleinen Hack machen, der allerdings nen C-Compiler erfordert:

Man schreibt die besagte Funktion in C und nutzt hierbei als Aufruf-Konvention __cdecl. In Delphi bindet man nun die Object-File von C mit {$O function.obj} ein und deklariert die besagte Funktion als externalcdeclvarargs;. Ist zwar nicht sauber, geht aber :P

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Jakob Schöttl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: So 28.10.07 11:59 
ah, das array of const ist super, danke!