可以啊。先用Delphi的Import Library 功能Import一下。然后就可以用了。
解决方案 »
- delpphi实时监控数据库
- 系统在安装了Delphi的机子上可以运行,但是在没有安装Delphi的机子上却要出错,我用的是Database Desktop创建的表,请高手解决,急用!!!!!!!!!
- 接着赚分.
- 问一个关于sql和access的问题
- 怎样kill 远程 ORACLE 的进程
- 菜鸟问题:找不到TSQLClientDateSet类
- 请问用代码怎么实现将程序快捷方式加到系统右键菜单中?
- 以西游记盘点2009的一些流行趋势
- 请问怎样将字符串表示的16进制数转换成10进制数?
- 一个串口通讯的问题! 急!急!急!
- paradox里可不可以用select * into myNewTable from myTable where condition=myCondition
- 有关Form的建立与释放问题
ActiveX其实可以象VCL一样控制。
比如:
var
a: IYourType;a := CoYourType.Create;
然后,就可以用了。
假设有一个TClassReadDic的类。怎么用呢?
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes,
ReadDic_TLB in '..\Imports\ReadDic_TLB.pas';{$R *.RES}
function ItoS(V:integer):integer;stdcall;
var
cReadDic:TClassReadDic;begin
creaddic.Create(TclassreadDic);
result:=v+10;end;
exports
ItoS index 1 name 'ItoS';
begin
end.错误是 [Error] Project2.dpr(24): Incompatible types: 'TComponent' and 'Class reference'ReadDic_TLB内容是
unit ReadDic_TLB;// ************************************************************************ //
// WARNING
// -------
// The types declared in this file were generated from data read from a
// Type Library. If this type library is explicitly or indirectly (via
// another type library referring to this type library) re-imported, or the
// 'Refresh' command of the Type Library Editor activated while editing the
// Type Library, the contents of this file will be regenerated and all
// manual modifications will be lost.
// ************************************************************************ //// PASTLWTR : $Revision: 1.88 $
// File generated on 2003-3-28 16:22:15 from Type Library described below.// *************************************************************************//
// NOTE:
// Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties
// which return objects that may need to be explicitly created via a function
// call prior to any access via the property. These items have been disabled
// in order to prevent accidental use from within the object inspector. You
// may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively
// removing them from the $IFDEF blocks. However, such items must still be
// programmatically created via a method of the appropriate CoClass before
// they can be used.
// ************************************************************************ //
// Type Lib: D:\delphi程序\mjdic调用例\ReadDic.dll (1)
// IID\LCID: {B9FEC686-F021-4BC1-8987-3AE057261484}\0
// Helpfile:
// DepndLst:
// (1) v2.0 stdole, (C:\WINDOWS\SYSTEM\stdole2.tlb)
// (2) v4.0 StdVCL, (C:\WINDOWS\SYSTEM\STDVCL40.DLL)
// Errors:
// Error creating palette bitmap of (TClassReadDic) : Server D:\delphi程序\mjdic调用例\ReadDic.dll contains no icons
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
interfaceuses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;// *********************************************************************//
// 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
ReadDicMajorVersion = 1;
ReadDicMinorVersion = 0; LIBID_ReadDic: TGUID = '{B9FEC686-F021-4BC1-8987-3AE057261484}'; IID__ClassReadDic: TGUID = '{970C3FFB-4419-411E-9E13-5C8C59DC4FE8}';
CLASS_ClassReadDic: TGUID = '{988BF479-8593-4715-99FF-B32A840D2DBA}';
type// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
_ClassReadDic = interface;
_ClassReadDicDisp = dispinterface;// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
ClassReadDic = _ClassReadDic;
// *********************************************************************//
// Interface: _ClassReadDic
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {970C3FFB-4419-411E-9E13-5C8C59DC4FE8}
// *********************************************************************//
_ClassReadDic = interface(IDispatch)
['{970C3FFB-4419-411E-9E13-5C8C59DC4FE8}']
function ReadTheLine(var FileNam: WideString; var lineId: Integer; var Language: WordBool): WideString; safecall;
function ReadMean(var FileNam: WideString; var lineId: Integer): WideString; safecall;
function GetCount(var FileName: WideString): Integer; safecall;
end;// *********************************************************************//
// DispIntf: _ClassReadDicDisp
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {970C3FFB-4419-411E-9E13-5C8C59DC4FE8}
// *********************************************************************//
_ClassReadDicDisp = dispinterface
['{970C3FFB-4419-411E-9E13-5C8C59DC4FE8}']
function ReadTheLine(var FileNam: WideString; var lineId: Integer; var Language: WordBool): WideString; dispid 1610809344;
function ReadMean(var FileNam: WideString; var lineId: Integer): WideString; dispid 1610809345;
function GetCount(var FileName: WideString): Integer; dispid 1610809346;
end;// *********************************************************************//
// The Class CoClassReadDic provides a Create and CreateRemote method to
// create instances of the default interface _ClassReadDic exposed by
// the CoClass ClassReadDic. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoClassReadDic = class
class function Create: _ClassReadDic;
class function CreateRemote(const MachineName: string): _ClassReadDic;
end;
// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object : TClassReadDic
// Help String :
// Default Interface: _ClassReadDic
// Def. Intf. DISP? : No
// Event Interface:
// TypeFlags : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TClassReadDicProperties= class;
{$ENDIF}
TClassReadDic = class(TOleServer)
private
FIntf: _ClassReadDic;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TClassReadDicProperties;
function GetServerProperties: TClassReadDicProperties;
{$ENDIF}
function GetDefaultInterface: _ClassReadDic;
protected
procedure InitServerData; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: _ClassReadDic);
procedure Disconnect; override;
function ReadTheLine(var FileNam: WideString; var lineId: Integer; var Language: WordBool): WideString;
function ReadMean(var FileNam: WideString; var lineId: Integer): WideString;
function GetCount(var FileName: WideString): Integer;
property DefaultInterface: _ClassReadDic read GetDefaultInterface;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TClassReadDicProperties read GetServerProperties;
{$ENDIF}
end;{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object : TClassReadDic
// (This object is used by the IDE's Property Inspector to allow editing
// of the properties of this server)
// *********************************************************************//
TClassReadDicProperties = class(TPersistent)
private
FServer: TClassReadDic;
function GetDefaultInterface: _ClassReadDic;
constructor Create(AServer: TClassReadDic);
protected
public
property DefaultInterface: _ClassReadDic read GetDefaultInterface;
published
end;
{$ENDIF}
procedure Register;implementationuses ComObj;class function CoClassReadDic.Create: _ClassReadDic;
begin
Result := CreateComObject(CLASS_ClassReadDic) as _ClassReadDic;
end;class function CoClassReadDic.CreateRemote(const MachineName: string): _ClassReadDic;
begin
Result := CreateRemoteComObject(MachineName, CLASS_ClassReadDic) as _ClassReadDic;
end;procedure TClassReadDic.InitServerData;
const
CServerData: TServerData = (
ClassID: '{988BF479-8593-4715-99FF-B32A840D2DBA}';
IntfIID: '{970C3FFB-4419-411E-9E13-5C8C59DC4FE8}';
EventIID: '';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;procedure TClassReadDic.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
Fintf:= punk as _ClassReadDic;
end;
end;procedure TClassReadDic.ConnectTo(svrIntf: _ClassReadDic);
begin
Disconnect;
FIntf := svrIntf;
end;procedure TClassReadDic.DisConnect;
begin
if Fintf <> nil then
begin
FIntf := nil;
end;
end;function TClassReadDic.GetDefaultInterface: _ClassReadDic;
begin
if FIntf = nil then
Connect;
Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
Result := FIntf;
end;constructor TClassReadDic.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TClassReadDicProperties.Create(Self);
{$ENDIF}
end;destructor TClassReadDic.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps.Free;
{$ENDIF}
inherited Destroy;
end;{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TClassReadDic.GetServerProperties: TClassReadDicProperties;
begin
Result := FProps;
end;
{$ENDIF}function TClassReadDic.ReadTheLine(var FileNam: WideString; var lineId: Integer;
var Language: WordBool): WideString;
begin
Result := DefaultInterface.ReadTheLine(FileNam, lineId, Language);
end;function TClassReadDic.ReadMean(var FileNam: WideString; var lineId: Integer): WideString;
begin
Result := DefaultInterface.ReadMean(FileNam, lineId);
end;function TClassReadDic.GetCount(var FileName: WideString): Integer;
begin
Result := DefaultInterface.GetCount(FileName);
end;{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TClassReadDicProperties.Create(AServer: TClassReadDic);
begin
inherited Create;
FServer := AServer;
end;function TClassReadDicProperties.GetDefaultInterface: _ClassReadDic;
begin
Result := FServer.DefaultInterface;
end;{$ENDIF}procedure Register;
begin
RegisterComponents('ActiveX',[TClassReadDic]);
end;我折腾了一上午还是不行,请帮忙看看那有问题。
我太菜了,请老兄多费心,添麻烦了。
a: ClassReadDic;
begin
a := CoClassReadDic.Create;
a.GetCount('YourFileName');
end;