RAD Studio VCL Reference
|
Instantiates an Automation object.
function CreateOleObject(const ClassName: string): IDispatch;
IDispatch CreateOleObject(const AnsiString ClassName);
CreateOleObject creates a single uninitialized object of the class specified by the ClassName parameter. ClassName specifies the string representation of the Class ID (CLSID). CreateOleObject is used to create an object of a specified type when the CLSID is known, and when the object is on a local or in-proc server. Only objects that are not part of an aggregate are created using CreateOleObject.
C++ Examples:
/* The following code shows an example of how to create an Ole Object and how to perform specific operations. */ void __fastcall TMyForm::ButtonClick(TObject *Sender) { OleVariant WordApp, NewDoc; /* Creates a Microsoft Word application. */ WordApp = CreateOleObject("Word.Application"); /* Creates a new Microsoft Word document. */ NewDoc = WordApp.OlePropertyGet("Documents").OleFunction("Add"); /* Inserts the text 'Hello World!' in the document. */ WordApp.OlePropertyGet("Selection").OleFunction("TypeText", "Hello World!"); /* Saves the document on the disk. */ NewDoc.OleFunction("SaveAs", "my_new_document.doc"); /* Closes Microsoft Word. */ WordApp.OleFunction("Quit"); /* Releases the interface by assigning the Unassigned constant to the Variant variables. */ NewDoc = Unassigned; WordApp = Unassigned; }
Delphi Examples:
{ The following code shows an example of how to create an Ole Object and how to perform specific operations. } procedure TForm1.ButtonClick(Sender: TObject); var WordApp, NewDoc: Variant; begin { Creates a Microsoft Word application. } WordApp := CreateOleObject('Word.Application'); { Creates a new Microsoft Word document. } NewDoc := WordApp.Documents.Add; { Inserts the text 'Hello World!' in the document. } WordApp.Selection.TypeText('Hello World!'); { Saves the document on the disk. } NewDoc.SaveAs('my_new_document.doc'); { Closes Microsoft Word. } WordApp.Quit; { Releases the interface by assigning the Unassigned constant to the Variant variables. } NewDoc := Unassigned; WordApp := Unassigned; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|