16,748
社区成员
发帖
与我相关
我的任务
分享
unit A_03_TLB;
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
{$ALIGN 4}
interface
uses Windows, ActiveX, Classes, Graphics, OleServer, StdVCL, Variants;
// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLASS_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
const
// TypeLibrary Major and minor versions
A_03MajorVersion = 3;
A_03MinorVersion = 0;
LIBID_A_03: TGUID = '{DAD4FAA2-CD2A-4F07-BA7A-687F5E7A4B27}';
IID__Test: TGUID = '{72B3C6DC-4F23-4954-ACF6-5ACF102BE864}';
CLASS_Test: TGUID = '{3799C0FE-7D12-4C5D-A01E-422F6F496DCE}';
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
_Test = interface;
_TestDisp = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
Test = _Test;
// *********************************************************************//
// Interface: _Test
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {72B3C6DC-4F23-4954-ACF6-5ACF102BE864}
// *********************************************************************//
_Test = interface(IDispatch)
['{72B3C6DC-4F23-4954-ACF6-5ACF102BE864}']
procedure a_01(var a: Single); safecall;
procedure a_02(var a: Double); safecall;
procedure A_03(var a: WideString); safecall;
end;
// *********************************************************************//
// DispIntf: _TestDisp
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {72B3C6DC-4F23-4954-ACF6-5ACF102BE864}
// *********************************************************************//
_TestDisp = dispinterface
['{72B3C6DC-4F23-4954-ACF6-5ACF102BE864}']
procedure a_01(var a: Single); dispid 1610809344;
procedure a_02(var a: Double); dispid 1610809345;
procedure A_03(var a: WideString); dispid 1610809346;
end;
// *********************************************************************//
// The Class CoTest provides a Create and CreateRemote method to
// create instances of the default interface _Test exposed by
// the CoClass Test. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoTest = class
class function Create: _Test;
class function CreateRemote(const MachineName: string): _Test;
end;
implementation
uses ComObj;
class function CoTest.Create: _Test;
begin
Result := CreateComObject(CLASS_Test) as _Test;
end;
class function CoTest.CreateRemote(const MachineName: string): _Test;
begin
Result := CreateRemoteComObject(MachineName, CLASS_Test) as _Test;
end;
end.
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm3 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
var
MyDLL : Test; -----> 这一步要 "明确" 宣告型态,
为了顾及执行速度 "不能" 宣告为 MyDLL: OleVariant;
MyDLL :=CreateOleObject(......);
begin
MyDLL.a_01(); // 呼叫.....
MyDLL.a_02();
end;
uses
A_03_TLB;
var
a:_Test;
begin
a.a_01(参数);
end;