Calling functions in c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JT JTM
    New Member
    • Feb 2012
    • 1

    Calling functions in c++

    Hi,
    i have a defined function, but when i run my program jumps the function without reading it. Here is how my code look like:
    Code:
            void processComboItem(); declaring the function
     void TPosGetPaymentMethodForm::processComboItem()//details of the function
    {
            int key = PosMainForm->PosTrnObj->PayKey;
    
            long double         FITotal = PosMainForm->PosTrnObj->FinalInvoiceTotal;
            long double         FIDue = PosMainForm->PosTrnObj->FinalInvoiceDue ;
            long double         FIVat = PosMainForm->PosTrnObj->FinalInvoiceVat;
            long double         FIDiscount = PosMainForm->PosTrnObj->FinalInvoiceDiscount ;
            double total = 0;
    
            AnsiString StockCode = "";
            AnsiString Slipnumber = PosMainForm->PosTrnObj->SlipNumber;
            double value = 0;
            PosDataForm->SelectQuery->Close();
            PosDataForm->SelectQuery->CommandText = "SELECT StockCode,Value,Quantity FROM POS_Transactions WHERE Slip = '" + AnsiReplaceStr( Slipnumber, "'", "`" ) + "' and Type = '02'";
            PosDataForm->SelectQuery->Open();
            if (PosDataForm->SelectQuery->RecordCount > 0)
            {
                  StockCode = AnsiString(PosDataForm->SelectQuery->FieldValues["StockCode"]);
                  value = double(PosDataForm->SelectQuery->FieldValues["Value"]);
                  PosDataForm->SelectQuery->Close();
                  PosDataForm->SelectQuery->CommandText = "SELECT IngredientID, Quantity FROM RECIPES WHERE KitchenItemID = '" + AnsiReplaceStr( StockCode.Trim(), "'", "`" ) + "'";
                  PosDataForm->SelectQuery->Open();
    
                  if (PosDataForm->SelectQuery->RecordCount > 0)
                  {
    
                    while(!PosDataForm->SelectQuery->Eof)
                    {
                        PosMainForm->PosTrnObj->Search(AnsiString(PosDataForm->SelectQuery->FieldValues["IngredientID"]),"POSTerminal" );
                        PosDataForm->SelectQueryCents->Close();
                        PosDataForm->SelectQueryCents->CommandText = "SELECT Value FROM POS_Transactions WHERE Slip = '" + AnsiReplaceStr( Slipnumber, "'", "`" ) + "' and StockCode = '"+AnsiString(PosDataForm->SelectQuery->FieldValues["IngredientID"])+"'";
                        PosDataForm->SelectQueryCents->Open();
    
                        if (PosDataForm->SelectQueryCents->RecordCount > 0)
                        {
                              total += double(PosDataForm->SelectQueryCents->FieldValues["Value"]);
                        }
    
                        PosDataForm->SelectQuery->Next();
                    }
                  }
    
                  total = value - total;
                  PosDataForm->UpdateCommand->CommandText = "UPDATE POS_Transactions SET Value = "+AnsiString(total)+", Total = "+AnsiString(total)+" WHERE  Slip = '" + AnsiReplaceStr( Slipnumber, "'", "`" ) + "' and StockCode = '"+ StockCode +"'";
                  PosDataForm->UpdateCommand->Execute();
            }
            //restore values
            PosMainForm->PosTrnObj->FinalInvoiceTotal = FITotal;
            PosMainForm->PosTrnObj->FinalInvoiceDue = FIDue;
            PosMainForm->PosTrnObj->FinalInvoiceVat=FIVat;
            PosMainForm->PosTrnObj->FinalInvoiceDiscount=FIDiscount;
            PosMainForm->PosTrnObj->PayKey = key;
    
    } 
    
    //calling the function
    void __fastcall TPosGetPaymentMethodForm::Button19Click(TObject *Sender)
    {
            processComboItem();
            PosPaymentReceivedKeyPress(this, 'n');
    }
    when i run my application it doesn't go through the calling it skips that part.
    can anyone help?
    Last edited by Rabbit; Feb 20 '12, 11:37 PM. Reason: Please use code tags when posting code.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Have you walked this code through your debugger?

    Are you even calling this function:
    Code:
    void __fastcall TPosGetPaymentMethodForm::Button19Click(TObject *Sender)
     {
    ?
    BTW: TPosGetPaymentM ethodForm::Butt on19Click does not use its argument.

    Comment

    Working...