Closed Thread
Results 1 to 5 of 5

Thread: Writing to binary file

  1. #1
    paul. is offline Newbie
    Join Date
    Apr 2007
    Posts
    6
    Rep Power
    0

    Writing to binary file

    Ok I have only recently started with delphi and kind of got thrown in at the deep end so to speak.

    I have a blank binary file that needs strings and booleans input from several lists in .txt files at a repetative address. I am not sure how to do this.

    For example say the values in the namelist.txt were:
    Code:
    Paul
    Michael
    Andrew
    Stacy
    The output binary file needs to be something like this:
    Code:
    045061756C00000000000000000000000000000000000000000000000000000000000000
    074D69636861656C00000000000000000000000000000000000000000000000000000000
    06416E647265770000000000000000000000000000000000000000000000000000000000
    055374616379000000000000000000000000000000000000000000000000000000000000
    So it tells the length of the "name" then the "name" and every 36 bytes a name is input

    Would appreciate it if someone could help me do this.
    Thanks a lot

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    paul. is offline Newbie
    Join Date
    Apr 2007
    Posts
    6
    Rep Power
    0
    All I can come up with is this, it allows me to write Hello every 8 bytes

    Code:
    var
      binString1, myString2: shortString;
      binFile : File of string[8];
    
    begin
      AssignFile(binFile, 'Test.bin');
      ReWrite(binFile);
    
      binString1 := 'Hello';
      binString2 := 'Hello';
      Write(binFile, binString1, binString2);
    
      CloseFile(binFile);
    
    end;
    This deletes the old file and writes to a new one. Also doesnt allow me to position where the bytes are input to.

    Thanks

  4. #3
    paul. is offline Newbie
    Join Date
    Apr 2007
    Posts
    6
    Rep Power
    0
    Done it now nevermind thanks for reading

  5. #4
    Jordan Guest
    That was fast, what was your solution?

  6. #5
    paul. is offline Newbie
    Join Date
    Apr 2007
    Posts
    6
    Rep Power
    0
    It was under my nose the whole time, I just didnt realise it was compatable with binary and strings. I used TMemoryStream, which allowed me to adjust the position and then saved the memory stream to a file.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Binary file modification
    By eafkuor in forum C and C++
    Replies: 7
    Last Post: 04-18-2011, 09:29 AM
  2. copying binary file in C
    By nerio in forum C and C++
    Replies: 4
    Last Post: 11-27-2010, 05:06 AM
  3. C++ Writing Binary Files?
    By AtoZ in forum C and C++
    Replies: 1
    Last Post: 01-31-2010, 11:14 AM
  4. ASP: Saving binary to file
    By s0mmer in forum ASP, ASP.NET and Coldfusion
    Replies: 9
    Last Post: 01-23-2010, 03:10 AM
  5. Determine if a file is binary
    By Nightracer in forum C# Programming
    Replies: 5
    Last Post: 09-16-2006, 12:26 PM

Tags for this Thread

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