Mega Code Archive

 
Categories / Delphi / Examples
 

Calling deletefile function

Question: I want to call the Windows DeleteFile() function, but I get the error "Incompatible types: 'string' and 'Pointer'" when compiling. How can I get around this? Answer: The DeleteFile() procedure is declared both in the SysUtils unit and the Windows unit. The following example demonstrates calling both procedures. The version declared in the SysUtils unit accepts strings, and the Windows version accepts PChars. procedure TForm1.Button1Click(Sender: TObject); var s : string; a : array[0..MAX_PATH - 1] of char; begin s := 'C:\SomeFile'; SysUtils.DeleteFile(s); a := 'C:\SomeFile'; Windows.DeleteFile(@a); end;