If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > C++ Save Table As?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-04, 09:40
someThinker someThinker is offline
Registered User
 
Join Date: Oct 2004
Posts: 3
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!!!!!";
}
}
Reply With Quote
  #2 (permalink)  
Old 12-09-04, 12:16
someThinker someThinker is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On