How do I make Delphi 7 objects read hex values from a file and make it where I can edit it.
I want to make an Music editor for SMB 2 but, I can't seem to figure out how to make it read the hex values from the file.
Does anyone here know how to make this work?
What file? The .nes file? The data won't be stored in any particular base. Each byte contains 8 bits, which together make up a value in the range 0-255. Whether you want to look at that in decimal, hexadecimal, octal or binary form is just a matter of which textual representation is the most practical.
13, %1101, 0xD and 015 are all representations of the same value, just different ways of looking at it.
IIRC, back when I used Delphi I used a function called "blockread" to read binary files. With it you can read the whole file to an array, you can manipulate the individual bytes of the array as much as you want, and finally write it back to the file with "blockwrite".
Also, mic_ is right, there is no such thing as "reading hex values"... All files are made of bytes, and how those bytes are going to be interpreted or shown is up to the program that's handling the file.
Okay, basically what I mean is, you know how you make a level editor, and like, we'll say the value 02 will be C. 03 would be c# etc. in a hex editor,
At address we'll say $022.
And say I want the program I'm making to access that with a slider bar.
How would I go about that?
I'm not sure if I'm making enough sense here, but, all I've got to refer off of is editing values in hex editors, sou it's rather hard to explain it as a program.
Hopefully I can get my point across here. I'm not using the correct terminology.
Since we're talking small files (they are not several megabytes or gigabytes, right?) it makes sense to load a whole file to RAM, edit it there and save the whole file back to disk when the user hits "save".
Just make an array of bytes large enough to load the largest file you plan to support. Then use the BlockRead procedure to load the file into this array. With everything in the array it's really easy to seek and modify bytes, just do it like you would with any array (for example, to modify the byte at $022 to $02 you'd do byteArray[$022] := $02;).
If you want a slide bar I assume you want to show a window of X bytes and allow the user to scroll through the file, right? For that you'll need a variable to hold the index of the first element of the window, and whenever the slide bar moves that index changes accordingly. To refresh the window you just loop through X elements in the array, starting from the one pointed by the variable I mentioned above, displaying them all.
When the user hits "save" you just use BlockWrite to write the array back to the file. Look for BlockRead and BlockWrite in the language reference to find examples of how to use those commands.
Thank you. I really appreciate you for helping me out. I'm gonna try this out a bit later.
Thanks again!