I am attempting to wrap the sidebar with a DIV, and when the sidebar is empty the DIV shouldn't be displayed

However i cannot use codes like

if(dynamic_sidebar(1))
{
  echo '<div>';
  dynamic_sidebar(1);
  echo '</div>';
}

because it will load the sidebar prior to the DIV if it's not empty, any ideas?

You could use output loading. When output loading is on, anything which may normally be echoed towards the screen is rather saved inside a buffer. After that you can test to ascertain if there's anything within the buffer before outputting your div tags.

ob_start();
dynamic_sidebar(1);
$sidebar = ob_get_clean();  // get the contents of the buffer and turn it off.
if ($sidebar) {
    echo "<div>" . $sidebar . "</div>";
}

Try:

if ( is_active_sidebar(1) )
{
  echo '<div>';
  dynamic_sidebar(1);
  echo '</div>';
}