« Vue locale (langage) » : différence entre les versions

De Wiki1000
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 54 : Ligne 54 :
</pre>
</pre>


Les vues peuvent utiles pour effectuer des traitement sur des classes complexes, par exemple il est possible d'utiliser un curseur sur une classe vue  :
Les vues peuvent utiles pour effectuer des traitement sur des classes complexes, par exemples :
 
'''Curseur sur une classe vue  :'''


<source lang="delphi">
<source lang="delphi">
Ligne 75 : Ligne 77 :
end;
end;
</source>
</source>
'''Vue sur des combinaisons uniques d'attributs :'''
<source lang="delphi">
function foo(const S:string):Integer;
Type
  MyView = viewof(ClassA distinct)
    unCode:string = unCodeA primary;
    unEntier:Integer = refB.unEntierB;
  end;
var inst:MyView; cursor:MyViewCursor
begin
  cursor := MyView.CreateCursorWhere(''unCode=%1'','''',true,[S]);
  foreach inst in cursor do
  begin
    ...
  end;
end;
</source>
'''Vue avec agrégats :'''
<source lang="delphi">
function foo(const S:string):Integer;
Type
  MyView = viewof(ClassA)
    unCode:string = unCodeA primary;
    unEntier:Integer = sum(unEntier);
  end;
var inst:MyView; cursor:MyViewCursor
begin
  cursor := MyView.CreateCursorWhere(''unCode=%1'','''',true,[S]);
  foreach inst in cursor do
  begin
    ...
  end;
end;
</source>


Voir aussi :
Voir aussi :

Version du 19 septembre 2011 à 10:03

{{#images:versionTahoe-32x32.png|stock}}

Les vues locales sont des type de données vues déclarées localement à l'intérieur d'une opération.

Par exemple le code suivant déclare une vue MyView et effectue une recherche sur cette vue :

<source lang="delphi"> function foo(const S:string):Integer; Type

 MyView = viewof(ClassA)
 unCode:string = unCodeA;
 unEntier:Integer = refB.unEntierB;
 end;

var inst:MyView; begin

 inst := MyView.Find('unCode=%1',,true,['B1']);
 if Assigned(inst) then
  begin
    ...
  end;

end </source>

Le périmètre du type est limité à la procédure, il n'est donc pas possible de passer les objets de la vue en paramètre à d'autres fonctions (pour cela utilisez une vue globale).

La syntaxe pour définir une vue locale :

  BNF style grammar : 

  <nom_vue> ::= ViewOf(<class_dec>) [<attribute_def>] end 
  <class_dec> ::= <class_name> | <class_name> <class_dec>
  <class_name> ::= identifier
  <class_dec> ::= distinct
  <attribute_def> ::= <simple_attribute_def> | <simple_attribute_def> <attribute_directive> 
  <simple_attribute_def> ::= <attribute_dec> | <attribute_dec> = <attribute_ref>
  <attribute_dec> ::= <attribute_name> : <type_name>
  <attribute_ref> ::= <main_class_attribute_name> | <operator>(<main_class_attribute_name>)
  <operator> ::= <aggregate_operator> | <date_operator>
  <aggregate_operator> ::= count|sum|max|min
  <date_operator> ::= year|month|quarter|week|day|dayofyear|dayofweek|hour|minute|second
  <attribute_directive> ::=  primary | orderby | orderby desc 

  Type
    NomDeVue = ViewOf(NomDeClassePrincipale)
      Attribut : Type;
      Attribut : Type = AliasDe;
      Attribut : Type = operator(AliasDe);
      Attribut : Type = AliasDe primary;
      Attribut : Type = AliasDe orderby;
      Attribut : Type = AliasDe orderby desc;
    end;

Les vues peuvent utiles pour effectuer des traitement sur des classes complexes, par exemples :

Curseur sur une classe vue  :

<source lang="delphi"> function foo(const S:string):Integer; Type

 MyView = viewof(ClassA)
   newCode:string;
   unCode:string = unCodeA;
   unEntier:Integer = refB.unEntierB;
 end;

var inst:MyView; cursor:MyViewCursor begin

 Result := 0;
 cursor := MyView.CreateCursorWhere(unCode=%1,',true,[S]);
 foreach inst in cursor do
  begin
    Result := Result + inst.unEntier;
  end;

end; </source>

Vue sur des combinaisons uniques d'attributs :

<source lang="delphi"> function foo(const S:string):Integer; Type

 MyView = viewof(ClassA distinct)
   unCode:string = unCodeA primary;
   unEntier:Integer = refB.unEntierB;
 end;

var inst:MyView; cursor:MyViewCursor begin

 cursor := MyView.CreateCursorWhere(unCode=%1,',true,[S]);
 foreach inst in cursor do
  begin
    ...
  end;

end; </source>

Vue avec agrégats :

<source lang="delphi"> function foo(const S:string):Integer; Type

 MyView = viewof(ClassA)
   unCode:string = unCodeA primary;
   unEntier:Integer = sum(unEntier);
 end;

var inst:MyView; cursor:MyViewCursor begin

 cursor := MyView.CreateCursorWhere(unCode=%1,',true,[S]);
 foreach inst in cursor do
  begin
    ...
  end;

end; </source>


Voir aussi :