Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Reusing the control

Help
sippy
2011-02-21
2013-04-30
  • sippy
    sippy
    2011-02-21

    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?

     
  • Bernhard Elbl
    Bernhard Elbl
    2011-02-26

    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

     
  • sippy
    sippy
    2011-04-04

    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.

     
  • sippy
    sippy
    2011-04-04

    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.