Autor Beitrag
bms
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 735

Win XP
Delphi 3, Delphi 6 PE, Delphi 2005 PE
BeitragVerfasst: Sa 20.03.04 18:31 
Wie kriege ich es hin einer Prozedur mitzuteilen welche Prozedur sie aufrufen soll. Hier ein Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure aaa;
begin
   ShowMessage('aaa');
end;

procedure bbb;
begin
   ShowMessage('bbb');
end;

procedure ccc(Hier_Prozedur_Name);
begin
  ???
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   ccc(aaa);
end;


Verstanden? Ich will aus Button1 Prozedur die Prozedur ccc aufrufen und ihr per Parameter sagen welche Prozedur sie ihreseits benutzen soll. Ich glaube, daß sowas geht. Nur wie? Und wenn es geht, geht es auch mit Funktionen?
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 20.03.04 18:39 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure ccc(ProcName: String);
begin
  if ProcName = 'aaa' then
    aaa
  else if ProcName = 'bbb' then
    bbb
  else
    ShowMessage('Unbekannte Prozedur');
end;

Einfacher gestalltet es sich wenn du einen Integer übergibst, dann kannst du die Verzweigung mit case machen.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 20.03.04 18:41 
Oder so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
type
  myProz = procedure;


implementation

procedure aaa;
begin
  ShowMessage('aaa');
end;

procedure bbb;
begin
  ShowMessage('bbb');
end;

procedure makeItSo(temp : MyProz);
begin
  temp;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  makeItSo(aaa);
end;

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
bms Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 735

Win XP
Delphi 3, Delphi 6 PE, Delphi 2005 PE
BeitragVerfasst: Sa 20.03.04 21:49 
@Luckie

Das wäre ein wenig zu einfach gewesen, aber danke für den Versuch.

@Peter Lustig

Genau das habe ich gesucht. Ich dachte zuerst, dass es das Ding mit dem @, also der Callbackfunktion sein wird, aber das ist auch ok.
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: Di 06.04.04 23:48 
sodele... vom prinzip her hat mir das geholfen und funkioniert auch...
mein Problem ist allerdings noch etwas komplexer...
und zwar ist bei mir "makeitso" eine Prozedur einer Klasse 1
und aaa eine Prozedur einer anderen Klasse 2
hat irgendwer ne ahnung, wei man das hinbekommen kann? *hoff*
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 07.04.04 10:57 
Wie siehts mit...

ausblenden Delphi-Quelltext
1:
2:
type 
  myMethod = procedure of object;


...aus?

_________________
mfg.
mâximôv
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: Mi 07.04.04 11:15 
weiterhin die Fehlermeldung
Zitat:
[Fehler] un_menu.pas(167): Inkompatible Typen: 'Methodenzeiger und reguläre Prozedur'

:(
EDIT: nein, es funktioniert doch!! DAnke an alle!