Autor Beitrag
trm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 491
Erhaltene Danke: 19

Windows 7x64
Delphi 7
BeitragVerfasst: Do 19.04.12 18:14 
Huhu.

gibt es eine Möglichkeit, wenn man alle Controls einer Form durchläuft, die Ereignisse des Controls zu löschen, ohne dass man weiss, welchem Typ das Control entspringt?

Bsp: Timer hat ja andere Ereignisse als ein Button. Normalerweise müsste ich prüfen, ob das aktuelle Control ein Button ist, dann alle Ereignisse auf nil setzen.

Geht das eleganter mit einer generischen Zuweisung?

_________________
In Erfurt gibt es eine Pension, in der es gemütlich ist, Google einfach nach Pension Fiege ;)
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 19.04.12 18:34 
Ob das so ganz sauber ist weiß ich nicht ....

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm2.Button2Click(Sender: TObject);
var
  x,y: Word;
  pl: PPropList;
  m:TMethod;
begin
  m.Code := nil;
  m.Data := nil;
  y := GetPropList(Self, pl);
  for x := 0 to y - 1 do
  begin
    if Copy(pl[x].Name, 12) <> 'On' then Continue;
    if GetMethodProp(Self, pl[x].Name).Code <> nil then
      begin
      Memo1.Lines.Add(Self.Name + ' - ' + pl[x].Name);
      SetMethodProp(Self, pl[x].Name,m);
      end;
  end;
end;


oder gekapselt ....
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Procedure RemoveEvents(O:TObject);
var
  x,y: Word;
  pl: PPropList;
  m:TMethod;
begin
  m.Code := nil;
  m.Data := nil;
  y := GetPropList(o, pl);
  for x := 0 to y - 1 do
  begin
    if Copy(pl[x].Name, 12) <> 'On' then Continue;
    if GetMethodProp(o, pl[x].Name).Code <> nil then
      begin
      SetMethodProp(o, pl[x].Name,m);
      end;
  end;
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS


Zuletzt bearbeitet von bummi am Do 19.04.12 18:38, insgesamt 1-mal bearbeitet

Für diesen Beitrag haben gedankt: trm
glotzer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 393
Erhaltene Danke: 49

Win 7
Lazarus
BeitragVerfasst: Do 19.04.12 18:37 
Hätte da auch noch eine Idee

System.TObject.FieldAddress

kurze Erklärung:
damit kann man alles was Published ist finden. Jetzt könnte man einfach alle möglichen Events durchgehen und dann auf nil setzen.
Das ist aber Arbeit und wahrscheinlich auch nicht sehr schnell.

_________________
ja, ich schreibe grundsätzlich alles klein und meine rechtschreibfehler sind absicht
trm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 491
Erhaltene Danke: 19

Windows 7x64
Delphi 7
BeitragVerfasst: Do 19.04.12 20:06 
Danke bummi, Deine Procedure war sehr hilfreich.
Wie kommt man auf so ein Konstrukt?

_________________
In Erfurt gibt es eine Pension, in der es gemütlich ist, Google einfach nach Pension Fiege ;)
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 19.04.12 23:05 
@trm
von selbst sicher nicht ;-)
Da muss erst jemand mit so seltsamen Anforderungen kommen. (just kidding)

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS