The documentation states this control is re-usable, but I am having trouble clearing the bytes when I try to reuse it. For example, if I load the hexbox control with 100 bytes, then I want to load it with a new byte array of, say 10 bytes, it will overwrite the first 10 bytes and still display the other 90 bytes of the original 100 bytes. I am using what I believe to be the appropriate code to "clear" the underlying bytes in the ByteProvider class as shown in the HexEditor project included with the source code, but it does not seem to work:
if (hexViewer.ByteProvider != null)
{
IDisposable byteProvider = hexViewer.ByteProvider as IDisposable;
if (byteProvider != null)
byteProvider.Dispose();
hexViewer.ByteProvider = null;
}
Here is how I am loading the hexbox viewer:
MemoryStream ms = new MemoryStream(data);
Be.Windows.Forms.DynamicFileByteProvider prov = new Be.Windows.Forms.DynamicFileByteProvider(ms);
hexViewer.ByteProvider = prov;
Any thoughts?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried the DynamicByteProvider as you suggested, but I am still having the same problem.
There aren't any other details to provide, really. I'm just instantiating a hexbox form control:
Be.Windows.Forms. this.hexViewer = new Be.Windows.Forms.HexBox();
And then populating it with a byte array (first clearing any data, using code from the HexEditor's Cleanup() function):
if (hexViewer.ByteProvider != null)
{
IDisposable byteProvider = hexViewer.ByteProvider as IDisposable;
if (byteProvider != null)
byteProvider.Dispose();
hexViewer.ByteProvider = null;
}
hexViewer.ByteProvider = new Be.Windows.Forms.DynamicByteProvider(data);
I have also tried refreshing/invalidating the control, to no effect. And also manually deleting the bytes using hexViewer.byteProvider.DeleteBytes(), still nothing. This has to be something simple.
Any suggestions/tips are greatly appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the sample. I found the underlying problem was the bytes I was assigning to hexViewer.byteProvider belonged to a memoryStream that was not getting closed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The documentation states this control is re-usable, but I am having trouble clearing the bytes when I try to reuse it. For example, if I load the hexbox control with 100 bytes, then I want to load it with a new byte array of, say 10 bytes, it will overwrite the first 10 bytes and still display the other 90 bytes of the original 100 bytes. I am using what I believe to be the appropriate code to "clear" the underlying bytes in the ByteProvider class as shown in the HexEditor project included with the source code, but it does not seem to work:
if (hexViewer.ByteProvider != null)
{
IDisposable byteProvider = hexViewer.ByteProvider as IDisposable;
if (byteProvider != null)
byteProvider.Dispose();
hexViewer.ByteProvider = null;
}
Here is how I am loading the hexbox viewer:
MemoryStream ms = new MemoryStream(data);
Be.Windows.Forms.DynamicFileByteProvider prov = new Be.Windows.Forms.DynamicFileByteProvider(ms);
hexViewer.ByteProvider = prov;
Any thoughts?
Your code seems to be buggy. As you can see in Be.HexEditor you can open and close several files in a sequence without any problems.
If you have only a byte array you can also look for the DynamicByteProvider instead. A sample can be found in the "Find"- dialog.
I think you did something wrong here. Could you provide more details?
Thanks
Bernhard
Hi Bernhard,
I tried the DynamicByteProvider as you suggested, but I am still having the same problem.
There aren't any other details to provide, really. I'm just instantiating a hexbox form control:
Be.Windows.Forms. this.hexViewer = new Be.Windows.Forms.HexBox();
And then populating it with a byte array (first clearing any data, using code from the HexEditor's Cleanup() function):
if (hexViewer.ByteProvider != null)
{
IDisposable byteProvider = hexViewer.ByteProvider as IDisposable;
if (byteProvider != null)
byteProvider.Dispose();
hexViewer.ByteProvider = null;
}
hexViewer.ByteProvider = new Be.Windows.Forms.DynamicByteProvider(data);
I have also tried refreshing/invalidating the control, to no effect. And also manually deleting the bytes using hexViewer.byteProvider.DeleteBytes(), still nothing. This has to be something simple.
Any suggestions/tips are greatly appreciated.
Please take a look into the following tracker item. There is a small sample application attached.
https://sourceforge.net/tracker/?func=detail&aid=3274259&group_id=196205&atid=956524
Thanks for the sample. I found the underlying problem was the bytes I was assigning to hexViewer.byteProvider belonged to a memoryStream that was not getting closed.