Index: oup/current/Tools/BinEdit.dfm
===================================================================
--- oup/current/Tools/BinEdit.dfm	(revision 86)
+++ oup/current/Tools/BinEdit.dfm	(revision 87)
@@ -4,8 +4,12 @@
   OnCloseQuery = FormCloseQuery
   OnKeyUp = FormKeyUp
-  ExplicitWidth = 500
-  ExplicitHeight = 450
   PixelsPerInch = 96
   TextHeight = 13
+  inherited panel_files: TPanel
+    inherited filelist: TListBox
+      ExplicitTop = 153
+      ExplicitHeight = 270
+    end
+  end
   inherited content: TPanel
     object Splitter2: TSplitter
Index: oup/current/Tools/BinEdit.pas
===================================================================
--- oup/current/Tools/BinEdit.pas	(revision 86)
+++ oup/current/Tools/BinEdit.pas	(revision 87)
@@ -57,5 +57,5 @@
     procedure value_viewer_contextPopup(Sender: TObject);
   private
-    fileid: LongWord;
+    fileid: Integer;
   public
   end;
@@ -291,5 +291,5 @@
   if VST.RootNodeCount = 0 then
   begin
-    structs := LoadStructureDefinition(fileid);
+    structs := LoadStructureDefinition(Connection, fileid);
     if structs.Data then
     begin
Index: oup/current/Tools/Preview.dfm
===================================================================
--- oup/current/Tools/Preview.dfm	(revision 86)
+++ oup/current/Tools/Preview.dfm	(revision 87)
@@ -3,4 +3,10 @@
   PixelsPerInch = 96
   TextHeight = 13
+  inherited panel_files: TPanel
+    inherited filelist: TListBox
+      ExplicitTop = 153
+      ExplicitHeight = 270
+    end
+  end
   inherited content: TPanel
     object lbl_notpossible: TLabel
Index: oup/current/Tools/Preview.pas
===================================================================
--- oup/current/Tools/Preview.pas	(revision 86)
+++ oup/current/Tools/Preview.pas	(revision 87)
@@ -32,5 +32,5 @@
     bitmaps:   array of TBitmap;
     actualimg: Byte;
-    _fileid:   LongWord;
+    _fileid:   Integer;
   public
   end;
@@ -55,17 +55,27 @@
 begin
   _fileid := fileinfo.ID;
-  lbl_notpossible.Visible := False;
-  Self.img.Visible := True;
-  Self.timer.Enabled := False;
-  Self.panel_buttons.Visible := False;
-  ext     := fileinfo.Extension;
-  if (ext = 'PSpc') or (ext = 'TXMB') or (ext = 'TXMP') then
-    PreviewImage
-  else if ext = 'TXAN' then
-    PreviewTXAN
-  else
-  begin
-    Self.lbl_notpossible.Visible := True;
+  if _fileid >= 0 then
+  begin
+    lbl_notpossible.Visible := False;
+    Self.img.Visible := True;
+    Self.timer.Enabled := False;
+    Self.panel_buttons.Visible := False;
+    ext     := fileinfo.Extension;
+    if (ext = 'PSpc') or (ext = 'TXMB') or (ext = 'TXMP') then
+      PreviewImage
+    else if ext = 'TXAN' then
+      PreviewTXAN
+    else
+    begin
+      Self.lbl_notpossible.Visible := True;
+      Self.img.Visible := False;
+    end;
+  end
+  else
+  begin
     Self.img.Visible := False;
+    lbl_notpossible.Visible := False;
+    Self.timer.Enabled := False;
+    Self.panel_buttons.Visible := False;
   end;
 end;
Index: oup/current/Tools/Template.pas
===================================================================
--- oup/current/Tools/Template.pas	(revision 86)
+++ oup/current/Tools/Template.pas	(revision 87)
@@ -102,19 +102,38 @@
 begin
   oldcon := combo_connection.Items.Strings[combo_connection.ItemIndex];
+  combo_connection.ItemIndex := -1;
   combo_connection.Items.Clear;
-  for i := 0 to High(DataConnections) do
-  begin
-    level := DataConnections[i].LevelInfo.LevelNumber;
-    fn := ExtractFileName(DataConnections[i].FileName);
-    if DataConnections[i].Backend = ODB_Dat then
-      datatype := 'ONI-.dat: '
-    else if DataConnections[i].Backend = ODB_ADB then
-      datatype := 'OUP-DB: '
-    else
-      datatype := 'Unknown: ';
-    boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
-    combo_connection.Items.Add(boxstring);
-    if oldcon = boxstring then
-      combo_connection.ItemIndex := combo_connection.Items.Count - 1;
+  if Length(DataConnections) > 0 then
+  begin
+    for i := 0 to High(DataConnections) do
+    begin
+      level := DataConnections[i].LevelInfo.LevelNumber;
+      fn := ExtractFileName(DataConnections[i].FileName);
+      if DataConnections[i].Backend = ODB_Dat then
+        datatype := 'ONI-.dat: '
+      else if DataConnections[i].Backend = ODB_ADB then
+        datatype := 'OUP-DB: '
+      else
+        datatype := 'Unknown: ';
+      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
+      combo_connection.Items.Add(boxstring);
+      if oldcon = boxstring then
+        combo_connection.ItemIndex := combo_connection.Items.Count - 1;
+    end;
+    if combo_connection.ItemIndex = -1 then
+    begin
+      combo_connection.ItemIndex := 0;
+      combo_connectionChange(Self);
+    end;
+  end
+  else
+  begin
+    FConnection := nil;
+    filelist.Items.Clear;
+    combo_extension.Items.Clear;
+    combo_connectionChange(Self);
+    FSelectedFile := GetEmptyFileInfo;
+    if Assigned(FOnNewFileSelected) then
+      FOnNewFileSelected(FSelectedFile);
   end;
 end;
@@ -127,19 +146,29 @@
 begin
   combo_connection.Items.Clear;
-  for i := 0 to High(DataConnections) do
-  begin
-    level := DataConnections[i].LevelInfo.LevelNumber;
-    fn := ExtractFileName(DataConnections[i].FileName);
-    if DataConnections[i].Backend = ODB_Dat then
-      datatype := 'ONI-.dat: '
-    else if DataConnections[i].Backend = ODB_ADB then
-      datatype := 'OUP-DB: '
-    else
-      datatype := 'Unknown: ';
-    combo_connection.Items.Add(datatype + fn + ' (Level: ' + IntToStr(level) + ')');
-  end;
-  FConnection := DataConnections[0];
-  combo_connection.ItemIndex := 0;
-  combo_connectionChange(Self);
+  if Length(DataConnections) > 0 then
+  begin
+    for i := 0 to High(DataConnections) do
+    begin
+      level := DataConnections[i].LevelInfo.LevelNumber;
+      fn := ExtractFileName(DataConnections[i].FileName);
+      if DataConnections[i].Backend = ODB_Dat then
+        datatype := 'ONI-.dat: '
+      else if DataConnections[i].Backend = ODB_ADB then
+        datatype := 'OUP-DB: '
+      else
+        datatype := 'Unknown: ';
+      combo_connection.Items.Add(datatype + fn + ' (Level: ' + IntToStr(level) + ')');
+    end;
+    FConnection := DataConnections[0];
+    combo_connection.ItemIndex := 0;
+    combo_connectionChange(Self);
+  end
+  else
+  begin
+    FConnection := nil;
+    filelist.Items.Clear;
+    combo_extension.Items.Clear;
+    combo_connectionChange(Self);
+  end;
 end;
 
@@ -150,18 +179,21 @@
 begin
   combo_extension.Items.Clear;
-  combo_extension.Items.Add('_All files_ (' +
-    IntToStr(FConnection.GetFilesCount) + ')');
-  exts := FConnection.GetExtensionsList;
-  for i := 0 to High(exts) do
-    if Length(FAllowedExts) > 0 then
-    begin
-      if Pos(MidStr(exts[i],1,4), FAllowedExts) > 0 then
+  if FConnection <> nil then
+  begin
+    combo_extension.Items.Add('_All files_ (' +
+      IntToStr(FConnection.GetFilesCount) + ')');
+    exts := FConnection.GetExtensionsList;
+    for i := 0 to High(exts) do
+      if Length(FAllowedExts) > 0 then
       begin
+        if Pos(MidStr(exts[i],1,4), FAllowedExts) > 0 then
+        begin
+          combo_extension.Items.Add(exts[i]);
+        end;
+      end else
         combo_extension.Items.Add(exts[i]);
-      end;
-    end else
-      combo_extension.Items.Add(exts[i]);
-  combo_extension.ItemIndex := 0;
-  combo_extensionClick(Self);
+    combo_extension.ItemIndex := 0;
+    combo_extensionClick(Self);
+  end;
 end;
 
@@ -177,23 +209,26 @@
   i: LongWord;
 begin
-  Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
-  no_zero_bytes := not check_zerobyte.Checked;
-  pattern := '';
-  if check_filtername.Checked then
-    pattern := edit_filtername.Text;
-  if Extension = '_All' then
-    if Length(FAllowedExts) > 0 then
-      Extension := FAllowedExts
-    else
-      Extension := '';
-
-  files := FConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
-
-  filelist.Visible := False;
-  filelist.Items.Clear;
-  if Length(files) > 0 then
-    for i := 0 to High(files) do
-      filelist.Items.Add(files[i]);
-  filelist.Visible := True;
+  if FConnection <> nil then
+  begin
+    Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
+    no_zero_bytes := not check_zerobyte.Checked;
+    pattern := '';
+    if check_filtername.Checked then
+      pattern := edit_filtername.Text;
+    if Extension = '_All' then
+      if Length(FAllowedExts) > 0 then
+        Extension := FAllowedExts
+      else
+        Extension := '';
+
+    files := FConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
+
+    filelist.Visible := False;
+    filelist.Items.Clear;
+    if Length(files) > 0 then
+      for i := 0 to High(files) do
+        filelist.Items.Add(files[i]);
+    filelist.Visible := True;
+  end;
 end;
 
@@ -296,8 +331,5 @@
   inherited;
   RecreateList;
-  FConnection := nil;
-  FSelectedFile.ID := -1;
-  FSelectedFile.FileName := '';
-  FSelectedFile.FileNameHex := '';
+  FSelectedFile := GetEmptyFileInfo;
   if Length(ToolList) > 0 then
   begin
