OfficeXml/openxml/OpenXmlSimpleType.tsf

105 lines
3.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

type OpenXmlSimpleType = class(OpenXmlElement)
public
function Init();override;
function InitNode(_node: XmlNode);override;
function Copy(_obj: tslobj);override;
function Deserialize();override;
function Serialize();override;
function Marshal(): tableArray;override;
public
// attributes property
XmlAttrVal;
property Val read ReadXmlAttrVal write WriteXmlAttrVal;
function ReadXmlAttrVal();
function WriteXmlAttrVal(_value: any);
// 动态获取IsApplied
// IsApplied: boolean; // 是否已经应用和val值有关
property IsApplied read ReadIsApplied;
function ReadIsApplied();
public
Enable: boolean; // 是否启用 <b /> 没有属性需要通过val写属性
end;
function OpenXmlSimpleType.Init();override;
begin
{self.}Enable := false;
end;
function OpenXmlSimpleType.InitNode(_node: XmlNode);override;
begin
{self.}XmlNode := ifObj(_node) ? _node : nil;
end;
function OpenXmlSimpleType.Copy(_obj: tslobj);override;
begin
if not ifnil(_obj.Enable) then {self.}Enable := _obj.Enable;
if not ifnil(_obj.XmlAttrVal.Value) then {self.}Val := _obj.XmlAttrVal.Value;
end;
function OpenXmlSimpleType.Marshal(): tableArray;override;
begin
if not {self.}Enable then return array();
attr := array();
if not inil({self.}XmlAttrVal.Value) then attr[{self.}XmlAttrVal.ElementName] := {self.}XmlAttrVal.Value;
arr := array("type": "element", "name": name_, "attributes": attr, "children": array());
return arr;
end;
function OpenXmlSimpleType.Deserialize();override;
begin
if ifObj({self.}XmlNode) then
begin
attrs := {self.}XmlNode.Attributes();
if length(attrs) > 1 then
begin
echo "OpenXmlSimpleType.Deserialize error.\n";
return;
end
{self.}Val := nil;
for k,v in attrs do
{self.}Val := v;
{self.}Enable := true;
end
else begin
{self.}Enable := false;
{self.}XmlAttrVal := nil;
end
end;
function OpenXmlSimpleType.Serialize();override;
begin
if not ifObj({self.}XmlNode) then
begin
if not ifnil({self.}XmlAttrVal.Value) then {self.}GetNode().SetAttribute({self.}XmlAttrVal.ElementName, {self.}XmlAttrVal.Value);
end
else begin
if not {self.}Enable or {self.}Removed then
{self.}Parent.XmlNode.DeleteChild({self.}XmlNode);
else if not ifnil({self.}XmlAttrVal.Value) then
{self.}XmlNode.SetAttribute({self.}XmlAttrVal.ElementName, {self.}XmlAttrVal.Value);
end
end;
function OpenXmlSimpleType.ReadXmlAttrVal();
begin
return {self.}XmlAttrVal.Value;
end;
function OpenXmlSimpleType.WriteXmlAttrVal(_value: any);
begin
if ifnil({self.}XmlAttrVal) then
{self.}XmlAttrVal := new OpenXmlAttribute({self.}Prefix, "val", nil);
{self.}XmlAttrVal.Value := _value;
{self.}Enable := true;
end;
function OpenXmlSimpleType.ReadIsApplied();
begin
if {self.}Enable then
return {self.}XmlAttrVal.Value = "0" or {self.}XmlAttrVal.Value = "false" ? false : true;
return false;
end;