How to connect to existing OLE application

Giganews Newsgroups
Subject:How to connect to existing OLE application
Posted by: Charles Hacker (Rep…@ToNewsGroups)
Date:Tue, 25 Aug 2009

Hi all,

I am writing an app to send data to MATLAB.
The code works, but it starts up a new instance each time.
Basically I want it to connect to the existing app, like the
  ConnectKind:= ckRunningOrNew
command does.

However, 'ConnectKind:= ckRunningOrNew' does not seem to work for general
'Variant'.

So how could I connect to an exiting application with a CreateOLEObject!

--- Test code I am using is below

procedure TForm1.Button2Click(Sender: TObject);
var
  V: Variant;
  MReal : OleVariant;
  MImage : OleVariant;
  i,j : integer;
begin
% V.ConnectKind:= ckRunningOrNew; -- DOES NOT WORK
V:= CreateOLEObject('Matlab.Application');
MReal  := VarArrayCreate([0, 1, 0, 3], varDouble);
MImage := VarArrayCreate([0,0,0,0], varDouble);
for i := 0 to 1 do
  for j := 0 to 3 do
  MReal[i,j] := i+4;
  V.PutFullmatrix('b','base',VarArrayRef(MReal),VararrayRef(MImage));
end;

Replies