Thema: Delphi Rekursion unterdrücken

Einzelnen Beitrag anzeigen

Dejan Vu
(Gast)

n/a Beiträge
 
#6

AW: Rekursion unterdrücken

  Alt 12. Mai 2014, 06:30
Wenn Du auf deine Aufrufkonvention verzichten könntest, dann ändere die Signatur einfach zu:
Delphi-Quellcode:
Procedure Locked (lockedCode : TMyLockedCode);
Begin
  if lockedCode.Busy then raise Exception.Create('recursion not allowed here');
  lockedCode.Busy := True;
  try
    LockedExecute(lockedCode.Code);
  finally
    lockedCode.Busy := False;
  end
End;
Eventuell kannst Du den Prozedurzeiger auch direkt hashen und dann einfach eine Hashtabelle nehmen und prüfen, so etwa (pseudocode)
Delphi-Quellcode:
Procedure Locked (lockedCode : TMethod);
var
  hash : DWORD;
Begin
  hash := MakeHash(lockedCode);
  
  if Busy[hash] then raise Exception.Create('recursion not allowed here');
  Busy[hash] := True;
  try
    LockedExecute(lockedCode());
  finally
    Busy[hash] := False;
  end
End;
Vielleicht geht #2 ja wirklich.
  Mit Zitat antworten Zitat