I had some interesting USE CASE’s to solve. Database MetaData proved to be the answer.
For ease of use I created these in the Database MetaData Editor, but any way they are created and applied to the database would have obtained the same result. Alter table modify constraint metadata would do the same job.
What I show below is the metadata I created.
1) I had a caption for a field, nAcctBalance, that had to change based on the value of another field, lHasBalance
I first accessed the MetaData Editor for the nAcctBalance field by doing to the Data section, selecting the table and then the field, and then selecting MetaData Editor from the “gear” menu for the fields dialog.
formitem.caption=[lHasBalance]Balance,Balance Not Used
In the editor the 3 entries would be (showing | to indicate the sections):
formitem.section | lHasBalance | Balance,Balance Not Used
2) the same field, nAcctBalance, which had to be made not Editable when lHasBalance was .T.
formitem.editable | lHasBalance |TRUE,FALSE
Notice the use of oData-style .T. and .F.
3) make the data of nAcctBalance invisible when Balance Not Used
This could have been fancier, but works here:
formitem.dataForeColor | lHasBalance | Black,White
Refreshing the app shows the MetaData effects.
The beauty of this approach is that conditionals can’t be used in the attribute inspector but can in Metadata.
And it refreshes instantly (when lHasBalance is checked or unchecked), even when adding a record and changing the value of lHasBalance. No refresh is need for the conditionals to apply.
This is astounding, really, beyond belief. I have focused on working with Metadata for 21 years and never dreamed of anything this powerful.
In our VFP app, we end up writing methods to run on a Refresh to make these kinds of things happen. We can handle of number of things dynamically, but here we have the ability to use it for every attribute the object has.
This is magic!
is possible to manipulate MetaType from code?
for example add or modify?
whether you can create or modify the metatype files created by the MetaType Editor programmatically the answer is no.
MetaTypes created with the MetaType Editor and MetaDafa attached to databases, tables and columns are two completely different things.
MetaTypes belong to the UI whereas
MetaData belongs to data.
In Lianja 3.4 as stated in the roadmap:
- Added a graphical MetaData Editor for Database, Tables and Columns. Click the “Edit” icon in the ActionBar to show the MetaData Editor. You can find information on how to use MetaData here.