Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defining Fields for a cbMemSet

Status
Not open for further replies.

tjcusick

Programmer
Dec 26, 2006
134
US
I am trying to define fields in a cbMemSet, reading the field names from another table.

Code:
      [b]with[/b] UDFLabels [b]do[/b] [b]begin[/b]
        Open;
        DefineTableStart;
        [b]While[/b] [b]not[/b] dbfTable.Eof [b]do[/b] [b]begin[/b]
          xLbl:=dbfTable.FieldAsString([teal]'LBL_ID'[/teal]);
          xDesc:=dbfTable.FieldAsString([teal]'DESC'[/teal]);
          [b]if[/b] dbfTable[purple]2.[/purple]Seek(xLbl) [b]then[/b]
            xUDFDesc:=dbfTable[purple]2.[/purple]FieldAsString([teal]'DESC'[/teal])
          [b]else[/b]
            xUDFDesc:=xDesc;
          xtmp:=QuotedStr(xUDFDesc);
          xFileName:=dbfTable.FieldAsString([teal]'FILE_NAME'[/teal]);
          DefineField(xtmp, [teal]'C'[/teal], [purple]40[/purple], [purple]0[/purple], True);
          dbfTable.Skip([purple]1[/purple]);
         [b]end[/b]; [navy]//While not dbfTable.Eof do[/navy]
        DefineTableEnd;
        Close;
       [b]end[/b]; [navy]//with UDFLabels

Im not sure why but it is not creating any fields in my cbMemSet. when debugging it it goes though that line each and every time but when looking at my cbMemSet there are no defined fields in there?

Suggestions?

Thanks in advance for the help

Tom C
 
Well i figured out why the fields were not being created it was because there were duplicates. So i made the field unique and now i have all my fields created.

Now my problem is that nothing is being filled into the fields with this code. When i remove the Append and add the GoTop line i get a message that the field "blahblah" not found, even though i can see the field does exist.
Code:
      UDFLabels.EnsureOpen;
      UDFLabels.GoTop;
      [b]for[/b] y:=[purple]1[/purple] [b]to[/b] x-[purple]1[/purple] [b]do[/b] [b]begin[/b]
[navy]//        UDFLabels.Append;[/navy]
        xstr:=ary[y].xLblName;
        ystr:=ary[y].xUDFDesc;
        UDFLabels.ReplaceString(quotedstr(xstr), [teal]'Test'[/teal]);
      [b]end[/b]; [navy]//For[/navy]
Suggestions? Any Help is appreciated.

Thank you very much

Tom C

--------------------------------------------
Code that i get the fields defined.
Code:
  [b]procedure[/b] BuildingTheArray(y:integer);
  [b]begin[/b]
    [b]with[/b] CusRptDM [b]do[/b] [b]begin[/b]
      ary[y].xLbl:=dbfTable.FieldAsString([teal]'LBL_ID'[/teal]);
      ary[y].xDesc:=dbfTable.FieldAsString([teal]'DESC'[/teal]);
      [b]if[/b] dbfTable[purple]2.[/purple]Seek(ary[y].xLbl) [b]then[/b]
        ary[y].xUDFDesc:=dbfTable[purple]2.[/purple]FieldAsString([teal]'DESC'[/teal])
      [b]else[/b]
        ary[y].xUDFDesc:=ary[y].xDesc;
      ary[y].xFileName:=dbfTable.FieldAsString([teal]'FILE_NAME'[/teal]);
      ary[y].xLblName:=ary[y].xType+[teal]'_'[/teal]+ary[y].xDesc+[teal]'_'[/teal]+ary[y].xLbl;
      UDFLabels.DefineField(ary[y].xLblName, [teal]'C'[/teal], [purple]40[/purple], [purple]0[/purple], False)
    [b]end[/b]; [navy]//with[/navy]
  [b]end[/b];

  [b]procedure[/b] LoadUDFLabels;
  [b]var[/b]
    x, y:integer;
    xstr, ystr:String;
  [b]begin[/b]
    [b]with[/b] CusRptDM [b]do[/b] [b]begin[/b]
      x:=[purple]1[/purple];
      [b]with[/b] dbfTable [b]do[/b] [b]begin[/b]
        CBDataBase:= CBDBSysDB;
        FileNameOverride:= CBDBSysDB.DataPath+[teal]'cstable.sdb'[/teal];
        EnsureOpen;
        GoTop;
        [b]While[/b] [b]not[/b] Eof [b]do[/b] [b]begin[/b]
          inc(x);
          skip([purple]1[/purple]);
         [b]end[/b];[navy]//while[/navy]
        GoTop;
       [b]end[/b];  [navy]//with dbfTable[/navy]

      [b]with[/b] dbfTable[purple]2[/purple] [b]do[/b] [b]begin[/b]
        CBDataBase:= CBDBSysDB;
        FileNameOverride:= CBDBSysDB.DataPath+[teal]'csudflbl.sdb'[/teal];
        EnsureOpen;
        SetTag([teal]'FIELD_ID'[/teal]);
        GoTop;
       [b]end[/b];  [navy]//with dbfTable2[/navy]
      y:=[purple]1[/purple];
      SetLength(ary, x+[purple]1[/purple]);
      UDFLabels.DefineTableStart;
      ary[y].xType:=dbfTable.FieldAsString([teal]'TYPE'[/teal]);
      [b]While[/b] [b]not[/b] dbfTable.Eof [b]do[/b] [b]begin[/b]
        BuildingTheArray(y);
        dbfTable.Skip([purple]1[/purple]);
        inc(y);
        ary[y].xType:=dbfTable.FieldAsString([teal]'TYPE'[/teal]);
       [b]end[/b]; [navy]//While not dbfTable.Eof do}[/navy]
      UDFLabels.DefineTableEnd;

      UDFLabels.EnsureOpen;
      UDFLabels.GoTop;
      [b]for[/b] y:=[purple]1[/purple] [b]to[/b] x-[purple]1[/purple] [b]do[/b] [b]begin[/b]
[navy]//        UDFLabels.Append;[/navy]
        xstr:=ary[y].xLblName;
        ystr:=ary[y].xUDFDesc;
        UDFLabels.ReplaceString(quotedstr(xstr), [teal]'Test'[/teal]);
      [b]end[/b]; [navy]//For[/navy]

      dbfTable.Close;
      dbfTable[purple]2.[/purple]Close;
 
Actually something else i just discovered is that the QuotedStr(xstr) is what is causing it to tell me that the "blahblah" not found. If i remove the QuotedStr it runs without errors but still does not populate the fields with the word 'Test'...

Help?
 
FIgured this delima out for anyone interested in know what goof i made...

The mistake was I had the Append and Post inside the FOR loop. Moving them outside the FOR loop created one set of records. Inside the for loop the append made a record for each pass.

Tom C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top