OLECheck是来包装CoCreateInstance和其他OLE函数的调用。OLE函数一般返回名为HResult的变量。该变量成功是通常为零,失败时返回Activex.pas中声明来确定标准错误值的负值。Olecheck就会尝试着把Hresult的数值转换为可读的字符串,接着出现异常,并且把字符串显示出来。如果不想用OLECheck,也可以用函数Succeeded或者Failed检查来调用结果。如:
var
hr: HResult
begin
hr := MYOLEFunc;
if SUCCEEDED(hr) then ...
var
hr: HResult
begin
hr := MYOLEFunc;
if SUCCEEDED(hr) then ...
解决方案 »
- 关于createprocess()命令行参数的问题
- 小問題。幫幫忙
- 自己分析了Client和Cerver连接后的问题(麻烦牛人们进来指教指教!最好详细点!)
- IdTCPServer稳定性的问题
- 增加字段
- 用Socket传输文件,点对点已经可以了,但是点对多不知道如何实现
- 我发现书上的例子在编译的时候电脑提示有错误??????????
- 如何用delphi编程实现实时查看上网带宽的占用情况(即上网连接的繁忙程度)?
- 有没有一个属性设置EDIT控件为灰色只读无焦点,不用分别设置
- 数据库记录定位问题
- 告急:如何利用TListview自定义...Draw事件设置ListView中的某个SubItem具有不同与ListView的Font?
- 谢谢你的回答
..
FIDesktopFolder: IShellFolder;
NewPIDL: PItemIDList;
..
OLECheck(SHGetDesktopFolder(FIDesktopFolder));
..
OLECheck(SHGetSpecialFolderLocation(
Application.Handle,
CSIDL_DRIVES,
NewPIDL)
);
SetPath(NewPIDL);请各位帮帮忙?
至于你提到内容在ShlObj单元(源码)有详细描述
我的理解大概是这样的:
..
//得到一个IShellFolder接口,SHGetDesktopFolder相当于CoCreateInstance函数
OLECheck(SHGetDesktopFolder(FIDesktopFolder));
..
//通过CSIDL_DRIVES得到一个PItemIDList变量
OLECheck(SHGetSpecialFolderLocation(
Application.Handle,
CSIDL_DRIVES,
NewPIDL)
);
具体细节我不是很清楚,你还是自己看吧,注释很详细。
A client base application can control transaction context through the ITransactionContextEx interface. The following code example shows how a client application uses CreateTransactionContextEx to create the transaction context. This method returns an interface to this object.
This example wraps the call to the transaction context in a call to OleCheck which is necessary because the CreateInstance method is not declared as safecall. procedure TForm1.MoveMoneyClick(Sender: TObject);begin
Transfer(CLASS_AccountA, CLASS_AccountB, 100);
end;
procedure TForm1.Transfer(DebitAccountId, CreditAccountId: TGuid; Amount: Currency);
var
TransactionContextEx: ITransactionContextEx;
CreditAccountIntf, DebitAccountIntf: IAccount;
begin
TransactionContextEx := CreateTransactionContextEx;
try
OleCheck(TransactionContextEx.CreateInstance(DebitAccountId,
IAccount, DebitAccountIntf));
OleCheck(TransactionContextEx.CreateInstance(CreditAccountId, IAccount, CreditAccountIntf));
DebitAccountIntf.Debit(Amount);
CreditAccountIntf.Credit(Amount);
except
TransactionContextEx.Abort;
raise;
end;
TransactionContextEx.Commit;
end;
2.Setting up a transaction object on the server side
To control transaction context from the MTS server side, you create an instance of ObjectContext. In the following example, the Transfer method is in the MTS object. In using ObjectContext this way, the instance of the object we are creating will inherit all the transaction attributes of the object who is creating it. We wrap the call in a call to OleCheck because the CreateInstance method is not declared as safecall. procedure TAccountTransfer.Transfer(DebitAccountId, CreditAccountId: TGuid; Amount: Currency);
var
CreditAccountIntf, DebitAccountIntf: IAccount;
begin
try
OleCheck(ObjectContext.CreateInstance(DebitAccountId,
IAccount, DebitAccountIntf));
OleCheck(ObjectContext.CreateInstance(CreditAccountId,
IAccount, CreditAccountIntf));
DebitAccountIntf.Debit(Amount);
CreditAccountIntf.Credit(Amount);
except
DisableCommit;
raise;
end;
EnableCommit;
end;