Autor Beitrag
TmpDir
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53
Erhaltene Danke: 3

Win7HP Win8.1 Deb/Ubuntu
C# [Delphi 6 Pro, Delphi 2005 PE, TurboDelphi PE]
BeitragVerfasst: Do 01.06.06 14:53 
Hoffe mal der Titel ist richtig :)

ich hab ein descendant von TTreeView. Innerhalb der Komponente läuft ein aufruf auf
EnumChildWindows. Und da komme ich im Moment nicht mit zurecht.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
 type
  TWindowsListUtil = class(TtreeView)
  private
    ...
  published
    function CBEnumWinChild(WND: HWND; LPARAM: DWORD): Bool; stdcall;  

  ...

procedure TWindowsListUtil.Test();
begin
  EnumChildWindows(HWND, <span style="color: red">@CBEnumWinChild</span>, LPARAM);
end;

Da wo ROT (Zeile 12): Der Compiler verlangt immer eine Variable. Hö???
Es sollte ja nun möglich sein, einfach mit dem @ Operator dir Address der Funktion zu übergeben. Geht aber nicht.

Und die Callback-Funktion soll als Teil der Komponente enthalten sein.

Geht das, oder muss die CB-Funktion ausserhalb der Komponente deklariert sein. (Der aufruf Funktioniert dann.)

mfg

[edit] Titel geändert [/edit]

_________________
repeat :autsch: until :think:
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: Do 01.06.06 18:34 
Titel: Re: Callback Function nutzen, die in Komponente deklariert i
Hier im Forum kannst Du für Hervorhebungen den Highlight-Tag nutzen ...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
 type
  TWindowsListUtil = class(TtreeView)
  private
    ...
  published

  ...

procedure TWindowsListUtil.Test();
    function CBEnumWinChild(WND: HWND; LPARAM: DWORD): Bool; stdcall;  
    begin
        Inst = TWindowsListUtil(LPARAM);

        //Callback Source hier*
    end;
begin
    EnumChildWindows(HWND, @CBEnumWinChild, DWORD(Self));
end;


Bei dem Callback ist zu beachten, dass Du nicht direkt auf die lokalen Variablen der umhüllenden Funktion bzw. der Klasse zugreifen kannst. Du musst also, wie oben gezeigt, die Instanz als Parameter übergeben.

_________________
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.
TmpDir Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53
Erhaltene Danke: 3

Win7HP Win8.1 Deb/Ubuntu
C# [Delphi 6 Pro, Delphi 2005 PE, TurboDelphi PE]
BeitragVerfasst: Fr 02.06.06 18:10 
Titel: Danke.... :)
Vielen Dank für diese gut funktionierende Antwort.

mfg

_________________
repeat :autsch: until :think: