| 9 a |
| Would you like to react to this message? Create an account in a few clicks or log in to continue. |
Code4bin Delphi 2021 — Premiumvar // Example data to write DataToWrite: array[0..9] of Byte = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); DataRead: array[0..9] of Byte; i: Integer; BinaryFile: File of Byte; // Display the read data Writeln('Data read from example.bin:'); for i := 0 to 9 do Write(DataRead[i], ' '); code4bin delphi 2021 // Open the file for reading Reset(BinaryFile); var // Example data to write DataToWrite: array[0 except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; DataRead: array[0..9] of Byte begin try // Assign and open the file for writing AssignFile(BinaryFile, 'example.bin'); Rewrite(BinaryFile); // Write data to the file for i := 0 to 9 do Write(BinaryFile, DataToWrite[i]); // Close the file CloseFile(BinaryFile); // Close the file CloseFile(BinaryFile); Readln; // Pause before exiting end. This program uses a typed file ( File of Byte ) to directly read and write Byte values. This approach simplifies working with binary data, but you can also use an untyped file ( File ) for more complex or larger data structures by using BlockRead and BlockWrite . |