我从dll
创建了一个tlb库。所以我有一些com
对象。
我想扩展界面,但我不能。
_Ckdu_cache:
// *********************************************************************//
// Interface: _Ckdu_cache
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {0137B6A2-76D0-3E27-A13C-557542A3AAD5}
// *********************************************************************//
_Ckdu_cache = interface(IDispatch)
['{0137B6A2-76D0-3E27-A13C-557542A3AAD5}']
function Get_ToString: WideString; safecall;
function Equals(obj: OleVariant): WordBool; safecall;
function GetHashCode: Integer; safecall;
function GetType: _Type; safecall;
function close: Byte; safecall;
function get_capabilities: Integer; safecall;
function read(buf: PSafeArray; num_bytes: Integer): Integer; safecall;
function seek(offset: Int64): Byte; safecall;
function get_pos: Int64; safecall;
function set_tileheader_scope(tnum: Integer; num_tiles: Integer): Byte; safecall;
function set_precinct_scope(unique_id: Int64): Byte; safecall;
procedure Dispose; safecall;
function add_to_databin(databin_class: Integer; codestream_id: Int64; databin_id: Int64;
data: PSafeArray; offset: Integer; num_bytes: Integer; is_final: Byte;
add_as_most_recent: Byte; mark_if_augmented: Byte): PByte1; safecall;
Cockdu_cache:
// *********************************************************************//
// The Class CoCkdu_cache provides a Create and CreateRemote method to
// create instances of the default interface _Ckdu_cache exposed by
// the CoClass Ckdu_cache. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoCkdu_cache = class
class function Create: _Ckdu_cache;
class function CreateRemote(const MachineName: string): _Ckdu_cache;
end;
我的课程:
type
TKduCache = class(CoCkdu_cache)
我的构造函数:
constructor TKduCache.Create(_targetID, _cachePath: String);
var
cache : _Ckdu_cache;
begin
cache:= inherited Create;
end;
错误: EIntfCastError,消息“Interface not supported”
我创建了另一个没有扩展的方法,如下所示:cache:= Cockdu_cache.Create;
但是我得到了同样的错误。我按照这个方法进行了另一个COM
对象创建,它们可以工作。但这对我不起作用。如何使用 _Ckdu_cache 方法?
其他:
unit kducache;
interface
uses imagecachestatus, jpipdatasegment, kdu_mni_TLB, globalvalues, SysUtils, Dialogs,
System.Classes, System.Variants, Winapi.ActiveX, jpipdatabinclass,
jpipresponse;
type
TIntArray = array of Integer;
type
TKduCache = class
private
{ private declarations }
//The cache file to use. Null if its not using a chace file.
cacheFile : TFileStream;
Flags : Word;
cachePath : String;
status : IImageCacheStatus;
//The targetID for the image as given by the JPIP server.
//Should be a unique hash for the image and thus serves
//as a good way of naming the cache file.
targetID : String;
//The amount of new data placed in this object via the
//addDataSegment method starting after the initial
//readCacheFromFile method.
newData : Integer;
//This flags indicates if the server has to be loaded/saved to disk.
iamPersistent : Boolean;
class var maxCacheSize : LongInt;
cacheExists : Boolean;
class function uByteToInt(_x : array of Byte) : TIntArray;
class function getCacheFiles(_cachePath : String) : TStringStream;
protected
{ protected declarations }
public
FCache: _Ckdu_cache;
{ public declarations }
procedure setImageCacheStatus(imageCacheStatus : IImageCacheStatus);
procedure setInitialScope;
procedure addDataSegment(_data : TJPIPDataSegment);
class procedure updateCacheDirectory(_cachePath : String; maxSize : Double); overload;
class procedure updateCacheDirectory(_cachePath : String); overload;
function getNewDataSize : Integer;
function getTotalDataSize : Integer;
function isDataBinCompleted(_binClass : TJPIPDatabinClass; _streamID : Integer; _binID : Integer) : Boolean;
function Close : Boolean;
function addJPIPResponseData(jRes : TJPIPResponse) : Boolean;
function writeCacheToFile : Boolean;
function readCacheFromFile : Boolean;
function buildCacheModelUpdateString(force : Boolean) : String;
function getCacheFile : TStringStream;
constructor Create(_targetID : String; _cachePath : String); virtual;
// constructor Create(_targetID : String; _cachePath : String; _iamPersistent : Boolean); overload;
published
{ published declarations }
end;
implementation
{ TJHV_Kdu_Cache }
{ TKduCache }
//Main constructor used when you want to use a cache file.
constructor TKduCache.Create(_targetID, _cachePath: String);
begin
FCache:= CoCkdu_cache.Create;
targetID:= _targetID;
cachePath:= _cachePath + '\' + targetID + '.cache';
cacheExists:= true;
Flags:= fmOpenReadWrite;
if _cachePath = '' then
cacheExists:= false
else
begin
Flags := fmCreate;
cacheFile:= TFileStream.Create(cachePath, Flags);
end;
newData:= 0;
cacheFile.Free;
if cacheExists then
readCacheFromFile;
end;
我打电话:
TKduCache.Create(jpipTargetID, 'C:\Users\myComputer\Desktop\WorkStation\cache');
答案 0 :(得分:1)
您无需使用继承。不要声明派生类。创建一个接口实例,如下所示:
cache := CoCkdu_cache.Create;
然后直接在cache
上调用方法。