Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: deletion of binary files

  1. #1

    deletion of binary files

    hi everybody,

    I've got a computing project to do and so I'm working on a database. Now the problem is that I don't know (neither can't find) how to delete binary files (within the program) that were created in the program.

    Can anyone provide me with a sample code if possible pls? I would really appreciate it!

    (Oh and as regards Validations [example: checking whether no numbers have been inserted in the 'name' field], any help on those pls aswell! But primarily the deletion of binary files is my major problem)

    Thankyou so much in advance,
    War Robe

  2. #2

    deletion of binary files

    Deleteion of any file is simply:
    Code:
    if FlieExists(FileName) then
      DeleteFile(FileName);
    As for validation, you can achieve it on two levels. For example if your using a standard Edit control (TEdit) then in its OnKeyPress event you can place code to trap and kill invalid characters:
    Code:
    procedure NameKeyPress(Sender:TObject; var Key:Char);
    begin
      if not (Key in ['A'..'Z','a'..'z']) then // check for anything but a-z
        Key := #0; // This kills the key stroke
    end;
    Take a read through the Delphi help files, and on some basic UI tutorials. Theirs lots of infomraiton out their on this type of stuff. A good resource is Tamaracka.com

  3. #3

    deletion of binary files

    Thanks so much for ur help jdarling. Regarding the 'file exists' I thought it could only be used in text files. But if it works on binary files, where should I put the coding lines pls? At the begining before creating the file?

    Cos I need to do an option that if the user selects it, then he types in the file name to be deleted and so it gets deleted.

    Thanks alot,
    War Robe

  4. #4

    deletion of binary files

    Quote Originally Posted by War Robe
    Thanks so much for ur help jdarling. Regarding the 'file exists' I thought it could only be used in text files. But if it works on binary files, where should I put the coding lines pls? At the begining before creating the file?

    Cos I need to do an option that if the user selects it, then he types in the file name to be deleted and so it gets deleted.

    Thanks alot,
    War Robe
    Well you would place the code where it would seem most appropriate according to your needs. For example if your wanting to delete an existing file before you create or download the new version then you would place the if exists and delete before you create or download.

    So for example if you have the following code:
    Code:
    procedure MyCreateNewFile;
      if SaveDialog1.Execute then
        begin
          // Your code here to create
        end;
    end;
    Then you might modify it something to this effect:
    Code:
    procedure MyCreateNewFile;
      if SaveDialog1.Execute then
        begin
          if FileExists(SaveDialog1.FileName) then
            DeleteFile(SaveDialog1.FileName);
          // Your code here to create
        end;
    end;

  5. #5

    deletion of binary files

    But is
    Code:
    DeleteFile
    a built in code? Like the
    Code:
    FileExists
    ? Beacuse it gives me an 'unknown identifier' error.

    Thanks for the rest,
    War Robe

  6. #6

    deletion of binary files

    deletefile is a procedure in the windows api
    fileexists is a function from the sysutils unit

    you need to include both in your uses clause(eg. "uses sysutils, windows;")

    Regards,
    Jeppe
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #7

    deletion of binary files

    War Robe, if you are using the TFileStream object you can overwrite files easier than these workarounds.

  8. #8

    deletion of binary files

    Quote Originally Posted by JSoftware
    deletefile is a procedure in the windows api
    Actually, DeleteFile is also declared in SysUtils unit, al least for FPC and Kylix 3 (so probably also for Delphi >= 6). For portability it's better to not use the version in Windows unit.

    So (assuming you use FPC or newer version of Delphi) it should be enough for you to add SysUtils unit to your uses clause.

  9. #9

    deletion of binary files

    oh ofcourse ops:

    i would use the sysutils version of deletefile

    you don't need the windows unit included...
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  10. #10

    deletion of binary files

    Thanks alot for the info! Although I can't fin a website where I can download the unit (since I don't have one in the units folder).

    Any suggestions pls?

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •