###绝对让你晕头的COM+问题!!!先200分吧### (200分)

  • 主题发起人 desertsmoke
  • 开始时间
D

desertsmoke

Unregistered / Unconfirmed
GUEST, unregistred user!
环境1:
WinXP Pro+SP1
Delphi6 Enterprise+Update pack2+RTL Update Pack 3
环境2:
Win2000 Pro+Sp3
Delphi7
问题:delphi->新建->ActiveX->Transactional Object创建一个COM+服务器,修改、保存,编译、安装都没问题。但是:[red]关闭这个工程,然后重新打开,保存(.dpr或_TLB.pas)就会出现错误提示如下:[/red][purple](注:并不是每次都一定出现!!!)[/purple]
---------------------------
Error
---------------------------
The type library ComProjFund had translation errors or warnings.
Some information may be lost or modified. do
you want save with these modifications?
---------------------------
Yes No
---------------------------
如果保存XXX_TLB.pas则会出现下面的情况:
[blue]原来文件内容(部分):
-------------------------------------------------------------
const
// TypeLibrary Major and minor versions
Test001MajorVersion = 1;
Test001MinorVersion = 0;
LIBID_Test001: TGUID = '{A30A0937-24E4-4132-9047-2190154B4EA1}';
IID_ITest001: TGUID = '{DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}';
CLASS_Test001: TGUID = '{19E13C2D-C57C-40AE-9B95-6C283C06FB23}';
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
ITest001 = interface;
ITest001Disp = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
Test001 = ITest001;

// *********************************************************************//
// Interface: ITest001
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}
// *********************************************************************//
ITest001 = interface(IDispatch)
['{DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}']
function GetMsg(ErrCode: Integer): WideString;
safecall;
end;

// *********************************************************************//
// DispIntf: ITest001Disp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}
// *********************************************************************//
ITest001Disp = dispinterface
['{DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}']
function GetMsg(ErrCode: Integer): WideString;
dispid 1;
end;

// *********************************************************************//
// The Class CoTest001 provides a Create and CreateRemote method to
// create instances of the default interface ITest001 exposed by
// the CoClass Test001. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoTest001 = class
class function Create: ITest001;
class function CreateRemote(const MachineName: string): ITest001;
end;

implementation
uses ComObj;
class function CoTest001.Create: ITest001;
begin
Result := CreateComObject(CLASS_Test001) as ITest001;
end;

class function CoTest001.CreateRemote(const MachineName: string): ITest001;
begin
Result := CreateRemoteComObject(MachineName, CLASS_Test001) as ITest001;
end;
-------------------------------------------------------------[/blue]
保存后的文件内容:
-------------------------------------------------------------
const
// TypeLibrary Major and minor versions
Test001MajorVersion = 1;
Test001MinorVersion = 0;
LIBID_Test001: TGUID = '{A30A0937-24E4-4132-9047-2190154B4EA1}';
IID_ITest001: TGUID = '{DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}';
[red]CLASS_Test001_[/red]: TGUID = '{19E13C2D-C57C-40AE-9B95-6C283C06FB23}';
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
ITest001 = interface;
ITest001Disp = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
[red]Test001_[/red] = ITest001;

// *********************************************************************//
// Interface: ITest001
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}
// *********************************************************************//
ITest001 = interface(IDispatch)
['{DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}']
function GetMsg(ErrCode: Integer): WideString;
safecall;
end;

// *********************************************************************//
// DispIntf: ITest001Disp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}
// *********************************************************************//
ITest001Disp = dispinterface
['{DAC8C355-7CD6-436D-8EC4-C2C4F65440D5}']
function GetMsg(ErrCode: Integer): WideString;
dispid 1;
end;

// *********************************************************************//
// The Class CoTest001_ provides a Create and CreateRemote method to
// create instances of the default interface ITest001 exposed by
// the CoClass Test001_. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
[red]CoTest001_[/red] = class
class function Create: ITest001;
class function CreateRemote(const MachineName: string): ITest001;
end;

implementation
uses ComObj;
class function [red]CoTest001_[/red].Create: ITest001;
begin
Result := CreateComObject([red]CLASS_Test001_[/red]) as ITest001;
end;

class function [red]CoTest001_[/red].CreateRemote(const MachineName: string): ITest001;
begin
Result := CreateRemoteComObject(MachineName, [red]CLASS_Test001_[/red]) as ITest001;
end;
-------------------------------------------------------------
从此之后,只要保存就会出现这个问题!
哪位碰到过这种问题?如何解决的?请不吝赐教,200分奉上,多谢。
[red]注:delphi已经重新安装过。[/red]
 
示例代码在这里:http://www.cnlore.com/test002.rar
 
接口改變了,當然會有這個問題,一般來說沒關係的
如果你每次都編譯的話,記住先取消type lib的註冊.
 
to:foresail
可是我的接口没做任何改变啊!
另:出现这个问题后,再修改就不能保存了!
或者我理解不对,请说详细些,多谢!
 
接口的参数名有冲突,Delphi自动帮你更正了,只是提示信息,保存后不影响使用的。
 
to:chyni
请打开这个示例代码看一下:
示例代码在这里:http://www.cnlore.com/test002.rar
保存后是会有影响的,类名称后需加“_”,这不是设计的本意!
 
找李维那本书看...我认为三层并不怎么样呀....用不好的话反而让你难受呀......
 
工程名称和接口名称相同时会有这样的提示。
 
的确如此!!!不知道算不算是delphi的BUG?——保存时没有提示,再次打开就有问题!(当初保存时就应该检查!)
 

Similar threads

顶部