From 96485b6fc6595003c850fa85cfb12d9d4215ab6f Mon Sep 17 00:00:00 2001
From: guy <guy@c028cbd2-c16b-5b4b-a496-9718f37d4682>
Date: Mon, 2 Sep 1996 14:00:46 +0000
Subject: [PATCH] Corrette ricerche e caricamneto funzioni9 utente

git-svn-id: svn://10.65.10.50/trunk@3477 c028cbd2-c16b-5b4b-a496-9718f37d4682
---
 ve/ve4100.cpp | 96 +++++++++++++++++++++++++--------------------------
 1 file changed, 48 insertions(+), 48 deletions(-)

diff --git a/ve/ve4100.cpp b/ve/ve4100.cpp
index 75f6a2c3a..17fefeb5f 100755
--- a/ve/ve4100.cpp
+++ b/ve/ve4100.cpp
@@ -69,19 +69,16 @@ void TTable_expression::load_table(bool force)
       n = expr.get("CODTAB");
       e = expr.get("S1");
       e << expr.get("S2");
-      const TTypeexp t = expr.get_bool("B0") ? _numexpr : _strexpr;
+      const TTypeexp t = expr.get_bool("B0") ? _strexpr : _numexpr;
       
       TTable_expression* te = new TTable_expression;
-      if (te->set(e, t))
-      {
-        THash_object* o = new THash_object(n, te);
-        _expr.add(o);
-      }
-      else
+      THash_object* o = new THash_object(n, te);
+      const int index = _expr.add(o);
+      if (!te->set(e, t))
       {
         te->error_box("La funzione %s contiene un simbolo errato: %s",
                       (const char*)n, te->last_token());
-        delete te;  
+        te->set("", t);  
       }  
     }
   }
@@ -171,17 +168,18 @@ int TTable_expression::name2index(const char* name) const
   if (_expr.items() == 0)
     load_table();
   
+  TString code(name); code.upper();
   for (int index = _expr.items()-1; index >= 0; index--)
   {
     const THash_object& h = (const THash_object&)_expr[index];
-    if (h.key() == name)
+    if (h.key() == code)
       break;
   }            
   
   if (index < 0)
   {
     TTable expr("%FRM");
-    expr.put("CODTAB", name);
+    expr.put("CODTAB", code);
     if (expr.read() == NOERR)
     {
       TString e(127);
@@ -190,7 +188,7 @@ int TTable_expression::name2index(const char* name) const
       TTable_expression* te = new TTable_expression;
       if (te->set(e, t))
       {
-        THash_object* o = new THash_object(name, te);
+        THash_object* o = new THash_object(code, te);
         index = _expr.add(o);
       }
       else
@@ -587,15 +585,15 @@ TCursor& TRicalcolo_mask::create_cursor()
 bool TRicalcolo_mask::file_handler(TMask_field& f, KEY k)
 {
   TRicalcolo_mask& m = (TRicalcolo_mask&)f.mask();
-  if (k == K_SPACE)
+  if (k == K_SPACE && m.is_running())
   {
     const int n = atoi(f.get());
-    if (n != m._cur_file || !m.is_running())
+    if (n != m._cur_file)
     {
       m._cur_file = n;
       const RecDes* rd = m.get_rec_des();
       const int keys = rd->NKeys;
-      
+
       TToken_string codes(16);
       TToken_string values(80);
       TString16 tmp;
@@ -607,10 +605,9 @@ bool TRicalcolo_mask::file_handler(TMask_field& f, KEY k)
         tmp.format("Chiave %d", k);
         values.add(tmp);
       }
+
       TList_field& lk = (TList_field&)m.field(F_KEY);
       lk.replace_items(codes, values);
-      if (atoi(lk.get()) != 0)
-        lk.reset();
     }  
   }
   return TRUE;
@@ -621,41 +618,44 @@ bool TRicalcolo_mask::key_handler(TMask_field& f, KEY k)
   if (k == K_SPACE)
   {                           
     TRicalcolo_mask& m = (TRicalcolo_mask&)f.mask();
-    const int cur_key = atoi(f.get());
-    TToken_string& key_expr = m.get_key_expr(cur_key);
-    const bool empty = key_expr.empty_items();
-    int first_enabled = 0;
-    
     TSheet_field& sheet = (TSheet_field&)m.field(F_FIELDS);
-    TString_array& sa = sheet.rows_array();
-    sa.destroy();                     
-    if (empty)
+    if (m.is_running() || sheet.items() == 0)
     {
-      for (int i = 4; i >= 0; i--)
-        sa.add("");
+      const int cur_key = atoi(f.get());
+      TToken_string& key_expr = m.get_key_expr(cur_key);
+      const bool empty = key_expr.empty_items();
+      int first_enabled = 0;
+    
+      TString_array& sa = sheet.rows_array();
+      sa.destroy();                     
+      if (empty)
+      {
+        for (int i = 4; i >= 0; i--)
+          sa.add("");
+      }  
+      else
+      {  
+        TRelation_description& des = m.get_des();
+        for (TString field = key_expr.get(0); !field.blank(); field = key_expr.get())
+        {
+          const int r = sa.add(field);
+          sa.row(r).add(des.get_field_description(field), F_DESCR-F_FIELD);
+        }  
+        if (des.file_num() == LF_CONDV || des.file_num() == LF_RCONDV)
+        {
+          first_enabled = 4;
+          TToken_string& row = sa.row(0);
+          const TString& lco = m.get(F_TIPO_LCO);
+          row.add(lco, 1);
+          row.add(lco, 2);
+        }  
+      } 
+      
+      for (int r = sa.items()-1; r >= 0; r--)
+        sheet.enable_cell(0, -1, r >= first_enabled);   
+      
+      sheet.force_update();
     }  
-    else
-    {  
-      TRelation_description& des = m.get_des();
-      for (TString field = key_expr.get(0); field.not_empty(); field = key_expr.get())
-      {
-        const int r = sa.add(field);
-        sa.row(r).add(des.get_field_description(field), F_DESCR-F_FIELD);
-      }  
-      if (des.file_num() == LF_CONDV || des.file_num() == LF_RCONDV)
-      {
-        first_enabled = 4;
-        TToken_string& row = sa.row(0);
-        const TString& lco = m.get(F_TIPO_LCO);
-        row.add(lco, 1);
-        row.add(lco, 2);
-      }  
-    } 
-    
-    for (int r = sa.items()-1; r >= 0; r--)
-      sheet.enable_cell(0, -1, r >= first_enabled);   
-    
-    sheet.force_update();
   }
   return TRUE;
 }