How do I use IStream?

利用IStorage和IStream存储自定义数据到Inventor文件 (C++) 我去年在全球博客就写了此文章,还有一个姊妹篇(用.NETx竟然没有 阅读详情

IStream is a Win32 interface, accessable to alot of programing languages, but is not well documented for Delphi. How do I use IStream?


  There are alot of articles here and elsewhere showing how to convert just about everything to a variant in order to pass it through a COM Interface.  However, most of the VCL has methods and properties already set up to work with streams.  It's much eaiser to work with IStreams.  The trick is using TOLEStream and TStreamAdapter.
  IStream is defined in the ActiveX unit, TStreamAdapter is in Classes, and TOLEStream is in Axctrls.  You can use TStreamAdapter to convert a TStream decendant ( such as TMemoryStream ) to an IStream interface and TOLEStream converts a IStream to a TStream.  The following class wrapps this all together for you.  (WARNING : do not try to convert these functions to a property of type IStream.  There may be a way to do it, but if you do, you may be tempted to use that property to call the IStream methods, which won't really work - or at least, I get access violations)

Uses Classes, ActiveX, Axctrls;

Type TInterfaceStream = Class ( TMemoryStream )
  Public
    Procedure LoadFromIStream(Source : IStream);
    Function GetIStream : IStream;
end;

Procedure TInterfaceStream.LoadFromIStream(Source : IStream);
var
  Adapt : TOLEStream;
  Buff : Byte;
  I : Integer;
begin
ADapt := TOLEStream.Create(Source);
Adapt.Position := 0;
Self.Clear;
Self.Position := 0;
For I := 0 to Adapt.Size do
  begin
    Adapt.Read(Buff, 1);
    Self.Write(Buff, 1);
  end;
Self.Position := 0;
end;

Function TInterfaceStream.GetIStream : IStream;
var
  Adapt : TStreamAdapter;
  tPos : Int64;
begin
Adapt := TStreamAdapter.Create(Self);
Adapt.Seek(0, 0, tPos);
Result := Adapt as IStream;
end;

Now it's simple to use IStream.  For instance, if you have a method of a COM object that your building that needs to return a IStream, simply declare a TInterfaceStream as a private member of the object( we'll call it FStream here), Create it on initialize, and write your method like this

Function TSampleCOMObj.Mehtod1 : IStream
begin
// Here's where you load whatever actually goes into the stream
result := FStream.GetIStream;
end;

Making it a local variable to the method could be a little tricky.  There may be a potentiality that the memory could be deallocated prior to the application using this object gets around to reading the contents.  Making it a private member is safer.

On the application side, simply do the reverse:

Procedure Form1.Button1OnClick(Sender : TObject);
var
  Server : ISampleCOMObj;
  temp : IStream;
  ResultStream : TInterfaceStream;
begin
Server := CreateCOMObject(Class_TSampleCOMObj) as ISampleComObj;
temp := Server.method1;
ResultStream := TinterfaceStream.Create;
ResultStream.Clear;
resultStream.Position := 0;
resultstream.LoadFromIStream(Temp);
// do whatever it is you want with the data in the stream;
end;

This is also a great way to move TStrings around.  IStrings is Delphi specific, but a TStrings saved to a IStream isn't.

将pytorch的权值矩阵量化为定点数补码并导入FPGA中 Xilinx FPGA实现LSTM算法时对ROM的初始化 将pytorch框架的权重矩阵以定点数补码的形式导入到FPGA中 文章目录Xilinx FPGA实现LSTM算法时对ROM的初始化1. pytorch框架中的LSTM2. 初始化一个RNN模型 3. 初始化ROM的coe文件格式 4. 将参数转换为补码,并且输出到coe文件 5. 配置一个ROM 6. 结论7. 代码 1. pytorch框架中的LSTM pytorch框架将LSTM算法中的八个权值矩阵连接成两个矩阵,假设要导入的LSTM网络的输 阅读详情

相关推荐

MySQL安装配置教程(超级详细)

一、 下载MySQL Mysql官网下载地址:MySQL :: Download MySQL Installer (Archived Versions) 1. 选择要安装的版本,本篇文章选择的是5.7.31版本,点击Download下载 正在上传…重新上传取消 二、 安装MySQL 1. 选择设置类型双击运行mysql-installer-community-5.7.31.0.msi 这里选择是自定义安装,所以直接选择“Custom”,点击“Next” “Developer Default”是

m0_67322837的博客 5万+

JAVA I/O流

I/O流概述 字节流 字符流 File类 RandomAccessFile类 NIO NIO.2

爱学习的小段的博客 647

通过声音识别鸟类

根据野生鸟类的外表来识别它是一回事。仅仅根据声音来识别同一只鸟是另一回事。除非你是一个熟练的观鸟者,通过声音识别鸟类可能相当具有挑战性德国马尔堡大学的一组数学、计算机科学和生物学研究人员设计了一种快速识别鸟类和监测当地生物多样性的方法。他们使用连接到 NVIDIA 的便携式设备拍摄的录音根据研究人员的说法是一个边缘人工智能系统,“基于分布式系统中运行的嵌入式边缘设备,能够对森林中记录的声景进行高效、连续的评估。”要了解更多信息,请参阅。

分享AI前沿科技 1680

python中newfile是干嘛用的_python3,new方法,文件基本操作

_ _ new __()方法用于定义创建对象执行的操作object类中的_ _ new __()方法完成对象创建过程中的内存空间申请,对象属性初始化等一系列的操作。_ _ new __()方法创建对象时自动运行覆盖object类中的_ _ new __方法后创建对象将执行覆盖后的方法class Man: # objectdef __new__(cls, *args, **kwar...

weixin_39955423的博客 1355

Spring Cloud 整合(一) CRUD

Springcloud 整合之 CRUDSpringcloud介绍功能概述为什么要选用Springcloud Springcloud介绍 功能概述 实现微服务 Spring Cloud为开发人员提供了工具,以快速构建分布式系统中的某些常见模式(例如,配置管理,服务发现,断路器,智能路由,微代理,控制总线,一次性令牌,全局锁,领导选举,分布式会话,群集状态)。分布式系统的协调导致样板式样,并且使用Spring Cloud开发人员可以快速站起来实现这些样板的服务和应用程序。 为什么要选用Springcloud

Kerwin-Lin的博客 1501

使用自制的NTC测量模块测试Plecs的热仿真效果

可以测试:您完全可以用这个模型来测试热仿真。NTC 模型是连接电气域和热域的关键桥梁。实现闭环:通过这种方式,您创建了一个高度真实的正反馈闭环系统:负载增加 -> 损耗增加 -> 温度升高 -> NTC 阻值变化 -> 控制电路可能因此调整(如降低频率或电流)-> 损耗变化 -> 温度变化。应用场景:这对于设计过温保护 (OTP) 电路风扇控制系统以及分析热失控条件非常有用。单位:确保热域中使用的单位( Kelvin 或 Celsius )与您的 C-Script 模型输入期望的单位一致。

311

How do I use MySQL C++ Connector for storing binary data?

http://stackoverflow.com/questions/1071120/how-do-i-use-mysql-c-connector-for-storing-binary-dataYou have to subclass streambuf e.g. like this:class DataBuf : public streambuf{public:   Data

ghost5216的专栏 1037

msfvenom制作windows/linux/android/ios木马

msfvenom选项如下 -p, --payload<payload> 指定 payload(攻击荷载)。如果使用自定义payload,请使用'-'或者stdin指定。 -l, --list [module_typel列出指定模块的所有可用资源。模块类型包括:payloads, encoders, nops, all -n, --nopsled <length>为payload预先指定一个NOP滑动长度。 -f, --format <format>指定输出格式(使

Cwillchris的博客 2734

c++中istream类的超详细说明

/读取__n长度的字符串保存在__s中,直到读取完成__n个字符或者遇到文件结束符,eofbit及failbit都被置为1。0 可提取min(rdbuf()->in_avail(), __n)个字符。cout << “打开文件出错” << endl;cout << “打开文件出错” << endl;cout << “打开文件出错” << endl;cout << “打开文件出错” << endl;cout << “打开文件出错” << endl;cout << “打开文件出错” << endl;

2501_90193504的博客 647

YOLOv11改进策略【注意力机制篇】| SE、CBAM、ECA、CA、Swin Transformer等注意力机制全面解析与应用

本文详细介绍了五种主流的注意力机制及其在YOLOv11中的应用。通过合理的模块选择和位置部署,注意力机制能够显著提升目标检测性能。

QQ_778132974的博客 876

C# + YOLO 实时摄像头检测:Emgu CV + ONNX Runtime,30FPS+ 流畅运行

很多教程只给“单张图片推理”代码,一上摄像头就卡成 PPT(<5 FPS)。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 215

C++ istream_iterator

From: https://stackoverflow.com/questions/16727125/how-does-stdcopy-work-with-stream-iterators First, note that in this case, there’s no real need to use std::copy at all. You can just initialize the v

Huntinux 1169

云原生监控:Prometheus+Grafana监控Nginx实战

在云原生环境中,应用的高可用性和性能优化至关重要。Nginx作为一款广泛使用的高性能Web服务器、反向代理服务器及电子邮件(IMAP/POP3)代理服务器,对其进行有效的监控能够及时发现潜在问题,保障服务的稳定运行。本文章的目的是详细介绍如何使用Prometheus和Grafana构建一套完整的监控系统来监控Nginx,范围涵盖从环境搭建、数据采集、存储到可视化展示的整个流程。

AI云原生与云计算技术学院 1574

C++之istream与ostream

istream istream类定义了许多用于从流中提取数据和操作文件的成员函数,并对流的析取运算符>>进行了重载,实现了对内置数据量的输入功能 其中常用的几个成员函数是get、getline、read 、ignore ostream ostream类提供了许多用于数据输出的成员函数,并通过流的输出<<重载,实现了对内置数据类型的输出功能。 其中几个常用的成员函数是put、write、flush 输入输出的格式控制 C语言中可以使用scanf()和printf()实现数据的格式化输入输出,

陈小陈的博客 673

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

将 ADO 记录集保存到一个 IStream

将 ADO 记录集保存到一个 IStream ADO 1.5 x 和 2.x Recordset 实施提供了用于数据持久性到磁盘文件的两个函数: 若要将保存到文件中记录集对象 ADORecordset.Save()。 重新加载一个文件中的记录集 ADORecordset.Open()。 出于性能或其他原因它可能有时是所希望将 ADO 记录集保存到内存中,只能作为数据的流。若要完成的您可以使用 A...

泰瑞的博客 506

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

C++编译错误:call to deleted constructor of std::istream

call to deleted constructor of ‘std::istream’ (aka ‘basic_istream’) 示例代码 #include&lt;iostream&gt; using namespace std; int main() { std::istream is = cin; //出错代码 return 0; } 编译代码详细错误如下(g++ m...

Sunrise的专栏 1万+

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

istream java_为什么fstream不使用运算符的istream原型>>?

我有一个类使用友元函数来重载运算符>> . 重载的操作符方法在标准cin使用上测试良好 . 但是,当我尝试升级代码以使用ifstream对象而不是istream对象时,原型不会被识别为有效方法 .我理解ifstream是从istream继承的,因此,多态应该允许ifstream对象与istream重载函数一起运行 . 我的理解有什么问题?是否有必要为每个输入流类型复制函数?类:#inc...

weixin_33206743的博客 158

(转)在C#中使用WinGraphviz,一个COM图论组件,兼谈COM接口IStream在.NET下的互操作

https://blog.csdn.net/qinzhenhua100/article/details/61418159  Graphviz是AT&amp;T实验室的一个项目,提供了通过DOT语言(一种自定义的语言)绘出图论中有向图的工具,当然Graphviz也完全可以用于无向图的绘制。 在图(这里作为数据结构)的可视化方面,Graphviz是非常理想的工具。 WinGraphviz基于Grap...

zyb418的专栏 445

迭代器(ostream_iterator , istream_iterator , reverse_iterator)

迭代器 ostream_iterator , istream_iterator , reverse_iterator //=============================================================== //FileName: // copyit.cpp //Date: // 2019/11/29 //Author...

hm成长之路 202

use of deleted function ‘std::basic_istream<_CharT, _Traits>::basic_istream(const std::basic_istream

下述代码报错,原因是因为istream后漏了一个 & //从输入流中将家庭作业的成绩读入到一个vector<double>中 istream read_hw(istream& in, vector<double>& hw) { if (in) { //清除vector原先的内容 hw.clear(); //读家庭作业成绩 double x; while (in &gt

yuezhilanyi的博客 1098

Istream函数汇总及输入函数总结

Ø  gcount()Return valuesThe extraction count.Remarks Use basic_istream::get to read unformatted characters.Example#include using namespace std; int main( ) { cout Ø  get()int_type get( );basic_ist

冰枫的随笔 2701

GitDB 使用指南:纯 Python 的 Git 对象数据库——从流式接口到四种数据库类型的完整实战

GitDB 是 GitPython 生态中负责对象存储的核心组件:它用纯 Python 建模了标准 Git 对象数据库,将 blob、commit、tree、tag 四类对象统一以 20 字节 SHA-1 为键进行读写。本文以 [gitdb/doc/source/tutorial.rst](https://link.gitcode.com/i/c615a1cbc4034915f07d3c937ec

gitblog_01026的博客 1100

c++ istream转换为std::string

std::istreambuf_iterator&lt;char&gt; eos; std::string s(std::istreambuf_iterator&lt;char&gt;(stream), eos);---------------------------------------------------------------------------- (could be a on...

weixin_33806300的博客 1889

C++ *stream | istream / ostream / iostream 详解

……

u013669912的博客 2027
上一篇: 揭开Outlook Express编辑器的奥秘
下一篇: 拷贝控件的问题
iseekcode
博客等级 码龄18年 36粉丝 14原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值