TQTXReader and TQTXWriter for Smart Mobile Studio
Storage has become a theme the past couple of weeks for Smart Mobile Studio. I have posted twice about the filesystem classes I have added to QTX, but I have also added more – much more! As you will see over the next weeks 🙂
The writer allows you to, well.. write into a buffer (managed by the class). Like this:
var mObj:=TQTXWriter.Create(null); try mObj.writeStr("first-name",edFirstname.text); mobj.writeStr("last-name",edLastName.text); mObj.writeStr("cardID",edVisa.text); CallCardLookup(mObj.Deserialize, procedure () begin showmessage("Visa card is valid"); end); finally mObj.free; end;
And TQTXReader does the exact same, but in reverse. The constructor can take a variant containing the information you want to read (stored with TQTXWriter) and extract info in the same way.
Loads! You can use it to tailor custom messages to be used with the spanking new message-api. That way you don’t have to fiddle with JObject based classes. Serialize() and Deserialize() are the methods for turning the data into a string and back again.
You can use it to avoid strictly typed records, which can be handy – especially for grid designs and/or “flexible” arrays of content. But please remember that Serialize() and Deserialize() are costly in terms of speed.
It’s also perfect to interface with JS libraries which expects name-value pairs in constructors and setup routines.
But word to the wise – if all you need is a one-shot wonder, then TQTXWriter is overkill. In such a case you can get away with an anonymous record:
Fhandle.setupJS( record mouse := "yes"; startX := 100; startY := 100; end);