Quick Tip: Fixing “Could not convert variant of type (Null) into type…”
I often use the XML Data Binding wizard in Delphi. However, it doesn’t seem to have been given a lot of attention from Borland/Inprise/Borland/CodeGear/Embarcadero/Idera. And unfortunately, out of the box what it generates is often error prone, apparently not supporting optional elements/attributes.
When the generated code tries to read an optional element or attribute, you will get a “Could not convert variant of type (Null) into type” exception.
The offending code usually looks like this:
function TXMLMyType.Get_OptionalElement: Single;
begin
Result := ChildNodes['OptionalName'].NodeValue;
end;
If you do a little googling, you will see that people are still asking questions about this even pretty recently. The suggested fix you will often discover is labor intensive if you have a lot of optional elements/attributes an
Delphi开发技巧: 修复XML数据绑定错误: “Could not convert variant of type (Null) into type…”!
最新推荐文章于 2024-11-27 16:20:46 发布