Descriptor (TQueryExecuteTask)
De Wiki1000
(Différences entre les versions)
(→exporter) |
(→exporter) |
||
Ligne 24 : | Ligne 24 : | ||
<source lang="delphi"> | <source lang="delphi"> | ||
//Function CreateDescriptor():TxmlDocument; | //Function CreateDescriptor():TxmlDocument; | ||
− | var itr,itqs,itq,itt,itcs,itc,itu,itvs,itv:TxmlItem; | + | var itr,itqs,itq,itt,itcs,itc,itu,itvs,itv,itas:TxmlItem; |
begin | begin | ||
Result := TxmlDocument.Create(nil); | Result := TxmlDocument.Create(nil); | ||
itr := TxmlItem.Create(Result); | itr := TxmlItem.Create(Result); | ||
itr.ItemName := 'root'; | itr.ItemName := 'root'; | ||
− | // | + | |
+ | // Add a main query | ||
+ | // main is the default query name | ||
+ | // | ||
itqs := itr.AddItem('queries'); | itqs := itr.AddItem('queries'); | ||
itq := itqs.AddItem('query'); | itq := itqs.AddItem('query'); | ||
itq.AddItems(['QueryName','ClassName'],['main','WfClasseA']); | itq.AddItems(['QueryName','ClassName'],['main','WfClasseA']); | ||
+ | |||
+ | // Filtering | ||
+ | // | ||
+ | itq.AddItemText('Filter','(unBool=%1)'); | ||
+ | itas := itq.AddItem('Args'); | ||
+ | itas.AddItemSerializedVariant('Arg',True); // serializedValue for boolean true | ||
+ | |||
+ | // Output | ||
// | // | ||
itt := itr.addItem('output'); | itt := itr.addItem('output'); | ||
itt.AddItemText('ExportColumns','true'); | itt.AddItemText('ExportColumns','true'); | ||
+ | |||
+ | // Columns | ||
+ | // | ||
itcs := itt.AddItem('columns'); | itcs := itt.AddItem('columns'); | ||
// | // | ||
Ligne 43 : | Ligne 57 : | ||
itc := itcs.AddItem('column'); | itc := itcs.AddItem('column'); | ||
itc.AddItems(['PropName','Title'],['unBool','Boolean']); | itc.AddItems(['PropName','Title'],['unBool','Boolean']); | ||
+ | |||
+ | // Translate value list | ||
+ | // | ||
itvs := itc.AddItem('values'); | itvs := itc.AddItem('values'); | ||
− | + | ||
itv := itvs.AddItem('value'); | itv := itvs.AddItem('value'); | ||
itv.AddAttribute('oldValue','N'); | itv.AddAttribute('oldValue','N'); | ||
Ligne 65 : | Ligne 82 : | ||
itc.AddItems(['PropName','Title'],['unDouble','Double']); | itc.AddItems(['PropName','Title'],['unDouble','Double']); | ||
+ | // Define which exporter to used | ||
+ | // CSV for excel csv format | ||
+ | // | ||
itu := itr.AddItem('exporter'); | itu := itr.AddItem('exporter'); | ||
itu.AddItems(['ClassName'],['TCSVExporter']); | itu.AddItems(['ClassName'],['TCSVExporter']); |
Version du 14 janvier 2020 à 17:07
property Descriptor:TfwxmlDocument;
Cette propriété contient le descriptif d'exportation.
Un descriptif d'exportation à trois sections principales :
queries
Cette section est une collection de requêtes (query)
query
Cette section décrit une requête
output
Cette section décrit la destination de l'export
exporter
Cette section décrit le formatage des données exportées.
Exemple :
Création dynamique de descriptif d'exportation :
//Function CreateDescriptor():TxmlDocument; var itr,itqs,itq,itt,itcs,itc,itu,itvs,itv,itas:TxmlItem; begin Result := TxmlDocument.Create(nil); itr := TxmlItem.Create(Result); itr.ItemName := 'root'; // Add a main query // main is the default query name // itqs := itr.AddItem('queries'); itq := itqs.AddItem('query'); itq.AddItems(['QueryName','ClassName'],['main','WfClasseA']); // Filtering // itq.AddItemText('Filter','(unBool=%1)'); itas := itq.AddItem('Args'); itas.AddItemSerializedVariant('Arg',True); // serializedValue for boolean true // Output // itt := itr.addItem('output'); itt.AddItemText('ExportColumns','true'); // Columns // itcs := itt.AddItem('columns'); // itc := itcs.AddItem('column'); itc.AddItems(['PropName','Title'],['unCode','Code']); // itc := itcs.AddItem('column'); itc.AddItems(['PropName','Title'],['unBool','Boolean']); // Translate value list // itvs := itc.AddItem('values'); itv := itvs.AddItem('value'); itv.AddAttribute('oldValue','N'); itv.AddAttribute('newValue','false'); // itv := itvs.AddItem('value'); itv.AddAttribute('oldValue','O'); itv.AddAttribute('newValue','true'); itc := itcs.AddItem('column'); itc.AddItems(['PropName','Title'],['unCompteur','Compteur']); itc := itcs.AddItem('column'); itc.AddItems(['PropName','Title'],['unEntier','Entier']); itc := itcs.AddItem('column'); itc.AddItems(['PropName','Title'],['unEtat','Enuméré']); itc := itcs.AddItem('column'); itc.AddItems(['PropName','Title'],['unDouble','Double']); // Define which exporter to used // CSV for excel csv format // itu := itr.AddItem('exporter'); itu.AddItems(['ClassName'],['TCSVExporter']); end;
Affectation du descriptif à l'instance :
//Procedure Test; var qbe:TQueryExecuteTask; doc:TxmlDocument; begin qbe := TQueryExecuteTask.Create; doc := CreateDescriptor(); AStr := doc.SaveToString; // Do not create the descriptor directly inside the Descriptor.document // instead, use an intermediate document. // This will recreate the document with the correct internal item classes // qbe.Descriptor.Document.LoadFromString(AStr); ... end;
Voir aussi: