Message 1 of 1
Dephi and GetActiveOLEObject

Not applicable
06-06-2002
12:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Folks,
I have a problem with a Delphi program that interfaces with Autocad. The
problem only shows up when multiple versions have been installed on a
machine. If Acad 14 has been installed and then Acad 2002, the program
can't find Acad 2002. It can only find Acad 14. This is true even if Acad
14 has been unistalled. I tried cleaning out the registry, but to no avail.
If anyone has run across this and has any suggestions, I would appreciate
the input.
Function GetAcadWindow: HWnd;
var
Acad : OleVariant;
Caption : String;
begin
Acad := GetActiveOleObject('AutoCAD.Application');
Try
Caption := Acad.Caption;
except
on EOleSysError do begin
Result := 0;
Exit;
end;
end;
Result := FindWindow(Nil, PChar(Caption));
end;
Function SendCommand(Cmd: String) : boolean;
var
cds: TCopyDataStruct;
wnd, sender : HWND;
pData : array [0..255] of char;
begin;
result := False;
wnd := GetAcadWindow;
sender := Application.Handle;
if wnd <> 0 then
begin
StrPCopy(pData, Cmd + #13);
pData[Length(Cmd)+1] := #0;
cds.dwData := 1;
cds.cbData := SizeOf(pData);
cds.lpData := @pData;
Result := SendMessage(wnd, WM_COPYDATA, Sender, LParam(@cds)) <> 0;
end;
end;
Procedure ActivateWindow(Window : HWnd);
var
state : TWindowPlacement;
begin
If not IsWindow(Window) then exit;
If IsIconic(Window) then
begin
State.length := SizeOf(TWindowPlacement);
GetWindowPlacement(Window, PWindowPlacement(@State));
if (State.flags and 2) = 2 then
ShowWindow(Window, SW_SHOWMAXIMIZED)
else
ShowWindow(Window, SW_RESTORE);
end;
BringWindowToTop(Window);
SetForegroundWindow(Window);
end;
Function GetAcad : oleVariant;
var
Acad : oleVariant;
begin
Try
Acad := GetActiveOLEObject('AutoCad.Application');
except
// ShowMessage('Could not locate AutoCad session, please be sure AutoCad
is running.');
end;
result := Acad;
end;
I have a problem with a Delphi program that interfaces with Autocad. The
problem only shows up when multiple versions have been installed on a
machine. If Acad 14 has been installed and then Acad 2002, the program
can't find Acad 2002. It can only find Acad 14. This is true even if Acad
14 has been unistalled. I tried cleaning out the registry, but to no avail.
If anyone has run across this and has any suggestions, I would appreciate
the input.
Function GetAcadWindow: HWnd;
var
Acad : OleVariant;
Caption : String;
begin
Acad := GetActiveOleObject('AutoCAD.Application');
Try
Caption := Acad.Caption;
except
on EOleSysError do begin
Result := 0;
Exit;
end;
end;
Result := FindWindow(Nil, PChar(Caption));
end;
Function SendCommand(Cmd: String) : boolean;
var
cds: TCopyDataStruct;
wnd, sender : HWND;
pData : array [0..255] of char;
begin;
result := False;
wnd := GetAcadWindow;
sender := Application.Handle;
if wnd <> 0 then
begin
StrPCopy(pData, Cmd + #13);
pData[Length(Cmd)+1] := #0;
cds.dwData := 1;
cds.cbData := SizeOf(pData);
cds.lpData := @pData;
Result := SendMessage(wnd, WM_COPYDATA, Sender, LParam(@cds)) <> 0;
end;
end;
Procedure ActivateWindow(Window : HWnd);
var
state : TWindowPlacement;
begin
If not IsWindow(Window) then exit;
If IsIconic(Window) then
begin
State.length := SizeOf(TWindowPlacement);
GetWindowPlacement(Window, PWindowPlacement(@State));
if (State.flags and 2) = 2 then
ShowWindow(Window, SW_SHOWMAXIMIZED)
else
ShowWindow(Window, SW_RESTORE);
end;
BringWindowToTop(Window);
SetForegroundWindow(Window);
end;
Function GetAcad : oleVariant;
var
Acad : oleVariant;
begin
Try
Acad := GetActiveOLEObject('AutoCad.Application');
except
// ShowMessage('Could not locate AutoCad session, please be sure AutoCad
is running.');
end;
result := Acad;
end;