Autor Beitrag
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Fr 21.03.08 21:55 
Hallo,
ich stehe gerade ein wenig auf dem Schlauch.
Ich möchte im Prinzip eine Methode einer Objektinstanz an eine Prozedur (nicht Methode!) übergeben, damit diese dann in einem Array vorgehalten und ggf. aufgerufen werden kann.

Bisher verwende ich in etwa diesen Code:
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:
type
  TMyProcedure = procedure(param: string) of object;

  TMyObject = class
  public
    procedure Test(param: string);
    procedure DoIt;
  end;
procedure AddNotification(Proc: TMyProcedure);

...
implementation
var arr: array of TMyProcedure;

procedure TMyObject.DoIt;
begin
  AddNotification(Test); //[Pascal Error] uMain.pas(59): E2009 Incompatible types: 'regular procedure and method pointer'
end;

procedure AddNotification(Proc: TMyProcedure);
begin
  Arr[Index] := Proc;
end;

In der Methode DoIt tritt der markierte Fehler beim Compilieren auf.

Irgendwie stehe ich dabei gerade ein wenig auf dem Schlauch, denn ich schaffe es derzeit irgendwie nicht, aus der "regular method" einen Methodenzeiger zu machen. Sämtliche Versuche mit Pointern und Typecasts sind fehlgeschlagen. Ich schwimme derzeit etwas planlos umher..

Gruß
alias5000

_________________
Programmers never die, they just GOSUB without RETURN
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 21.03.08 22:08 
Versuch mal
ausblenden Delphi-Quelltext
1:
 AddNotification(self.Test);					

_________________
Markus Kinzler.
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Fr 21.03.08 22:11 
Leider nein. Er bringt mir dieselbe Meldung.

_________________
Programmers never die, they just GOSUB without RETURN
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 21.03.08 22:14 
Versuch mal aus der Prozedur eine Methode zu machen, ob es dann geht

_________________
Markus Kinzler.
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Fr 21.03.08 22:22 
Hm, das ist irgendwie klassisch :roll:
Ich hab gerade durch Zufall mal die dcp-Datei gelöscht, in der die Prozedur enthalten ist (sie befindet sich in einem Package) und schon geht alles.

Daran muss man mal denken, obwohl ich schon die Abhängigkeiten im Projekt eingetragen habe :?

Naja, vielen Dank trotzdem dafür Markus

Viele Grüße

_________________
Programmers never die, they just GOSUB without RETURN
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: So 23.03.08 19:01 
Normalerweise gehört da vor den Funktionszeiger auch noch ein @ davor ...
Immer diese Compilermagic ... wird dadurch nicht logischer, wenn man immer mehr weglassen darf ;-)

_________________
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.
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 24.03.08 01:43 
Da hast du aber recht! Weil eigentlich war ich ja auch davon ausgegangen, dass da irgendwas Pointerartiges (sprich v.a. @) kommen muss, da das andere ja quasi eine TMethod ist.

Dass das jetzt an einer nicht korrekt neukompilierten dcp/bpl lag, da denkt man natürlich nicht dran (weil es ja eigentlich funktionieren sollte, wenn man das Package in die Dependencies einträgt...)

Gruß
alias5000

_________________
Programmers never die, they just GOSUB without RETURN