tsafecall1.pp 730 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. { %TARGET=win32,win64,wince}
  2. {$ifdef fpc}
  3. {$mode objfpc}
  4. {$endif}
  5. uses
  6. SysUtils;
  7. type
  8. TTest = class
  9. public
  10. procedure SomeError; safecall;
  11. function SafeCallException(ExceptObject: TObject; ExceptAddr: Pointer): HResult; override;
  12. end;
  13. var
  14. ExceptObj: TObject;
  15. Handled: Boolean;
  16. procedure TTest.SomeError; safecall;
  17. begin
  18. ExceptObj := Exception.Create('SomeException');
  19. raise ExceptObj;
  20. end;
  21. function TTest.SafeCallException(ExceptObject: TObject; ExceptAddr: Pointer): HResult;
  22. begin
  23. if ExceptAddr = nil then
  24. halt(2);
  25. if ExceptObject <> ExceptObj then
  26. halt(3);
  27. Handled := True;
  28. Result := 0;
  29. end;
  30. begin
  31. Handled := False;
  32. TTest.Create.SomeError;
  33. if not Handled then
  34. halt(1);
  35. end.