Einzelnen Beitrag anzeigen

Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#1

Methodenaufruf über Adresse

  Alt 29. Sep 2009, 16:16
Hallo Zusammen,

Delphi-Quellcode:
 // Methode einer TList hinzufügen
 procedure TComServ.attachCollector(routine: TRoutine);
  begin
    dataCollectors.Add(@routine);
  end;

  procedure TComServ.detachCollector(routine: TRoutine);
    begin
      dataCollectors.Delete(dataCollectors.IndexOf(@routine));
    end;
  
  // Routine für alle Listenmitglieder ausführen
  procedure TComServ.updateCollectors;
    var
      i :Byte;
      routine : TRoutine;
    begin
      if dataCollectors.Count > 0 then
        for i:=0 to dataCollectors.Count -1 do
          begin
            @routine := dataCollectors.Items[i];
            routine(self);
          end;
    end;
TRoutine schaut so aus:
TRoutine = procedure(comServ: TComServ) of object; Hinzufügen einer Routine:
comServ.attachCollector(update(comServ)); Beispiel update Routine:
Delphi-Quellcode:
  procedure TErrorLog.update(comServ: TComServ);
  begin
    debugLevel := comServ.dxtMonitorDebugLevel;
    MaxLines := comServ.dxtMonitorMaxLogLines;
    LogFilePath :=comServ.dxtMonitorLogFilePath;
  end;
Wenn nun den Properties etwas zugewiesen wird
knallt es:
---------------------------
Debugger Exception Notification
---------------------------
Project dxtMonitor.exe raised exception class EAccessViolation with message 'Access violation at address 00439DC4 in module 'dxtMonitor.exe'. Write of address 00000004'.
----------------------------------------------------

Wenn ich in der Update methode nur etwas ausgebe
funktioniert das ohne Probleme.

Es scheint, wenn ich die Update Methode über die Liste aufrufe,
dass dann die ObjectInstanz nicht bekannt ist.

Wie könnte ich das beheben oder umgehen.

Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat