第二十章 開發Delphi對象式數據管理功能(五)
該過程帶有兩個參數FileName和Instance
這個過程的意義在於
該過程的程序是這樣的
procedure WriteComponentResFile(const FileName: string; Instance: TComponent)
var
Stream: TStream;
begin
Stream := TFileStream
try
Stream
finally
Stream
end;
end;
函數中
ReadComponentResFile函數帶有兩個參數FileName和Instance
這個函數的意義在於
該函數的程序是這樣的
function ReadComponentResFile(const FileName: string; Instance: TComponent)
TComponent;
var
Stream: TStream;
begin
Stream := TFileStream
try
Result := Stream
finally
Stream
end;
end;
程序中使用FileStream對象打開由FileName指定的DFM文件
函數InternalReadComponentRes可以讀取Delphi應用程序資源中的部件
在第一節中曾經介紹過TResourceStream對象
function InternalReadComponentRes(const ResName: string;
var Instance: TComponent)
var
HRsrc: THandle;
begin { 避免
HRsrc := FindResource(HInstance
Result := HRsrc <>
if not Result then Exit;
FreeResource(HRsrc)
with TResourceStream
try
Instance := ReadComponent(Instance)
finally
Free;
end;
Result := True;
end;
HInstance是一個Delphi VCL定義的全局變量
在Delphi可視化設計環境中
實際上
ObjectBinaryToText過程將二進制流中存儲的部件轉化為基於文本的表現形式
ObjectBinaryToText過程的主程序是這樣的
procedure ObjectBinaryToText(Input
var
NestingLevel: Integer;
SaveSeparator: Char;
Reader: TReader;
Writer: TWriter;
procedure WriteIndent;
const
Blanks: array[
var
I: Integer;
begin
for I :=
end;
procedure WriteStr(const S: string)
begin
Writer
end;
procedure NewLine;
begin
WriteStr(#
WriteIndent;
end;
procedure ConvertHeader;
begin
…
end;
procedure ConvertBinary;
begin
…
end;
procedure ConvertValue;
begin
…
end;
procedure ConvertProperty;
begin
…
end;
procedure ConvertObject;
begin
…
end;
begin
NestingLevel :=
Reader := TReader
SaveSeparator := DecimalSeparator;
DecimalSeparator :=
try
Writer := TWriter
try
Reader
ConvertObject;
finally
Writer
end;
finally
DecimalSeparator := SaveSeparator;
Reader
end;
end;
過程中調用的ConvertObject過程是個遞歸過程
procedure ConvertObject;
begin
ConvertHeader;
Inc(NestingLevel)
while not Reader
Reader
while not Reader
Reader
Dec(NestingLevel)
WriteIndent;
WriteStr(
end;
NestStingLevel變量表示部件的嵌套層次
Inherited TestForm
或者
Object TestForm
前者是ffInherited和ffChildPos置位
ConvertProperty過程用於轉化屬性
procedure ConvertProperty;
begin
WriteIndent;
WriteStr(Reader
WriteStr(
ConvertValue;
WriteStr(#
end;
WriteIndent語句寫入屬性名前的空格
[
From:http://tw.wingwit.com/Article/program/Delphi/201311/25088.html