在帮助中说明DefianeProperties方法是有个例子,如下:
This example shows how to load and save an unpublished property whose value is a component that was created at runtime. It defines two methods, LoadCompProperty and StoreCompProperty that load or save the property value. The also defines an override for the DefineProperties method where these methods are passed to the streaming system. The DefineProperties method checks the filer抯 Ancestor property to avoid saving a property value in inherited forms.procedure TSampleComponent.LoadCompProperty(Reader: TReader);
begin
if Reader.ReadBoolean then
MyCompProperty := Reader.ReadComponent(nil);
end;procedure TSampleComponent.StoreCompProperty(Writer: TWriter);begin
Writer.WriteBoolean(MyCompProperty <> nil);
if MyCompProperty <> nil then
Writer.WriteComponent(MyCompProperty);
end;procedure TSampleComponent.DefineProperties(Filer: TFiler); function DoWrite: Boolean;
begin
if Filer.Ancestor <> nil then { check Ancestor for an inherited value }
begin
if TSampleComponent(Filer.Ancestor).MyCompProperty = nil then
Result := MyCompProperty <> nil
else if MyCompProperty = nil or
TSampleComponent(Filer.Ancestor).MyCompProperty.Name <> MyCompProperty.Name then
Result := True else Result := False;
end
else { no inherited value -- check for default (nil) value }
Result := MyCompProperty <> nil;
end;
begin
inherited; { allow base classes to define properties }
Filer.DefineProperty('MyCompProperty', LoadCompProperty, StoreCompProperty, DoWrite);
end;
请问上面的这个例子该怎么在程序中实现,调试?
TSampleComponent是指得什么控件?请那位高手能够给详细的解释一下,如何使用帮助文件?
参与的人多,回答的全面我会加分,凡来者都有分。。
This example shows how to load and save an unpublished property whose value is a component that was created at runtime. It defines two methods, LoadCompProperty and StoreCompProperty that load or save the property value. The also defines an override for the DefineProperties method where these methods are passed to the streaming system. The DefineProperties method checks the filer抯 Ancestor property to avoid saving a property value in inherited forms.procedure TSampleComponent.LoadCompProperty(Reader: TReader);
begin
if Reader.ReadBoolean then
MyCompProperty := Reader.ReadComponent(nil);
end;procedure TSampleComponent.StoreCompProperty(Writer: TWriter);begin
Writer.WriteBoolean(MyCompProperty <> nil);
if MyCompProperty <> nil then
Writer.WriteComponent(MyCompProperty);
end;procedure TSampleComponent.DefineProperties(Filer: TFiler); function DoWrite: Boolean;
begin
if Filer.Ancestor <> nil then { check Ancestor for an inherited value }
begin
if TSampleComponent(Filer.Ancestor).MyCompProperty = nil then
Result := MyCompProperty <> nil
else if MyCompProperty = nil or
TSampleComponent(Filer.Ancestor).MyCompProperty.Name <> MyCompProperty.Name then
Result := True else Result := False;
end
else { no inherited value -- check for default (nil) value }
Result := MyCompProperty <> nil;
end;
begin
inherited; { allow base classes to define properties }
Filer.DefineProperty('MyCompProperty', LoadCompProperty, StoreCompProperty, DoWrite);
end;
请问上面的这个例子该怎么在程序中实现,调试?
TSampleComponent是指得什么控件?请那位高手能够给详细的解释一下,如何使用帮助文件?
参与的人多,回答的全面我会加分,凡来者都有分。。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货