[ Dejan tf @ 06.06.2014. 11:34 ] @
Imam jedno pitanje.

Na formi imam dugme i opendialog1..Pomocu dugmeta ucitavam podatke. Zelim da stavim ogranicenje ako ucitam jedanput npr.neku tabelu STAT.dbf, da je nmg.ucitati ponovo, da mi se podaci ne bi duplirali. A uradio sam kada zatvaram formu, brisu mi se tabele..Pri kreiranju forme prave se tabele i upisuju se podaci u njih.

Deo koda za ucitavanje podataka

Code:

if(Open->Execute())
{

Edit1->Text = Open->FileName;
int i = Edit1->Text.LastDelimiter("\\");
int a = Edit1->Text.Length();
int b = a-i;
String s = Edit1->Text.SubString(i+1,b);
Edit2->Text = s;
Edit1->Text = Edit1->Text.SubString(1,i);
String p = Edit1->Text;




ADOConnection1->Close();
String str = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source="+p+";Mode=Share Deny None;Jet OLEDB:Engine Type=17;";


ADOConnection1->ConnectionString = str;
tabSTAT1->Connection = ADOConnection1;
tabSTAT1->TableName = s;
int x = s.LastDelimiter(".");
int y = s.Length();
int k = y-x;
String h = s.Delete(x,k+1);
ADOQuery1->SQL->Text = "INSERT INTO tabSTAT1 SELECT GRAD , PARTNER,DATUM,NAZIV_ART,KOLICINA,NETO FROM "+h+"";


.


Brisanje podataka pri zatvaranju forme


Code:


if(FileExists("tabSTAT.dbf"))
{
ADOConnection1->Close();
String s = ExtractFilePath(Application->ExeName);
String str= "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source="+s+";Mode=Share Deny None;Jet OLEDB:Engine Type=17;Properties=dBase IV;";
ADOConnection1->ConnectionString = str;
tabSTAT->Connection = ADOConnection1;
cmd->CommandText = "DROP TABLE tabSTAT";
cmd->Execute();

  }
[ X Files @ 06.06.2014. 18:49 ] @
Pokušaj nešto ovako...
(TOpsenDialog sam kreirao dinamički, ti ne moraš, stavi samo kontrolu na formu... i ne treba ti "new", "delete", ...)

// NETESTIRANO !!!
--- H ---
Code:

// ...
public:        // User declarations
// ...
        __fastcall ~TForm1();
        TStringList *SL;
// ...


--- CPP ---
Code:

__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   SL = new TStringList;
   if ( SL )
      SL->Clear();
}
__fastcall TForm1::~TForm1()
{
   if ( SL )
      delete SL;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   TOpenDialog *Od = new TOpenDialog ( Application );
   if ( Od )
   {
      Od->Filter = "dBASE datoteke (*.dbf)|*.DBF|Sve datoteke (*.*)|*.*";
      Od->InitialDir = ExtractFilePath( ParamStr(0) );
      Od->Title = "Otvori bazu...";
      if ( Od->Execute() )
      {
         if ( FileExists( Od->FileName ) )
         {
            if ( SL->IndexOf(Od->FileName) == -1 )
            {
               SL->Add(Od->FileName);
               ShowMessage("Uradi nešto sa datotekom: " + Od->FileName);
            }
            else
            {
               ShowMessage("Datoteka: '" + Od->FileName + "' je vec ucitana!");
            }

         }
         else
         {
            ShowMessage("Datoteka: '" + Od->FileName + "' ne postoji!");
         }
       }
      delete Od;
   }
}