Y
yue_shan
Unregistered / Unconfirmed
GUEST, unregistred user!
我想这样做,但不行,您给看看:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj,AxCtrls, ActiveX;
type
TEMailItem = class(TCollectionItem)
private
FMsgID: integer;
FBody: TFileStream;
public
procedure Assign(Source: TPersistent);override;
published
property MsgID: integer read FMsgID write FMsgID;
property Body: TFileStream read FBody write FBody;
end;
TEMailItems = class(TCollection)
public
constructor Create;
function Add: TEMailItem;
function GetItem(Index: Integer): TEMailItem;
procedure SetItem(Index: Integer;Value: TEMailItem);
property Items[Index: Integer]: TEMailItem read GetItem write SetItem;
end;
TEMailDummy = class(TComponent)
private
FItems: TEMailItems;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy;override;
published
property Items: TEMailItems read FItems write FItems;
end;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TEMailItem }
procedure TEMailItem.Assign(Source: TPersistent);
begin
if Source is TEMailItem then
begin
FMsgID := TEMailItem(Source).FMsgID;
FBody := TEMailItem(Source).FBody;
end else
Inherited Assign(Source);
end;
{ TEMailItems }
function TEMailItems.Add: TEMailItem;
begin
Result := inherited Add as TEMailItem;
end;
constructor TEMailItems.Create;
begin
inherited Create(TEMailItem);
end;
function TEMailItems.GetItem(Index: Integer): TEMailItem;
begin
Result := inherited GetItem(Index) as TEMailItem;
end;
procedure TEMailItems.SetItem(Index: Integer; Value: TEMailItem);
begin
inherited SetItem(Index,Value);
end;
{ TEMailDummy }
constructor TEMailDummy.Create(AOwner: TComponent);
begin
FItems := TEMailItems.Create;
end;
destructor TEMailDummy.Destroy;
begin
FItems.Free
end;
procedure TForm1.Button1Click(Sender: TObject);
var
FEmailItem: TEMailItem;
FEmailItems: TEmailItems;
F: TFileStream;
FName: WideString;
FRootStorage: IStorage;
stm: IStream;
OS: TOleStream;
Dummy: TEMailDummy;
buf: array[0..1024] of char;
begin
FEmailItems := TEMailItems.Create;
FName := ExtractFileDir(Application.ExeName)+'/aa.html';
F := TFileStream.Create(FName,fmOpenRead);
F.WriteBuffer(buf,sizeof(F));
FEMailItem := FEmailItems.Add;
FEMailItem.MsgID := 100;
FEMailItem.Body.ReadBuffer(buf,sizeof(f));
FName := ExtractFileDir(Application.ExeName)+'/aa.stm';
if not SUCCEEDED(StgOpenStorage(PWideChar(FName),nil,STGM_READWRITE or STGM_SHARE_eXCLUSIVE,nil,0,FRootStorage)) then
OleCheck(StgCreateDocFile(PWideChar(FName),STGM_CREATE or STGM_READWRITE or STGM_SHARE_EXCLUSIVE,0,FRootStorage));
if not SUCCEEDED(FRootStorage.OpenStream('Accounts',nil,STGM_CREATE or STGM_WRITE or STGM_SHARE_EXCLUSIVE,0,stm)) then
OleCheck(FRootStorage.CreateStream('Accounts',STGM_CREATE or STGM_WRITE or STGM_SHARE_EXCLUSIVE,0,0,stm));
Dummy := TEMailDummy.Create(nil);
try
Dummy.Items.Assign(FEmailItems);
OS := TOleStream.Create(stm);
try
OS.WriteComponent(Dummy);
finally
OS.Free;
end;
finally
Dummy.Free;
end;
FEmailItems.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
FEmailItem: TEMailItem;
FEmailItems: TEmailItems;
F: TFileStream;
FName: WideString;
FRootStorage: IStorage;
stm: IStream;
OS: TOleStream;
Dummy: TEMailDummy;
i: integer;
buf: array[0..124] of char;
begin
FEmailItems := TEMailItems.Create;
FName := ExtractFileDir(Application.ExeName)+'/aa.html';
FName := ExtractFileDir(Application.ExeName)+'/aa.stm';
if SUCCEEDED(StgOpenStorage(PWideChar(FName),nil,STGM_READ or STGM_SHARE_eXCLUSIVE,nil,0,FRootStorage)) then
if SUCCEEDED(FRootStorage.OpenStream('Accounts',nil,STGM_READ or STGM_SHARE_EXCLUSIVE,0,stm)) then
begin
Dummy := TEMailDummy.Create(nil);
try
OS := TOleStream.Create(stm);
try
OS.ReadComponent(Dummy);
FEmailItems.Assign(Dummy.Items);
finally
OS.Free;
end;
finally
Dummy.Free;
end;
end;
FName := ExtractFileDir(Application.ExeName)+'/bb.html';
F := TFileStream.Create(FName,fmCreate);
for i:=0 to FEmailItems.Count-1 do
begin
FEmailItem := FEmailItems.Items;
FEMailItem.Body.Write(buf,sizeof(FEMailItem.Body));
F.Read(buf,sizeof(FEMailItem.Body))
// F. := FEMailItem.Body.Create(FName,fmCreate);
end;
F.Free;
FEmailItems.Free;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj,AxCtrls, ActiveX;
type
TEMailItem = class(TCollectionItem)
private
FMsgID: integer;
FBody: TFileStream;
public
procedure Assign(Source: TPersistent);override;
published
property MsgID: integer read FMsgID write FMsgID;
property Body: TFileStream read FBody write FBody;
end;
TEMailItems = class(TCollection)
public
constructor Create;
function Add: TEMailItem;
function GetItem(Index: Integer): TEMailItem;
procedure SetItem(Index: Integer;Value: TEMailItem);
property Items[Index: Integer]: TEMailItem read GetItem write SetItem;
end;
TEMailDummy = class(TComponent)
private
FItems: TEMailItems;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy;override;
published
property Items: TEMailItems read FItems write FItems;
end;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TEMailItem }
procedure TEMailItem.Assign(Source: TPersistent);
begin
if Source is TEMailItem then
begin
FMsgID := TEMailItem(Source).FMsgID;
FBody := TEMailItem(Source).FBody;
end else
Inherited Assign(Source);
end;
{ TEMailItems }
function TEMailItems.Add: TEMailItem;
begin
Result := inherited Add as TEMailItem;
end;
constructor TEMailItems.Create;
begin
inherited Create(TEMailItem);
end;
function TEMailItems.GetItem(Index: Integer): TEMailItem;
begin
Result := inherited GetItem(Index) as TEMailItem;
end;
procedure TEMailItems.SetItem(Index: Integer; Value: TEMailItem);
begin
inherited SetItem(Index,Value);
end;
{ TEMailDummy }
constructor TEMailDummy.Create(AOwner: TComponent);
begin
FItems := TEMailItems.Create;
end;
destructor TEMailDummy.Destroy;
begin
FItems.Free
end;
procedure TForm1.Button1Click(Sender: TObject);
var
FEmailItem: TEMailItem;
FEmailItems: TEmailItems;
F: TFileStream;
FName: WideString;
FRootStorage: IStorage;
stm: IStream;
OS: TOleStream;
Dummy: TEMailDummy;
buf: array[0..1024] of char;
begin
FEmailItems := TEMailItems.Create;
FName := ExtractFileDir(Application.ExeName)+'/aa.html';
F := TFileStream.Create(FName,fmOpenRead);
F.WriteBuffer(buf,sizeof(F));
FEMailItem := FEmailItems.Add;
FEMailItem.MsgID := 100;
FEMailItem.Body.ReadBuffer(buf,sizeof(f));
FName := ExtractFileDir(Application.ExeName)+'/aa.stm';
if not SUCCEEDED(StgOpenStorage(PWideChar(FName),nil,STGM_READWRITE or STGM_SHARE_eXCLUSIVE,nil,0,FRootStorage)) then
OleCheck(StgCreateDocFile(PWideChar(FName),STGM_CREATE or STGM_READWRITE or STGM_SHARE_EXCLUSIVE,0,FRootStorage));
if not SUCCEEDED(FRootStorage.OpenStream('Accounts',nil,STGM_CREATE or STGM_WRITE or STGM_SHARE_EXCLUSIVE,0,stm)) then
OleCheck(FRootStorage.CreateStream('Accounts',STGM_CREATE or STGM_WRITE or STGM_SHARE_EXCLUSIVE,0,0,stm));
Dummy := TEMailDummy.Create(nil);
try
Dummy.Items.Assign(FEmailItems);
OS := TOleStream.Create(stm);
try
OS.WriteComponent(Dummy);
finally
OS.Free;
end;
finally
Dummy.Free;
end;
FEmailItems.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
FEmailItem: TEMailItem;
FEmailItems: TEmailItems;
F: TFileStream;
FName: WideString;
FRootStorage: IStorage;
stm: IStream;
OS: TOleStream;
Dummy: TEMailDummy;
i: integer;
buf: array[0..124] of char;
begin
FEmailItems := TEMailItems.Create;
FName := ExtractFileDir(Application.ExeName)+'/aa.html';
FName := ExtractFileDir(Application.ExeName)+'/aa.stm';
if SUCCEEDED(StgOpenStorage(PWideChar(FName),nil,STGM_READ or STGM_SHARE_eXCLUSIVE,nil,0,FRootStorage)) then
if SUCCEEDED(FRootStorage.OpenStream('Accounts',nil,STGM_READ or STGM_SHARE_EXCLUSIVE,0,stm)) then
begin
Dummy := TEMailDummy.Create(nil);
try
OS := TOleStream.Create(stm);
try
OS.ReadComponent(Dummy);
FEmailItems.Assign(Dummy.Items);
finally
OS.Free;
end;
finally
Dummy.Free;
end;
end;
FName := ExtractFileDir(Application.ExeName)+'/bb.html';
F := TFileStream.Create(FName,fmCreate);
for i:=0 to FEmailItems.Count-1 do
begin
FEmailItem := FEmailItems.Items;
FEMailItem.Body.Write(buf,sizeof(FEMailItem.Body));
F.Read(buf,sizeof(FEMailItem.Body))
// F. := FEMailItem.Body.Create(FName,fmCreate);
end;
F.Free;
FEmailItems.Free;
end;
end.