четвер, 29 листопада 2018 р.

Delphi warning "Unsafe type 'PChar'"

There is not only way to define it in the Delphi IDE settings by excluding raise of this type of warning.

var sa, sb: String; ca, cb: array[0..1023] of Char; … StrPCopy(ca, sa); StrPCopy(cb, sb);
  CopyFile(ca, cb, False); ...


Even better solution is to create class function:

type TCharArray = array[0..1023] of Char; ... class function TGeneralLibrary.StrToPChar(AText: String): TCharArray;
class function TGeneralLibrary.StrToPChar(AText: String): TCharArray; var cArray: TCharArray; begin StrPCopy(cArray, AText); Result := cArray; end; ...

Немає коментарів:

Дописати коментар