您可以创建自己的方法来读取和写入属性,方法是编写自己的方法来执行二进制数据与流之间的流式传输,并使用 和 将它们注册到 VCL/RTL 流式传输DefineProperties
系统DefineBinaryProperty
。JEDI JVCL 单元 JVXSlider.pas 中有一个易于理解的示例:
// interface
type
TJvCustomSlider=class(TJvCustomControl)
private
procedure ReadUserImages(Stream: TStream);
procedure WriteUserImages(Stream: TStream);
...
protected
procedure DefineProperties(Filer: TFiler); override;
// implementation
procedure TJvCustomSlider.DefineProperties(Filer: TFiler);
function DoWrite: Boolean;
begin
if Assigned(Filer.Ancestor) then
Result := FUserImages <> TJvCustomSlider(Filer.Ancestor).FUserImages
else
Result := FUserImages <> [];
end;
begin
// @RemyLebeau points out that the next line is apparently a bug
// in the JVCL code, and that inherited DefineProperties should always
// be called regardless of the type of Filer. Commented it out, but
// didn't delete it because it *is* in the JVCL code I cited.
//if Filer is TReader then
inherited DefineProperties(Filer);
Filer.DefineBinaryProperty('UserImages', ReadUserImages, WriteUserImages, DoWrite);
end;
procedure TJvCustomSlider.ReadUserImages(Stream: TStream);
begin
Stream.ReadBuffer(FUserImages, SizeOf(FUserImages));
end;
procedure TJvCustomSlider.WriteUserImages(Stream: TStream);
begin
Stream.WriteBuffer(FUserImages, SizeOf(FUserImages));
end;
Delphi 流系统会根据需要自动为定义的属性(在上面的示例中为 property )调用适当的方法,以自动UserImages
保存到 dfm 文件或从 dfm 文件中读取;你永远不需要自己打电话给他们。