procedure TMainForm
begin
if OpenDialog
begin
DesignWin := TMDIChild
ReadComponentResFile(OpenDialog
DesignWin
FileName := OpenDialog
DesignWin
end;
end;
DesignWin是在TMainForm中定義的TMDIChild類型的窗體部件
procedure TMDIChild
var
I: Integer;
Ctrl: TControl;
begin
BackGround
with BackGround do
for I:=
if Controls[I]
ObjectIns
end;
BackGround是TPanel類型的部件
動態DFM文件的存儲過程是這樣的
procedure TMainForm
begin
if DesignWin
DesignWin
WriteComponentResFile(FFilename
DesignWin
end;
end;
因為在DesignWin的Init方法中調用了InsertControl方法
procedure TMDIChild
var
I: Integer;
Ctrl: TControl;
Removed: Boolean;
begin
if Modified = True then
if MessageDlg(
[mbOk
CanClose := False;
if CanClose = True then
begin
repeat
removed := False;
I :=
repeat
if BackGround
begin
BackGround
Removed := True;
end;
I := I +
until (I >= BackGround
until (Removed = False)
SendMessage(ObjectIns
end;
end;
超媒體腳本語言設計是超媒體系統設計的重要內容
DFM文件可以看作是超媒體系統的卡片
ObjectBinaryToText和ObjectTextToBinary過程提供了在部件和DFM腳本之間相互轉化的功能
下面是卡片和腳本語言相互轉化的程序
procedure TMDIChild
var
In
begin
In := TMemoryStream
Out := TMemoryStream
try
In
ObjectResourceToText(In
ScriptForm
finally
In
Out
end;
end;
ScriptEdit是個文本編輯器
procedure TScriptForm
var
In
begin
In := TMemoryStream
Out := TMemoryStream
try
ScriptForm
ObjectTextToResource(In
In
finally
In
Out
end;
end;
這兩段程序是對整個卡片
超媒體系統的媒體編輯與卡片管理有其特殊的需求
● 利用Delphi部件開發技術
● 擴展DFM文件結構
前者是充分利用Delphi的面向對象部件開發技術
擴展動態DFM文件的總體思路是降低處理操作的數據的顆粒度
下面是存取操作的擴展示范
var
FileStream: TStream;
I: Integer;
begin
FileStream := TFileStream
With TWriter
try
for I :=
begin
WriteInteger(MMID[i])
WriteRootComponent(DesignWin
{ 寫相應媒體擴展信息 }
……
end;
WriteListEnd;
finally
Free;
end;
FileStream
end;
WriteInteger(MMID[i])語句是寫入媒體標識
下面是相應的讀擴展DFM的程序
var
PropInfo: PPropInfo;
Method : TMethod;
FileStream: TStream;
I: Integer;
begin
FileStream := TFileStream
With TReader
try
while not EndOfList do
begin
case ReadInteger of
IDText: begin
Ctrl := TControl(ReadRootComponent(nil))
PropInfo := GetPropInfo(Ctrl
Method
Method
if Method
SetMethodProp(Ctrl
DesignWin
end;
IDImage:
……
end;
……
WriteListEnd;
end;
finally
Free;
end;
FileStream
end;
SetMethodProp過程是用於重新聯接控制和它的事件處理過程
實現腳本語言擴展的基本方法與存取擴展類似
Delphi VCL提供了TBlobStream對象支持對數據庫BLOB字段的存取
TBlobStream對象用一個TBlobField類型的對象作為參數來創建與BLOB字段相聯的BLOB流
var
BlobStream: TBlobStream;
I: Integer;
begin
BlobStream := TBlobStream
With TWriter
try
for I :=
begin
WriteInteger(MMID[i])
WriteRootComponent(DesignWin
{ 寫相應媒體擴展信息 }
……
end;
WriteListEnd;
finally
Free;
end;
BlobStream
CardTable
end;
Fields變量是表示數據庫記錄的字段數組
上面這段程序是超媒體卡片存儲的部分源程序
var
PropInfo: PPropInfo;
Method: TMethod;
Blobtream: TStream;
I: Integer;
begin
BlobStream := TBlobStream
With TReader
try
while not EndOfList do
begin
case ReadInteger of
IDText: begin
Ctrl := TControl(ReadRootComponent(nil))
PropInfo := GetPropInfo(Ctrl
Method
Method
if Method
SetMethodProp(Ctrl
DesignWin
end;
IDImage:
……
end;
……
WriteListEnd;
end;
finally
Free;
end;
FileStream
end;
在多媒體數據庫中處理得比較多的是圖形圖像
在TBlobField對象中提供了LoadFromBitMap和SaveToBitMap方法存取位圖數據
procedure TBlobField
var
BlobStream: TBlobStream;
Header: TGraphicHeader;
begin
BlobStream := TBlobStream
try
if (DataType = ftGraphic) or (DataType = ftTypedBinary) then
begin
Header
Header
Header
BlobStream
Bitmap
Header
BlobStream
BlobStream
end else
Bitmap
finally
BlobStream
end;
end;
procedure TBlobField
var
BlobStream: TBlobStream;
Size: Longint;
Header: TGraphicHeader;
begin
BlobStream := TBlobStream
try
Size := BlobStream
if Size >= SizeOf(TGraphicHeader) then
begin
BlobStream
if (Header
(Header
BlobStream
end;
Bitmap
finally
BlobStream
end;
end;
程序中按兩種方式存取數據
[
From:http://tw.wingwit.com/Article/program/Delphi/201311/25090.html