Article View: borland.public.cppbuilder.database.ado
Article #4699TDatabase & Tquery problem
From: Stephane Baillargeon
Date: Thu, 15 Nov 2001 22:06
Date: Thu, 15 Nov 2001 22:06
226 lines
7982 bytes
7982 bytes
I'm trying to create a function that accepts two integers, one for language
and the other is the components tag value. I create two variables called
dbDatabase and qryQuery of type TDatabase and TQuery respectively. The
Database is for login prompt use only and the Query is for the SQL
statements to execute. Now here's the problem: when I build the code for
the DLL, The linker returns me several errors. I have included the file
MEMMGR.LIB because I return AnsiStrings from my functions and the ODBCs are
correctly set so it's not those things that make it not work. Maybe I
forgot to #include<> a header file... Here are the errors:
Note : The source code follows the error messages.
1. [Linker Error] Unresolved external '__fastcall
Dbtables::TDatabase::SetDatabaseName(const System::AnsiString)' referenced
from C:\MES DOCUMENTS\C++ BUILDER 5 PROJECTS\GESTICO\CAPTIONS.OBJ
2. [Linker Error] Unresolved external '__fastcall
Dbtables::TDBDataSet::SetDatabaseName(const System::AnsiString)' referenced
from C:\MES DOCUMENTS\C++ BUILDER 5 PROJECTS\GESTICO\CAPTIONS.OBJ
3. [Linker Error] Unresolved external '__fastcall Db::TParams::GetItem(int)'
referenced from C:\MES DOCUMENTS\C++ BUILDER 5 PROJECTS\GESTICO\CAPTIONS.OBJ
4. [Linker Error] Unresolved external '__fastcall
Db::TParam::SetAsInteger(int)' referenced from C:\MES DOCUMENTS\C++ BUILDER
5 PROJECTS\GESTICO\CAPTIONS.OBJ
5. [Linker Error] Unresolved external '__fastcall
Dbtables::TQuery::Prepare()' referenced from C:\MES DOCUMENTS\C++ BUILDER 5
PROJECTS\GESTICO\CAPTIONS.OBJ
6. [Linker Error] Unresolved external '__fastcall Db::TDataSet::Open()'
referenced from C:\MES DOCUMENTS\C++ BUILDER 5 PROJECTS\GESTICO\CAPTIONS.OBJ
7. [Linker Error] Unresolved external '__fastcall
Db::TDataSet::FieldByName(const System::AnsiString)' referenced from C:\MES
DOCUMENTS\C++ BUILDER 5 PROJECTS\GESTICO\CAPTIONS.OBJ
8. [Linker Error] Unresolved external '__fastcall Db::TDataSet::Close()'
referenced from C:\MES DOCUMENTS\C++ BUILDER 5 PROJECTS\GESTICO\CAPTIONS.OBJ
----------------
Here's the code
----------------
//--------------------------------------------------------------------------
-
#include <vcl.h>
#include <windows.h>
// Form header files
#include "Main.h"
// Other header files
#include "Constants.h"
#pragma hdrstop
void BindCaptionComponent(int intLang, int intType, TComponent *Component2);
AnsiString GetCaptionWithTag(int intLang, int intTag);
//--------------------------------------------------------------------------
-
// Borland's message about dlls
// .........................
//--------------------------------------------------------------------------
-
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*
lpReserved)
{
return 1;
}
//--------------------------------------------------------------------------
-
// Binds captions on chosen form in chosen language.
int __declspec(dllexport) BindCaptionsForm(int intLang, TForm *frmForm)
{
int intComponentCount, intComponentCur;
TComponent *Component;
intComponentCount = frmForm->ControlCount - 1;
// As long as there are components on the form, bind them if possible.
for(intComponentCur = 0; intComponentCur <= intComponentCount;
intComponentCur++)
{
Component = frmForm->Components[intComponentCur];
if(Component->ClassNameIs("TLabel"))
BindCaptionComponent(intLang, mintLABEL, Component);
else if(Component->ClassNameIs("TButton"))
BindCaptionComponent(intLang, mintBUTTON, Component);
else if(Component->ClassNameIs("TActionList"))
BindCaptionComponent(intLang, mintACTIONLIST, Component);
}
return 1;
}
//--------------------------------------------------------------------------
-
void BindCaptionComponent(int intLang, int intType, TComponent *Component2)
{
int intTag = 0;
switch(intType)
{
case mintLABEL:
{
// Cast the component to a TLabel and get tag value
TLabel *Label = dynamic_cast<TLabel*>(Component2);
intTag = Label->Tag;
Label->Caption = GetCaptionWithTag(intLang, intTag);
break;
}
case mintBUTTON:
break;
case mintACTIONLIST:
{
// Cast the component to a TActionList
TActionList *ActionList =
dynamic_cast<TActionList*>(Component2);
TAction *Action;
// Get number of actions in list
int intActCount;
int intActCur;
intActCount = ActionList->ActionCount;
// Loop through actions in list and set their captions
for(intActCur = 0; intActCur < intActCount; intActCur++)
{
// Cast TContainedAction to TAction
Action =
dynamic_cast<TAction*>(ActionList->Actions[intActCur]);
// If cast is successful
if(Action)
{
intTag = Action->Tag;
Action->Caption = GetCaptionWithTag(intLang, intTag);
}
}
break;
}
case mintFORM:
{
// Cast the component to a TLabel and get tag value
TForm *Form = dynamic_cast<TForm*>(Component2);
intTag = Form->Tag;
Form->Caption = GetCaptionWithTag(intLang, intTag);
break;
}
default:;
}
}
//--------------------------------------------------------------------------
-
AnsiString GetCaptionWithTag(int intLang, int intTag)
{
AnsiString strCaption = "";
TQuery *qryQuery;
TDatabase *dbDatabase;
// Set dbParams
dbDatabase->DatabaseName = "Gestico";
dbDatabase->LoginPrompt = false;
// Set qryParams
qryQuery->DatabaseName = "Gestico";
// Make sure that query is closed before opening it again
qryQuery->Close();
// Set SQL select
qryQuery->SQL->Clear();
// Select field depending on language
switch(intLang)
{
case mintENGLISH:
{
qryQuery->SQL->Add("SELECT Cap_String_Eng AS Caption");
break;
}
case mintFRENCH:
{
qryQuery->SQL->Add("SELECT Cap_String_Fre AS Caption");
break;
}
default:;
}
qryQuery->SQL->Add("FROM Captions");
qryQuery->SQL->Add("WHERE Cap_Tag = :Tag");
qryQuery->Params->Items[0]->AsInteger = intTag;
// Prepare and open query
if(!qryQuery->Prepared)
{
qryQuery->UniDirectional = true;
qryQuery->Prepare();
}
// Open query
qryQuery->Open();
// Get caption and bind to component
if(!qryQuery->Eof)
strCaption = qryQuery->FieldByName("Caption")->AsString;
else
strCaption = "zError";
// Close query
qryQuery->Close();
return strCaption;
}
//--------------------------------------------------------------------------
-
Technical Details
Message-ID:
<3bf43d0c$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,502484d298880c62,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2001-11-15 14:16:48 PST From: "Stephane Baillargeon" <mbaillargeon@sympatico.ca> Newsgroups: borland.public.cppbuilder.database.ado Subject: TDatabase & Tquery problem Date: Thu, 15 Nov 2001 17:06:05 -0500 Lines: 232 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-Mimeole: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 65.94.174.215 Message-ID: <3bf43d0c$1_1@dnews> X-Trace: dnews 1005862156 65.94.174.215 (15 Nov 2001 14:09:16 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews