델파이를 사용하여 .txt 파일을로드하고 이진 파일로 바이트 값을 읽으려고합니다. 나는 바이트로 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]
'x'가 바이트 인 경우, 'IntToHex (x, 2)'는 두 자리 16 진수의 텍스트 표현입니다. –
감사합니다. 나는이 방법을 사용했고, 이제 내가 원했던 16 진수 값을 얻는다. 지금 바이너리로 변환하려고 노력할 것입니다. – HHH
사용자가 OpenDialog에서 * Cancel * 버튼을 눌렀을 때 코드가 파일을로드하는 이유는 무엇입니까? –