From 0dd49a4410cf983415b5246d6fdeb0f5df1784e3 Mon Sep 17 00:00:00 2001
From: Lionel Debroux <lionel_debroux@yahoo.fr>
Date: Sun, 7 Dec 2008 17:27:28 +0100
Subject: Delphi IDE 2/3: add back VTI support *along with* (as opposed to "instead of") TIEmu support.

This patch adds back TMainForm.GetVTIWindow and uses in VTIStartUnit.
---
 tigcc/ide/MainUnit.pas     |   33 +++++++++++++++++++++++++++++++++
 tigcc/ide/VTIStartUnit.pas |   19 +++++++++++--------
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/tigcc/ide/MainUnit.pas b/tigcc/ide/MainUnit.pas
index 05e7420..e132543 100644
--- a/tigcc/ide/MainUnit.pas
+++ b/tigcc/ide/MainUnit.pas
@@ -468,6 +468,7 @@ type
 		procedure SortFiles;
 		procedure DisplayFolderMessage;
 		procedure ClearDebugInfo;
+		function GetVTIWindow: HWnd;
 		function GetTiEmuInterface: ITiEmuOLE;
 		procedure SendFiles(FNList: array of string);
 		procedure ExecuteCommandLine(const Line: string);
@@ -4694,6 +4695,38 @@ begin
 	end;
 end;
 
+function TMainForm.GetVTIWindow: HWnd;
+begin
+	CurVTIType := cvVTINone;
+	Result := FindWindow ('TEmuWnd', 'Virtual TI-89');
+	if Result = 0 then begin
+		Result := FindWindow ('TEmuWnd', 'Virtual TI-92+');
+		if Result = 0 then begin
+			Result := FindWindow ('TEmuWnd', 'Virtual TI-92');
+			if Result <> 0 then
+				CurVTIType := cvVTITI92;
+		end else
+			CurVTIType := cvVTITI92Plus;
+	end else
+		CurVTIType := cvVTITI89;
+	if Result = 0 then begin
+		if Length (VTIPath) > 0 then begin
+			with TVTIStartForm.Create (Self) do try
+				if ShowModal = mrOK then begin
+					Result := VTIWindow;
+					CurVTIType := VTIType;
+				end else
+					Abort;
+			finally
+				Free;
+			end;
+		end else begin
+			ShowDefaultMessageBox ('Virtual TI is not running.', 'Error', mtProgramError);
+			Abort;
+		end;
+	end;
+end;
+
 function TMainForm.GetTiEmuInterface: ITiEmuOLE;
 var
 	Unknown: IUnknown;
diff --git a/tigcc/ide/VTIStartUnit.pas b/tigcc/ide/VTIStartUnit.pas
index 717e081..a4e85f1 100644
--- a/tigcc/ide/VTIStartUnit.pas
+++ b/tigcc/ide/VTIStartUnit.pas
@@ -26,7 +26,7 @@ interface
 uses
 	MasterUnit,
 	Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
-	StdCtrls, ExtCtrls, ComObj, ActiveX, TiEmuOLELib_TLB;
+	StdCtrls, ExtCtrls;
 
 type
 	TVTIStartForm = class(TForm)
@@ -39,7 +39,8 @@ type
 	private
 		ProcessHandle: THandle;
 	public
-		TiEmuInterface: ITiEmuOLE;
+		VTIWindow: HWnd;
+		VTIType: TVTICalcType;
 	end;
 
 implementation
@@ -75,8 +76,6 @@ end;
 procedure TVTIStartForm.FindTimerTimer(Sender: TObject);
 var
 	ExitCode: Cardinal;
-	Unknown: IUnknown;
-	OLEResult: HResult;
 begin
 	if GetExitCodeProcess (ProcessHandle, ExitCode) then begin
 		if ExitCode <> STILL_ACTIVE then begin
@@ -84,11 +83,15 @@ begin
 			Exit;
 		end;
 	end;
-	OLEResult := GetActiveObject(CLASS_TiEmuOLE, nil, Unknown);
-	if OLEResult = S_OK then begin
-		OleCheck(Unknown.QueryInterface(ITiEmuOLE, TiEmuInterface));
+  VTIWindow := FindWindow ('TEmuWnd', 'Virtual TI-89');
+  if VTIWindow = 0 then begin
+    VTIWindow := FindWindow ('TEmuWnd', 'Virtual TI-92+');
+    if VTIWindow <> 0 then
+      VTIType := cvVTITI92Plus;
+  end else
+    VTIType := cvVTITI89;
+	if VTIWindow <> 0 then
 		ModalResult := mrOK;
-	end;
 end;
 
 end.
-- 
1.6.1.rc2


