Hi Im really stuck on one problem. I trying to save some data to a file.
im using Borland compiler.
the challenege is to create a new product and save its details to a text file.
1. the user inputs product details i.e. Barcode, Name, Price, and quantity via the interface
2. the user clicks on save button, and it creates a file to which the information is saved
heres what ive got so far:
Product.h file
class Product
{
private:
AnsiString BarCodeField[];
AnsiString ProductNameField[];
double PriceExVAT;
double PriceIncVAT;
int CurrentSupplyField;
int MinimumSupplyField;
public:
void CreateNewProduct(AnsiString theBarCodeField[],
AnsiString theProductNameField[],
double thePriceExVAT,
double thePriceIncVAT,
int theCurrentSupplyField,
int theMinimumSupplyField);
AnsiString getBarCode();
AnsiString getProductName();
double getExVAT();
double getIncVAT();
int getCurrentSupply();
int getMinimumSupply();
Product();
~Product();
};
Product.cpp file
Product::Product()
{
}
Product::~Product()
{
}
void Product::CreateNewProduct(AnsiString theBarCodeField[],
AnsiString theProductNameField[],
double thePriceExVAT,
double thePriceIncVAT,
int theCurrentSupplyField,
int theMinimumSupplyField)
{
BarCodeField[] = theBarCodeField[];
ProductNameField[] = theProductNameField[];
PriceExVAT = thePriceExVAT;
PriceIncVAT = thePriceIncVAT;
CurrentSupplyField = theCurrentSupplyField;
}
//---------------------------------------------------------------------------
AnsiString Product::getBarCode()
{
return BarCodeField[];
}
//---------------------------------------------------------------------------
AnsiString Product::getProductName()
{
return ProductNameField[];
}
//---------------------------------------------------------------------------
double Product::getExVAT()
{
return PriceExVAT;
}
//---------------------------------------------------------------------------
double Product::getIncVAT()
{
return PriceIncVAT;
}
//---------------------------------------------------------------------------
int Product::getCurrentSupply()
{
return CurrentSupplyField;
}
//---------------------------------------------------------------------------
int Product::getMinimumSupply()
{
return MinimumSupplyField;
}
//---------------------------------------------------------------------------
AddProductForm.cpp file
void __fastcall TForm2::AddToStockClick(TObject *Sender)
{
FILE * FSave;
theProduct.CreateNewProduct(//???????? HELP PLEASE!!!!!!! WHAT PARAMETERS GO HERE???
//BarcodeBox,
//ProductName,
//ExVAT,
//IncVAT
//CurrentSupply->Text,
//MinimumSupply->Text
); ???
{
strcpy(theProduct.getBarCode, BarcodeBox->Text.c_str());
//i want to copy the data from a TEdit box into the getBarCode variable and save it to file
}
if(SaveDialog1->Execute())
{
FSave = fopen(SaveDialog1->FileName.c_str(),"w");
ProdConfirm->Visible = true;
if(FSave == NULL)
{
MessageBox(NULL,"The file could not be saved","Error", MB_OK);
return;
}
fprintf(FSave, "%s\t", BarCodeField);
fprintf(FSave, "%s\t", ProductNameField);
fprintf(FSave, "%.2f\t", PriceExVAT);
fprintf(FSave, "%.2f\t", PriceIncVAT);
fprintf(FSave, "%s\t", CurrentSupplyField);
fprintf(FSave, "%s\t", MinimumSupplyField);
}
fclose(FSave);