流(Streams)编程:写文件前要筹建流;
创建流: IStorage.CreateStream;
打开流: IStorage.OpenStream;
读取流: IStream.Read; Delphi中在读取数据时采用IOleStream;
向流中写数据: IStream.write; Delphi中常常采用TOleStream的类;
创建和使用附加存储(Additional Storages):在存储中创建和访问流;还可以创建子存储;
创建附加存储: IStorage.CreateStorage;
打开已存在的存储(不是根存储):IStorage.OpenStorage;
创建流: IStorage.CreateStream;
打开流: IStorage.OpenStream;
读取流: IStream.Read; Delphi中在读取数据时采用IOleStream;
向流中写数据: IStream.write; Delphi中常常采用TOleStream的类;
创建和使用附加存储(Additional Storages):在存储中创建和访问流;还可以创建子存储;
创建附加存储: IStorage.CreateStorage;
打开已存在的存储(不是根存储):IStorage.OpenStorage;
解决方案 »
- 请教:在erp中,锁这个概念用的多吗?
- 关于拦截系统声音的难题!
- 刚开始学Delphi,请问网上有什么关于控件的参考吗?
- 在 线程外 如何判断线程已经结束;
- 论坛没有关闭以前参与 寻找数据库表格控件,欢迎光临的 请进。
- 小弟想入门,那位前辈有DELPHI数据控件的电子帮助文档呀,属情方法之类的
- 如何让窗体在运行时,位于屏幕的左上角?
- 关于DataModule
- 2008年10月份编程语言排行榜 Delphi持续上升
- 写了HOOK 程序,谁知道有关F4的代码值,比如
- 求时间加减函数,如果2004-5-8 10:10:10 15小时前怎么得到2004-5-9 2:10:10?
- 请教高手 关于分布开发的更新问题???急啊 !!求救?
比如说TStreamAdapter对IStream接口的支持。
msdn上面的都是英文,小弟的说平实在说部出口,看了半天也没有看的懂...
var
stgenum:IEnumStatStg;
tree:TTreeNodes;
vstatstg:STATSTG;
newNode:TTreeNode;
stgtmp:IStorage;
begin
stg.EnumElements(0,nil,0,stgenum);
while(stgenum.Next(1,vstatstg,nil)=NOERROR) do
begin
tree:=node.Owner;
newNode:=tree.AddChild(node,string(vstatstg.pwcsName)); if (vstatstg.dwType)=STGTY_STORAGE then
begin
newNode.ImageIndex:=2;
if stg.OpenStorage(vstatstg.pwcsName,nil,
STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
nil,0,stgtmp)=S_OK then
begin
TreeShowStorge(stgtmp,newNode);
end;
end
else if vstatstg.dwType=STGTY_STREAM then
begin
Newnode.ImageIndex:=3
end
end;
end;
procedure TFrmMain.OpenSTG(fname: string);
var
s:string;
stgroot:IStorage;
root:TTreeNode;
begin root:=TreeView2.Items.AddChild(nil,'root'); if StgOpenStorage(StringToOleStr(fname),
nil,
STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
nil,0,
stgroot
)=S_OK then
begin
TreeShowStorge(stgroot,root);
end;
end;
procedure TFrmMain.Button2Click(Sender: TObject);
beginif OpenDialog1.Execute then
OpenSTG(OpenDialog1.FileName);
end;
var
stgenum:IEnumStatStg;
tree:TTreeNodes;
vstatstg:STATSTG;
newNode:TTreeNode;
stgtmp:IStorage;
begin
stg.EnumElements(0,nil,0,stgenum);
while(stgenum.Next(1,vstatstg,nil)=NOERROR) do
begin
tree:=node.Owner;
newNode:=tree.AddChild(node,string(vstatstg.pwcsName)); if (vstatstg.dwType)=STGTY_STORAGE then
begin
newNode.ImageIndex:=2;
if stg.OpenStorage(vstatstg.pwcsName,nil,
STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
nil,0,stgtmp)=S_OK then
begin
TreeShowStorge(stgtmp,newNode);
end;
end
else if vstatstg.dwType=STGTY_STREAM then
begin
Newnode.ImageIndex:=3
end
end;end;procedure TFrmMain.OpenSTG2(fname: string);
var
s:string;
stgroot:IStorage;
root:TTreeNode;
begin
root:=TreeView2.Items.AddChild(nil,'root'); if StgOpenStorage(StringToOleStr(fname),
nil,
STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
nil,0,
stgroot
)=S_OK then
begin
TreeShowStorge(stgroot,root);
end;
end;procedure TFrmMain.Button2Click(Sender: TObject);
beginif OpenDialog1.Execute then
OpenSTG(OpenDialog1.FileName);end;
我写的那例子没有用它,不过想来剩下内容已经比较简单了。
最后一个问题:用流的形式写入文件,那么这个文件用记事本等普通的文本浏览器可以直接看到内容吗?我得意思是:我想把写入流文件的内容有加密功能,用普通的文本编辑器打开内容是杂乱无章的乱码,请问如何实现?