Eighth chapter-Object Linking and Embedding (ii) (4)

Source: Internet
Author: User
Tags command line integer ole

8.4.3 Automation another program

Each server in the system registration has a key called ProgID, mainly used to identify the server controller. Any controller can use the ProgID number to create an OLE object instance. Routine AutoForm is a controller program that creates an instance of an OLE object in its main form.

Procedure Tmainform.formcreate (Sender:tobject);

Begin

Try

Memoedit: = Createoleobject (' memoedit.application ');

Except

Messagedlg (

' An instance of the ' Memoedit application OLE automation Class could

Not to created,make sure that memoedit application has been registered

Using a "memoedit|regserver" command line,

mterror,[mbok],0)

Halt;

End

End

Once the controller has created an OLE Automation object instance, it can manipulate it. OLE automatic objects include properties and methods, although OLE Automation objects are not the same concept as objects in object-oriented Pascal, but Delphi allows calls to methods of OLE objects using similar syntax.

Many of the AutoForm procedures refer to the methods of OLE Automation objects:

Procedure Tmainform,tilebuttonclick (Sender:tobject);

Begin

Memoedit,tilewindow;

End

Where Tilewindows is the method defined in the OLE object Tmemoapp.

AutoForm also obtains a reference to the Tmemodoc of the OLE object inside the server through the Newmemo method of Tmemoapp.

Procedure Tmainform,createbuttonclick (Sender:tobject);

Var

I:integer;

Begin

Closememo

For I: = 1-3 do memos[2]: = Memoedit.newmemo;

End

The Newmemo is defined in the Memoauto unit as follows:

function IMemoApp.NewMemo:Variant;

Begin

Result: = Mainform,creatememo ('), OleObject;

End

After the controller obtains the internal OLE object for the server, it can refer to its method:

Procedure Tmainform.addtextbuttonclick (Sender,tobject);

Var

I:integer;

Begin

For I: = 1 to 3 do

If not Var isempty (Memo[i]) then

memo[i],insert{' This text is added through OLE automation ' #13 #10);

End

Insert is a method defined in Tmemodoc to insert a string into a subform.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.