Page 1 of 1

Preserve persistent fields when loading from stream

Posted: Sat 28 Feb 2015 13:17
by jim papas
I try to use VirtualTable (v9.4.8 for XE7) in my app.
I have a table with many lookup and calculated fields among other data fields.
When i load the table from a previous saved stream/file, the persistent fields become nil, so i can refer them only using "fieldByName".
But the most important is that i have to recreate the lookup and calculated fields every time i load the table and this happens hundred times (slave tables of a master table).
I saw this announcement "15-Jun-11 New Features in VirtualTable 7.20
•Possibility to load data without recreating persistent fields is added[/i]"
This means that THERE IS a way to preserve them.
What can i do to do this, please ?

Re: Preserve persistent fields when loading from stream

Posted: Mon 02 Mar 2015 12:00
by AlexP
Hello,

To solve the problem, you should set False as the second parameter on the LoadFromStream/LoadFromFile method

Code: Select all

VirtualTable1.LoadFromStream(MemorySream, False);

Re: Preserve persistent fields when loading from stream

Posted: Mon 02 Mar 2015 15:08
by jim papas
Thanks, this solved my problem. Shame to me that i didn't saw that it has second parameter !
But now another problem raised up.
Some persistent boolean fields have defaultExpresion AND displayValues.
Loading from stream i receive the error "FALSE is not a valid boolean value for field xxx"
It seems that defaultExpresion and displayValues prevents one the other. They can't excist together.
Is this the case ?

Re: Preserve persistent fields when loading from stream

Posted: Tue 03 Mar 2015 09:44
by AlexP
This occurs due to incorrect setting of DisplayValues for Boolean fields. For such fields, DisplayValues must be set in the following way:

Code: Select all

BooleanField.SetDisplayValues := 'TRUE;FALSE';
Where the first value is True, and the second one is False. These values are saved in the FTextValues array in the TBooleanField.SetDisplayValues method.

Re: Preserve persistent fields when loading from stream

Posted: Tue 03 Mar 2015 10:29
by jim papas
Yes, i found that it saves boolean fields as text not as byte.
So i must set as default value one of the displayValues eg
defaultValue : aaa
displayValues: aaa;bbb

But... another issue arrived.
The autoinc field doesn't get value by itself. It works like an integerField. I can set any value in it.
I tried setting the autoGenerateValue to arAutoInc without success

Re: Preserve persistent fields when loading from stream

Posted: Tue 03 Mar 2015 12:44
by AlexP
The ftAutoInc field type means, that data in this field will be generated automatically at the level of the database (depending on the algorithm of retrieving auto-incremental values). There is no sense to use this field type in VirtualTable.

Re: Preserve persistent fields when loading from stream

Posted: Tue 03 Mar 2015 13:20
by jim papas
ok, i can live without it.
But, i think that should be supported, as other memTables do, since it is there.

As far as i see, your component is better than others. Thanks

Re: Preserve persistent fields when loading from stream

Posted: Tue 03 Mar 2015 14:17
by AlexP
You can leave your suggestion on our uservoice page. If it gets enough user votes, we will implement it.
Currently, to implement behavior similar to auto-incrementation, you can use events, for example, BeforeInsert and AfterPost to fill in the required field with the needed values.