Solved

OLE - how to create out of process server for another App

Posted on 2000-05-10
4
165 Views
Last Modified: 2010-04-04
I have made an app that checks for a server on the LAN, if its there create a file there on a shared dir. Wait for another file to be created then I read the new file in and save the contents in a string. Now ive been told that theres a program developed that will need to run my app, parse some info wait for the my app to finish then use the info I got. Ive been told that the only way it will comunicate is with ole. So, sorry to ramble but how do I make my app a ole server/whatever?
MAny, many thanks to anyone who can help.
Smurff
0
Comment
Question by:smurff
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2798119
Delphi 5 help is very good on this subject. Find this bit below, and follow the links

Creating an Automation object for an application

An Automation object is an ObjectPascal class descending from TAutoObject that supports OLE Automation, exposing itself for other applications to use. Since TAutoObject supports OLE Automation, any object derived from it gets Automation support automatically. You create an Automation object using the Automation Object wizard.
Before you create an Automation object, create or open the project for an application containing functionality that you want to expose. The project can be either an application or ActiveX library, depending on your needs.

To display the Automation wizard:

1      Choose File|New.
2      Select the tab labeled, ActiveX.
3      Double-click the Automation Object icon.

In the wizard dialog, specify the following:

CoClass Name      Specify the class whose properties and methods you want to expose to client applications. (Delphi prepends a T to this name.)
Instancing      Specify an instancing mode to indicate how your Automation server is launched.Note: When your Automation object is used only as an in-process server, instancing is ignored.
Threading Model      Choose the threading model to indicate how client applications can call your object’s interface. This is the threading model that you commit to implementing in the Automation object. Note: The threading model you choose determines how the object is registered. You must make sure that your object implementation adheres to the model selected.
Generate event support code      Check this box to tell the wizard to implement a separate interface for managing events of your Automation object.
When you complete this procedure, a new unit is added to the current project that contains the definition for the Automation object. In addition, the wizard adds a type library project and opens the type library. Now you can expose the properties and methods of the interface through the type library as described in Exposing the application’s properties and methods for Automation.
The Automation object implements a dual interface, which supports both early (compile-time) binding through the VTable and late (runtime) binding through the IDispatch interface.  
0
 
LVL 3

Author Comment

by:smurff
ID: 2803694
Thanks for your reply. I have testede what you said and I understand how it works now but I still have a small problem. I have my application with Form1 and 4 procedures, then after your advice, I added a Automation object which added unit2.pas and Project1_tlb. From unit2 I made a procedure helloworld and all it did was showmessage(param1); it worked fine but what I need to do is to call the procedures and labels from form1. I just cant seem to do it. does anyone have an example I could look thought or ay help?
0
 
LVL 2

Accepted Solution

by:
mullet_attack earned 100 total points
ID: 2804089
I created a new app, normal exe. A form with one label control on it, nothing else.

Then I selected new > activeX > automation object, which added the tlb and unit2.

I defined a method 'SetCaption' in the type library, and saved it.

I added unit1 to the uses clause of unit 2, and added the code to the implementation of SetCaption in unit2.

here are the units.

unit1
--------------------------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

end.


unit2
-----------------------------
unit Unit2;

interface

uses
  ComObj, ActiveX, Project1_TLB, StdVcl, unit1;

type
  TComTest = class(TAutoObject, IComTest)
  protected
    procedure SetCaption(const Text: WideString); safecall;
    { Protected declarations }
  end;

implementation

uses ComServ;

procedure TComTest.SetCaption(const Text: WideString);
begin
   Form1.label1.caption := text;
end;

initialization
  TAutoObjectFactory.Create(ComServer, TComTest, Class_ComTest,
    ciMultiInstance, tmApartment);
end.


hope this helps
0
 
LVL 3

Author Comment

by:smurff
ID: 2809856
Fantastic, just wht I needed, I couldnt seem to interact the form with unit2. Cheers for your time and answer.
Smurff
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IdTelnet1DataAvailable handler freezes the Application 4 68
Newbie Thread Programming 1 139
find a node in VST 2 64
Press three keys together and trigger a function 3 51
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now