本例效果圖
代碼文件
unit Unit
interface
uses
Windows
Dialogs
type
TForm
Button
Button
procedure FormCreate(Sender: TObject);
procedure Button
procedure Button
end;
var
Form
implementation
{$R *
Uses Activex;
type
TRec = record
Name: string[
Age: Word;
end;
const FileName =
procedure TForm
begin
Button
Button
Position := poDesktopCenter;
end;
procedure TForm
const
Mode = STGM_CREATE or STGM_READWRITE or STGM_SHARE_EXCLUSIVE;
var
StgRoot
Stm: IStream;
Rec
begin
{建立根 IStorage: StgRoot}
StgCreateDocfile(FileName
{建立子 IStorage: StgSub}
StgRoot
{在子 IStorage: StgSub 中建立 IStream: Stm}
StgSub
{寫入數據}
Rec
Rec
Stm
end;
procedure TForm
const
Mode = STGM_READ or STGM_SHARE_EXCLUSIVE;
Var
StgRoot
Stm: IStream;
Rec
Begin
{如果不是結構化存儲文件則退出}
if StgIsStorageFile(FileName) <> S_OK then Exit;
{獲取根 IStorage: StgRoot}
StgOpenStorage(FileName
{獲取子 IStorage: StgSub; 注意: 第一個參數的名稱必須和保存時一致}
StgRoot
{獲取 IStream: Stm; 注意: 第一個參數的名稱必須和保存時一致}
StgSub
{讀出數據}
Stm
ShowMessageFmt(
end;
end
窗體文件
object Form
Left =
Top =
Caption =
ClientHeight =
ClientWidth =
Color = clBtnFace
Font
Font
Font
Font
Font
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch =
TextHeight =
object Button
Left =
Top =
Width =
Height =
Caption =
TabOrder =
OnClick = Button
end
object Button
Left =
Top =
Width =
Height =
Caption =
TabOrder =
OnClick = Button
end
end
From:http://tw.wingwit.com/Article/program/Delphi/201311/24675.html