如何在Delphi中使用tagDEC
我已将通过 COM Interop 提供的 .Net 类库导入到 Delphi 2007 中,并且 Decimal 数据类型作为 tagDEC 打包记录提供。如何填写使用此记录类型以便我可以使用类库?
Tks
编辑
下面是我的 C# 代码,通过 COM Interop 作为 ActiveX 公开:
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("ClassLibrary.Class1")]
public class Class1
{
[ComVisible(true)]
public string Method1(DateTime pDateTime, int pID, decimal pQty)
{
...........
}
}
我使用 Delphi 在 PC 上使用 regasm 注册该库,命令如下:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe .\ClassLibrary.dll /tlb:ClassLibrary.tlb
在 Delphi 2007 中,通过导入组件,我导入类型库,并在代理类中将其转换为以下方法:
function Method1(pDateTime: TDateTime; pID: Integer; pQty: TDecimal): WideString;
TDecimal
实际上是 tagDEC
类型的打包记录
,在 ActiveX
单元中找到。下面是它的语法:
{ from WTYPES.H }
PDecimal = ^TDecimal;
{$EXTERNALSYM tagDEC}
tagDEC = packed record
wReserved: Word;
case Integer of
0: (scale, sign: Byte; Hi32: Longint;
case Integer of
0: (Lo32, Mid32: Longint);
1: (Lo64: LONGLONG));
1: (signscale: Word);
end;
TDecimal = tagDEC;
{$EXTERNALSYM DECIMAL}
DECIMAL = TDecimal;
我的问题是如何填写它,以便我可以将十进制值传递到 .Net 类库方法中?有没有辅助功能?我没有找到。
再次感谢!
I have imported a .Net Class Library made available through COM Interop into Delphi 2007, and a Decimal data type was made available as a tagDEC packed record. How do I fill use this record type so I can use the Class Library?
Tks
Edit
Below is my C# code that is exposed as a ActiveX through COM Interop:
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("ClassLibrary.Class1")]
public class Class1
{
[ComVisible(true)]
public string Method1(DateTime pDateTime, int pID, decimal pQty)
{
...........
}
}
I register the library with regasm on the PC with Delphi, with the command below:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe .\ClassLibrary.dll /tlb:ClassLibrary.tlb
In Delphi 2007, through the Import Component, I import the Type Library, and it get's converted into the following method at the proxy class:
function Method1(pDateTime: TDateTime; pID: Integer; pQty: TDecimal): WideString;
The TDecimal
is actually a packed record
of type tagDEC
, found in the ActiveX
unit. Below is it's syntax:
{ from WTYPES.H }
PDecimal = ^TDecimal;
{$EXTERNALSYM tagDEC}
tagDEC = packed record
wReserved: Word;
case Integer of
0: (scale, sign: Byte; Hi32: Longint;
case Integer of
0: (Lo32, Mid32: Longint);
1: (Lo64: LONGLONG));
1: (signscale: Word);
end;
TDecimal = tagDEC;
{$EXTERNALSYM DECIMAL}
DECIMAL = TDecimal;
My question is how to I fill this in, so I can pass the decimal value into the .Net Class Library method? Is there any helper function? I didn't find any.
Tks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
巧合的是,我本周遇到了相反的问题:我正在 Delphi 中通过 COM 使用 C# 库,其中某些 C# 方法返回
decimal
(TDecimal
或Delphi 中的tagDEC
),并且还想知道如何处理它。在搜索了 ActiveX、ComObj 和 OleServer 单元后,我发现了这个函数:
它成功了。我有 Delphi,也没有前面提到的方便的来源,但很可能您会在这些单元中找到一种可以执行相反操作的方法。
不是一个明确的答案,但也许对你有帮助。
By coincidence, I had the opposite problem this week: I'm consuming a C# library through COM in Delphi, where some of the C# methods return a
decimal
(aTDecimal
ortagDEC
in Delphi), and was also wondering what to do with it.After searching through the ActiveX, ComObj and OleServer units I found this function:
Which did the trick. I have Delphi, nor the aforementioned sources handy here, but chances are that in you'll find a method in those units that will do the reverse.
Not a clear cut answer, but maybe it helps you.
你为什么不简单地尝试一下呢?我不是 .NETty,所以我无法测试,但是
例如将比例设置为 10000,hi32 设置为 5432,符号设置为 0。因此,幸运的是尝试通过 +5432/10000= 0.5432,假设符号为 TRUE 表示负数,0 表示正数(可能是相反的情况)
我有点担心不过与你的标题。匈牙利语前缀“p”似乎表示指针值。
Why don't you simple try? I'm not a .NETty, so I can' test, but
e.g. Set scale to 10000, hi32 to 5432 and sign to 0. So a luckily attempt to pass +5432/10000= 0.5432, assuming sign is TRUE for negative and 0 for positive (it may be the other way around)
I am a bit concerned with your header though. The "p" Hungarian prefix seems to indicate pointer values.
如果您愿意,您可以将 Decimal 视为不透明类型。为此,您需要从 C# 代码中导出合成 Decimal 值所需的帮助程序,然后从 Delphi 中调用该代码。我的猜测是你会想要一个 Double ->十进制助手,也许反之亦然。
或者,您可以修改 C#/COM 接口以使用双精度数,并在 C# 一侧转换为十进制。
You could regard Decimal as an opaque type if you wish. To do so you would export from your C# code the helpers you need to synthesise Decimal values and then call that code from Delphi. My guess is that you would want a Double -> Decimal helper and perhaps vice versa.
Alternatively you could modify the C#/COM interface to use doubles and convert to Decimal on the C# side of the fence.