BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TQuery problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop)
View previous topic :: View next topic  
Author Message
Lars Martin
Guest





PostPosted: Tue Aug 26, 2003 9:07 am    Post subject: TQuery problem Reply with quote



Hi !

I have a problem with the TQuery Object. I create in a DLL (DBModul) a
TDatabase and a TQuery Object, then I use the TQuery Object in an other DLL
(Test). Everything seems to be OK until I close the Query (MyQuery->Close())
and try to change the SQL String of the TQuery Object. Bang! Access
Violation. Has anyone a clue what the problem is?

Program is written in C++, CBuilder 5, dynamic RTL is used (so I think it is
not the string / memmgr.lib problem)

Test.dll:

DB = new DBModul("dmc60","1","","");
TQuery* Q = DB->Abfrage();
Q->SQL->Clear();
Q->SQL->Add("SELECT * FROM fertvorgang");
Q->Open(); // Abfrage ausführen

int AnzahlVorgaenge = Q->RecordCount; // Anzahl der Vorgänge im Arbeitsplan
for (int index = 1; index <= AnzahlVorgaenge; index++ ) { // Durchlaufen
aller Datensätze

auftragsnr = Q->Fields->FieldByName("auftragsnr")->AsInteger;
vorgangsnr = Q->Fields->FieldByName("vorgangspos")->AsInteger;
[...] snip
bstnr = Q->Fields->FieldByName("arbeitsplatznr")->AsInteger;
vorgangszeit = double(Q->Fields->FieldByName("te")->AsFloat) +
double(Q->Fields->FieldByName("ta")->AsFloat);
[...] snip
Q->Next();
}

Q->Close();

Q->SQL->Clear();
sprintf(msg, "SELECT * FROM auftragssta WHERE auftragsnr =
%u",vorauftragsnr);
cout << "msg: " << msg<< endl;
Q->SQL->Add(msg); <------ ACCESS VIOLATION
Q->Open();



And the DBModul DLL:

DBModul::DBModul(char* alias,char* SessionName, char* login, char* passwd) {
Sessions->OpenSession(AnsiString(SessionName));
TSession *pSession = Sessions->FindSession(AnsiString(SessionName));
TDatabase* TempDB = pSession->FindDatabase(AnsiString(alias));
// Prüfen ob bereits eine Session besteht
if (TempDB) {
cout << "Datenbankverbindung noch offen " < MyDB = TempDB;
}
MyDB = new TDatabase(NULL);
try {
cout << "Datenbank neu erzeugt " < MyDB->LoginPrompt = false;
MyDB->DatabaseName= alias;
MyDB->SessionName = AnsiString(SessionName);
MyDB->Params->Add(AnsiString("USERNAME=")+AnsiString(login));
MyDB->Params->Add(AnsiString("PASSWORD=")+AnsiString(passwd));
MyDB->KeepConnection = true;
MyDB->Open()
}
catch (EDatabaseError &e) {
cout << "Fehler: " << e.Message<
}
}

TQuery* DBModul::Abfrage() {
MyQuery = new TQuery(NULL);
MyQuery->DatabaseName = MyDB->DatabaseName;
MyQuery->SessionName = MyDB->SessionName;
return MyQuery;
}




Here a little more detailed description in german ;-)

Ich versuche mich gerade in die Datebankprogrammierung unter BDE
einzuarbeiten und habe ein Problem was ich nicht mehr verstehe.

Ich erzeuge in einer DLL (DBModul) ein neues TDatabase Object und ein
TQuery Object, diese rufe ich von einer anderen DLL (Test) aus auf. Ich
weiss hört sich chaotisch an muss aber sein, da es sich hierbei um ein
grosses Projekt handelt an das ich "nur" eine Datenbankanbindung
anprogrammieren muss Wink.

Die ersten Aufrufe von Funktion von TQuery funktionieren noch ohne Probleme
(Z.B. SQL->Add, Open, etc), nach dem Aufruf von Close() und dem erneuten
Aufruf von SQL-Add stürtzt das Programm mit einer Access Violation ab.
Eigentlich muss das ganze doch funktionieren, soweit ich TQuery->Close()
verstanden habe wird doch nur die Abfrage geschlossen und das Objekt
existiert noch oder verstehe ich da was falsch.








Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.