AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Methodenaufrufe intern

Ein Thema von stoxx · begonnen am 10. Jun 2006 · letzter Beitrag vom 10. Jun 2006
Antwort Antwort
Benutzerbild von stoxx
stoxx

Registriert seit: 13. Aug 2003
1.111 Beiträge
 
#1

Methodenaufrufe intern

  Alt 10. Jun 2006, 17:10
ich möchte folgendes realisieren.
Die Procedure : Zwischenaufruf soll nicht wissen, ob es sich um ein TNotifyEvent oder andere Events handelt.
Sie soll einfach jedes beliebige Event weiterleiten.
Aber irgendwie fehlen mir die genauen und professionellen Kenntnisse in Delphi.
Wie würde da funktionieren (procedure Zwischenaufruf)

hmm *grübel*

Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TEvent = procedure of Object;
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    procedure ZwischenAufruf( args: array of const);
    procedure Aufruf(Sender : TObject);
    { Private declarations }
  public
    Event : TEvent;
    FMethod : TMEthod;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var NotifyEvent : TNotifyEvent;
begin
  NotifyEvent := self.Aufruf;
  FMethod := TMethod(NotifyEvent);

  zwischenAufruf([self]);
end;

//==============================================================================

procedure TForm1.ZwischenAufruf( args: array of const);
begin

    TEvent(FMethod)( args); ?!?!?


end; // ZwischenAufruf (TForm1)

//==============================================================================

procedure TForm1.Aufruf(Sender : TObject);
begin

    TForm1(Sender).Caption := 'Erfolgreich';
end; // Aufruf (TForm1)
Phantasie ist etwas, was sich manche Leute gar nicht vorstellen können.
  Mit Zitat antworten Zitat
Dax
(Gast)

n/a Beiträge
 
#2

Re: Methodenaufrufe intern

  Alt 10. Jun 2006, 17:35
Puh... Ich weiß nicht, obs funktioniert, aber mein erster Ansatz wäre soetwas:
Delphi-Quellcode:
procedure TForm1.ZwischenAufruf(args: array of const);
var i: Integer; p: Pointer;
begin
  p := FMethod.Code;
  i := Length(args);
  case i of
    0: asm
         push p
         mov eax, Self
         call [esp]
         pop p
       end;
    1: asm
         push p
         mov eax, Self
         mov edx, [edx]
         mov edx, [edx]
         call [esp]
         pop p
       end;
    2: asm
         push p
         mov eax, Self
         mov edx, [edx]
         mov ecx, [edx+4]
         mov edx, [edx]
         call [esp]
         pop p
       end;
    else
      asm
        mov eax, args
        mov eax, [eax]
        mov ecx, [eax-4]
        mov edx, [edx]
      @_l:
        push [edx+ecx*4]
        cmp ecx, 2
        jnz @_1

        mov ecx, [edx+4]
        mov edx, [edx]
        call p
      end
  end;
end;
Ist ungetestet.. Grad so runtergeschrieben eben. Um Assembler wirst du bei diesem Vorhaben jedenfalls nicht rumkommen...
  Mit Zitat antworten Zitat
Alt 10. Jun 2006, 17:51     Erstellt von omata
Dieser Beitrag wurde von gelöscht.
Benutzerbild von stoxx
stoxx

Registriert seit: 13. Aug 2003
1.111 Beiträge
 
#3

Re: Methodenaufrufe intern

  Alt 10. Jun 2006, 18:22
Hi Dax,

ASM .. hmmm .. muss das sein ?
Dein Code funktioniert leider nicht und es kommt eine Access Violation.
Der Else zweig geht gar nicht zu kompilieren, @_1 wäre unbekannt.
Der Self parameter soll nicht verwendet werden sondern aus der Variablen MEthod extrahiert.
Jetzt hab ich es mal probiert so probiert.

Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TEvent = procedure of Object;
  TIrgendeinEvent = procedure(Sender : TObject; MeineZahl : Integer) of object;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    procedure Aufruf(Sender : TObject);
    procedure Aufruf2(Sender : TObject; MeineZahl : Integer);
  public
  end;

var
  Form1: TForm1;
  procedure ZwischenAufruf(Method : TMethod; args: array of const);

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    NotifyEvent : TNotifyEvent;
    IrgendeinEvent : TIrgendeinEvent;
begin
  NotifyEvent := self.Aufruf;
  IrgendeinEvent := self.aufruf2;

  zwischenAufruf(TMethod(NotifyEvent), [self]);
  zwischenAufruf(TMethod(IrgendeinEvent), [self, 95]);
end;

//==============================================================================

procedure ZwischenAufruf(Method : TMethod; args: array of const);
var i: Integer; p: Pointer;
    self : Pointer;
begin
  p := Method.Code;
  self := Method.Data;
  i := Length(args);
  case i of
    0: asm
         push p
         mov eax, Self
         call [esp]
         pop p
       end;
    1: asm
         push p
         mov eax, Self
         mov edx, [edx]
         mov edx, [edx]
         call [esp]
         pop p
       end;
    2: asm
         push p
         mov eax, Self
         mov edx, [edx]
         mov ecx, [edx+4]
         mov edx, [edx]
         call [esp]
         pop p
       end;
    else
      asm
// mov eax, args
// mov eax, [eax]
// mov ecx, [eax-4]
// mov edx, [edx]
// @_l:
// push [edx+ecx*4]
// cmp ecx, 2
// jnz @_1
//
// mov ecx, [edx+4]
// mov edx, [edx]
// call p
      end
  end;

end; // ZwischenAufruf (TForm1)


//==============================================================================

procedure TForm1.Aufruf(Sender : TObject);
begin
    TForm1(Sender).Caption := 'Erfolgreich';
end; // Aufruf (TForm1)

//==============================================================================

procedure TForm1.Aufruf2(Sender : TObject; MeineZahl : Integer);
var form : TForm1;
begin
  self.Caption := 'Self hat funktioniert';
  form := TForm1(Sender);
  form.Caption := form.Caption + ' Sender hat funktioniert';
  form.caption:= form.caption + ' Integer ist gekommen: ' + IntToStr(MeineZahl);
end; // Aufruf2 (TForm1)

end.
Phantasie ist etwas, was sich manche Leute gar nicht vorstellen können.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:01 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz