Mega Code Archive

 
Categories / Delphi / Activex OLE
 

How to determine the start method of an OLE automation object

Title: How to determine the start method of an OLE automation object Question: In some cases it is important to know with which method a program was started. Did the user start the exe file as an interactive application or was the program started by an OLE request. Which methods offers Delphi to do so? Answer: By default, when the ComServ unit is included in a project, Delphi constructs a COM server object and assigns it to an object ComServ. ComServ has several properties provide information about the objects loaded. So have a look at the TComServer object. TComServer provides a property StartMode which indicates why the COM server was started. type TStartMode = (smStandalone, smAutomation, smRegServer, smUnregServer); property StartMode: TStartMode; So how can you use it. For example in the create method of your form: uses ComSever; procedure TForm1.FormCreate(Sender : TObject); begin if (ComServer.StartMode = smStandAlone then ShowMessage('Started by users request') else ShowMessage('Startet by OLE automation'); end; So without an OLE automation object this always shows the first dialog. But generating an OLE automation object and using a short vbs like this: set Test = CreateObject("CallPerOle.perOle") you see the second message. Hope it helps and sorry for bad english. Mark