Einzelnen Beitrag anzeigen

Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.453 Beiträge
 
Delphi 12 Athens
 
#26

AW: Warum gibt es hier eine Acess Violation?

  Alt 11. Dez 2018, 07:23
Und da steht es ja auch schon genauso drin, daß es in dieser Situation crasht:

Zitat:
There is, however, a pitfall in the above example -
if the "inner" routine references any variable that was pushed onto
the stack before the "inner" procedure was called from testpass
(calltestpass parameters - if there were any, or local variables in
calltestpass - if there were any), your system most probably crashes:

Delphi-Quellcode:
{ This code compiles OK but generates runtime exception (could even be
  EMachineHangs :-) ) }

procedure testpass(p: pointer);
begin
  tProcedure(p);
end;
procedure calltestpass;
var msg: string;
 procedure inner;
 begin
   msg := 'hello';
   showmessage(msg);
 end;
begin
  testpass(@inner);
end;
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat