Solved

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

Posted on 2000-05-10
4
164 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Fantastic, just wht I needed, I couldnt seem to interact the form with unit2. Cheers for your time and answer.
Smurff
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

11 Experts available now in Live!

Get 1:1 Help Now