Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get rid of "W1047 Unsafe code '@ operator'" in this RaiseExeption call

The following code in Delphi 2007 gives me the warning

W1047 Unsafe code '@ operator'

in the line that passes @ThreadNameInfo to RaiseException:

procedure SetThreadName(const _Name: AnsiString);
var
  ThreadNameInfo: TThreadNameInfo;
begin
  ThreadNameInfo.FType := $1000;
  ThreadNameInfo.FName := PAnsiChar(_Name);
  ThreadNameInfo.FThreadID := $FFFFFFFF;
  ThreadNameInfo.FFlags := 0;
  try
    RaiseException($406D1388, 0, SizeOf(ThreadNameInfo) div SizeOf(LongWord),
      @ThreadNameInfo); // --> Here
  except
    // ignore
  end;
end;

Apart from disabling the compiler warning for "unsafe code", is there any other way to get rid of this warning? Does this warning even make sense any more, since Delphi no longer supports dotNET?

I tried to explicitly typecast the parameter to PDWord (the declared type of the last parameter), which didn't change anything.

like image 542
dummzeuch Avatar asked Mar 10 '23 07:03

dummzeuch


1 Answers

This warning is intended for use with code that is to be compiled by the .net compiler. If you are not using the Delphi .net compiler you can, and should, suppress that particular warning.

like image 52
David Heffernan Avatar answered May 09 '23 21:05

David Heffernan