我正在尝试使用 Delphi 加载 .txt 文件并以二进制文件读取文件的字节值。我正在尝试将 txt 数据作为字节获取,但我不确定它是否有效,因为我不知道如何显示字节值:
begin
// open dialog
openDialog := TOpenDialog.Create(self); // Create the open dialog object - assign to our open dialog variable
openDialog.InitialDir := GetCurrentDir; // Set up the starting directory to be the current one
openDialog.Options := [ofFileMustExist]; // Only allow existing files to be selected
if openDialog.Execute // Display the open file dialog
then ShowMessage('The file you chose is : '+openDialog.FileName)
else ShowMessage('Open file was cancelled');
// assign file.
fileName:= openDialog.FileName;
AssignFile(myFile, fileName); //ink a file on a disk to a file variable in our program
Reset(myFile); //open an existing file or Rewrite to create a new file
// get file length.
fileLength:= FileSize(myFile);
while not Eof (myFile) do
begin
begin
Read(myFile,x); // read file byte by byte
ShowMessage(x); //display the data. I'm getting an error here because ShowMessage takes a string value. Tried converting it but I can't find out how to display the binary value of the byte x
.... // [ manipulation code of binary values of bytes goes here. Not sure if this works because I don't know what x is at the moment]