Mega Code Archive

 
Categories / Delphi / Files
 

How to create read from a structured storage file Part 2

Title: How to create / read from a structured storage file Part 2 Question: How to read data from a structured storage file Answer: Article discontinued Due To Abuse. // Part 2 // Author Cjpsoftware.. Not for commercial use... // contact C J Pringle support@cjpsoftware.com // Part 2 on how to read / write from a structured // storage file.. // Copy / paste this unit into a new application // add 1 edit box and two buttons // When you are ready. // Click on Write data 1000 the number will be wrote to the // storage file // click read data the sturctured file will br openned and // the stream read. The value will be displayed in the edit box. // I have provided the unit you can download unit testunit; interface uses Windows, Messages, SysUtils,activex,axctrls, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,comobj; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public FRootStorage: IStorage; stm: IStream; { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} // Write data fromn ss file // procedure TForm1.Button1Click(Sender: TObject); var strfile: PWideChar; Myvalue: Integer; BytesWritten: Longint; begin // Structured Storeage File Strfile := 'Sh.ss'; // === if not SUCCEEDED(StgOpenStorage(Strfile, nil, STGM_READWRITE or STGM_SHARE_EXCLUSIVE, nil, 0, FRootStorage)) then Begin StgCreateDocFile(strfile, STGM_CREATE or STGM_READWRITE or STGM_SHARE_EXCLUSIVE, 0, FRootStorage); FRootStorage.CreateStream('Index', STGM_CREATE or STGM_READWRITE or STGM_SHARE_EXCLUSIVE, 0, 0, stm); End; Myvalue := 1000; // Write Datat To Stream Olecheck(Stm.Write(@MyValue,sizeof(Integer),@BytesWritten)); end; // read Data from ss file // procedure TForm1.Button2Click(Sender: TObject); Var Myvalue: Integer; Bytesread: Longint; begin // Open Storage File If SUCCEEDED(StgOpenStorage('sh.ss', nil, STGM_READWRITE or STGM_SHARE_EXCLUSIVE, nil, 0, FRootStorage)) Then Begin // Open the stream within the ss file OleCheck(FRootstorage.OpenStream('Index',Nil,STGM_READWRITE or STGM_SHARE_EXCLUSIVE,0,Stm)); Stm.read(@MyValue,Sizeof(integer),@Bytesread); Edit1.text := Inttostr(MyValue); End; end; end.