Index: oup/current/Main.pas
===================================================================
--- oup/current/Main.pas	(revision 87)
+++ oup/current/Main.pas	(revision 92)
@@ -7,5 +7,5 @@
   Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
   MPHexEditor, ToolWin, ImgList, Tabs,
-  MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI,
+  MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst,
   Data, Functions, DataStructures, OniDataClass, Exporters,
   Helper_LevelDB, Settings, Template,
@@ -89,5 +89,5 @@
     procedure menu_windows_nextClick(Sender: TObject);
     procedure menu_windows_tileClick(Sender: TObject);
-    function open_child(window_context: String; fileid: Integer): TForm_ToolTemplate;
+    function open_child(window_context: String; connection: TOniData; fileid: Integer): TForm_ToolTemplate;
     procedure menu_windows_closeallClick(Sender: TObject);
     procedure menu_windows_cascadeClick(Sender: TObject);
@@ -116,6 +116,9 @@
     procedure MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
       Y: Integer);
-  private
+
+    procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
   public
+    procedure DefaultHandler(var Message); override;
+  public
   end;
 
@@ -126,4 +129,60 @@
 
 {$R *.dfm}
+
+
+
+{ Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt }
+procedure TForm_Main.WMCopyData(var Msg: TWMCopyData);
+var
+  strings: TStringList;
+begin
+  if (Msg.CopyDataStruct.dwData = SecondInstMsgId) and (SecondInstMsgId <> 0) then
+  begin
+    Application.BringToFront;
+    
+    strings := TStringList.Create;
+    strings.Text := ParamBlobToStr(Msg.CopyDataStruct.lpData);
+    if strings.Count = 2 then
+    begin
+      if strings.Strings[0] = 'opf' then
+      begin
+        ShowMessage('Load OPF-File: ' + ParamStr(2));
+      end
+      else if strings.Strings[0] = 'oldb' then
+      begin
+        if CreateDataConnection(strings.Strings[1], ODB_ADB) = nil then
+          ShowMessage('Error while loading the file:' + CrLf +
+                strings.Strings[1] + CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?');
+      end
+      else if strings.Strings[0] = 'dat' then
+      begin
+        if CreateDataConnection(strings.Strings[1], ODB_Dat) = nil then
+          ShowMessage('Error while loading the file:' + CrLf +
+                strings.Strings[1] + CrLf + 'Perhaps not an Oni-.dat-file?');
+      end;
+      UpdateStatBar;
+      UpdateConLists;
+    end;
+  end
+  else
+    inherited;
+end;
+
+{----------------------------------------------------------------------------}
+{ Wir überschreiben den DefaultHandler, der alle Nachrichten zuerst bekommt, }
+{ damit wir auf die Nachricht mit der ID SecondInstMsgId reagieren können.   }
+{ (Dies ist notwendig, da wir jetzt noch nicht wissen welchen Wert           }
+{  die ID haben wird, weswegen wir keine statische Message-Prozedure,        }
+{  so wie bei WM_COPYDATA, schreiben können.)                                }
+{----------------------------------------------------------------------------}
+procedure TForm_Main.DefaultHandler(var Message);
+begin
+  if TMessage(Message).Msg = SecondInstMsgId then
+    { Eine zweite Instanz hat uns nach dem Handle gefragt }
+    { Es wird in die Message-Queue des Threads gepostet.  }
+    PostThreadMessage(TMessage(Message).WParam, SecondInstMsgId, Handle, 0)
+  else
+    inherited;
+end;
 
 
@@ -388,4 +447,5 @@
       end;
   end;
+  UpdateStatBar;
   UpdateConLists;
 end;
@@ -482,17 +542,6 @@
 procedure TForm_Main.menu_createdbClick(Sender: TObject);
 begin
-{  if Assigned(OniDataConnection) then
-    if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' +
-          'Do you want to close it to continue?'), PChar('Close file?'),
-          MB_YESNO + MB_ICONQUESTION) = ID_NO then
-      Exit
-    else begin
-      if TryCloseAll then
-      begin
-        CloseDataConnection;
-        UpdateStatBar;
-      end else
-        Exit;
-    end;
+  ShowMessage('Not yet usable');
+{
   opend.Filter     := 'Oni-Dat-Files|*.dat';
   saved.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
@@ -501,5 +550,6 @@
     if saved.Execute then
       Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
-}end;
+}
+end;
 
 
@@ -508,17 +558,6 @@
 procedure TForm_Main.menu_createlvlClick(Sender: TObject);
 begin
-{  if Assigned(OniDataConnection) then
-    if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' +
-          'Do you want to close it to continue?'), PChar('Close file?'),
-          MB_YESNO + MB_ICONQUESTION) = ID_NO then
-      Exit
-    else begin
-      if TryCloseAll then
-      begin
-        CloseDataConnection;
-        UpdateStatBar;
-      end else
-        Exit;
-    end;
+  ShowMessage('Not yet usable');
+{
   opend.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
   saved.Filter     := 'Oni-Dat-Files|*.dat';
@@ -527,5 +566,6 @@
     if saved.Execute then
       Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
-}end;
+}
+end;
 
  {#################################}
@@ -534,5 +574,5 @@
 procedure TForm_Main.menu_previewClick(Sender: TObject);
 begin
-  open_child('preview', -1);
+  open_child('preview', nil, -1);
 end;
 
@@ -540,5 +580,5 @@
 procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
 begin
-  open_child('txmpreplace', -1);
+  open_child('txmpreplace', nil, -1);
 end;
 
@@ -546,5 +586,5 @@
 procedure TForm_Main.menu_bineditClick(Sender: TObject);
 begin
-  open_child('binedit', -1);
+  open_child('binedit', nil, -1);
 end;
 
@@ -552,5 +592,5 @@
 procedure TForm_Main.menu_raweditClick(Sender: TObject);
 begin
-  open_child('rawedit', -1);
+  open_child('rawedit', nil, -1);
 end;
 
@@ -558,5 +598,5 @@
 procedure TForm_Main.menu_extractorClick(Sender: TObject);
 begin
-  open_child('extractor', -1);
+  open_child('extractor', nil, -1);
 end;
 
@@ -570,5 +610,5 @@
 procedure TForm_Main.menu_filecompareClick(Sender: TObject);
 begin
-  open_child('compare', -1);
+  open_child('compare', nil, -1);
 end;
 
@@ -666,5 +706,5 @@
 
 
-function TForm_Main.open_child(window_context: String; fileid: Integer): TForm_ToolTemplate;
+function TForm_Main.open_child(window_context: String; connection: TOniData; fileid: Integer): TForm_ToolTemplate;
 var
   toolform:    TForm_ToolTemplate;
@@ -722,6 +762,8 @@
     MDITab.AddTab(TForm(toolform), iconindex);
     toolform.Caption := AnsiReplaceStr(toolform.Caption, '       ', '');
-    if fileid > -1 then
-      toolform.SelectFileID(fileid);
+    if (fileid > -1) and (connection <> nil) then
+    begin
+      toolform.SelectFileID(connection, fileid);
+    end;
     Result := toolform;
   end;
