Archive

Posts Tagged ‘move’

How to Copy / Move Files

December 15th, 1999 m3Rlin No comments

Delphi’s runtime library does not provide any routines for copying or moving files. However, you can directly call the Windows API CopyFile() function to copy a file. CopyFile() is also useful when moving files across drives because neither Delphi’s RenameFile() function nor the Windows API MoveFile() function can rename/move files across drives.

!!Note: The file attributes for the existing file are copied to the new file, but the security attributes are not.

Here’s the Delphi code:

uses
  Windows;
...
  (* sSource - (PChar or string if typecasted) The full name of the source
  **   file.
  ** sDestination - (PChar or string if typecasted) The full name of the
  **   destination file.
  ** bNoOverwrite - (Boolean) Set False if you want to overwrite existing
  **   files, else set True.
  **
  ** Function result: True if successful, else it will return False.
  *)
  CopyFile(PChar(sSource), PChar(sDestination), bNoOverwrite);
...

Examples:

{ Both examples allow file overwriting }
CopyFile('C:\\Autoexec.bat', 'A:\\Backup\\Autoexec.bat', False);
CopyFile(PChar(Edit1.Text), PChar(Edit2.Text), False);

How to Move a Component to an Exact Spot

December 15th, 1999 m3Rlin No comments

By holding the Ctrl key you can move components by 1 pixel in the Borland Delphi and Borland Kylix IDEs. Otherwise the components will be aligned to the grid (you can set the grid size in the IDEs options).