Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    3

    Unanswered: C++ Save Table As?

    I'm quite new to C++ builder .Does anyone know how to save table database file under different name? Same function has Save As... to keep old file but to create new file??
    Im using code below, unfurtunatelly doesnt do anything? Any suggestions?

    Thanx

    if (SaveDialog2->Execute())
    {
    try {

    AnsiString NewFileName = ExtractFilePath(SaveDialog2->FileName) + ExtractFileName(SaveDialog2->FileName);
    AnsiString Msg = Format("Copy %s to %s", ARRAYOFCONST((Table1->TableName,NewFileName)));
    if (MessageDlg(Msg, mtConfirmation, mbOKCancel, 0) == mbOK)
    {
    TFileStream *OldFile = new TFileStream(Table1->TableName, fmOpenRead);
    try
    {
    TFileStream *NewFile = new TFileStream(NewFileName, fmCreate);
    try
    {

    NewFile->CopyFrom(OldFile, OldFile->Size);
    }
    __finally
    {
    FreeAndNil(NewFile);
    }
    }
    __finally
    {
    FreeAndNil(OldFile);
    }
    }

    } //try
    catch (const EConvertError &e)
    {
    StatusBar2->SimpleText = "File is not recognisable!!!!!";
    }
    }

  2. #2
    Join Date
    Oct 2004
    Posts
    3

    Talking thanx kaz

    thanx kaz for help
    this new code does work,

    void __fastcall TFilter::Button3Click(TObject *Sender)
    {
    AnsiString NewFileName;

    if (SaveDialog2->Execute())
    {
    NewFileName = ExtractFilePath(SaveDialog2->FileName) + ExtractFileName(SaveDialog2->FileName);
    }


    AnsiString OldFileName = ExtractFilePath(Table1->DatabaseName) + ExtractFileName(Table1->TableName);
    Table1->Close();
    Table1->Active = false;
    TFileStream *OldFile = new TFileStream(OldFileName, fmOpenRead);
    TFileStream *NewFile = new TFileStream(NewFileName, fmCreate);
    NewFile->CopyFrom(OldFile, OldFile->Size);
    NewFile->Free();
    OldFile->Free();

    Table1->Close();
    Table1->DatabaseName = ExtractFilePath(NewFileName);
    Table1->TableName = ExtractFileName(NewFileName);
    Table1->Active = true;
    Table1->Open();



    } //end save as butn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •