Database Application Developer's Guide Supplement
PAGE 3-5
(WAS)
virtual __fastcall TDataModule2(TComponent * Owner);
void LineItemsCalcFields(DataSet *TDataSet); // A function you add
};
(NOW)
virtual __fastcall TDataModule2(TComponent * Owner);
void LineItemsCalcFields(TDataSet* DataSet); // A function you add
};
PAGE 4-5
(WAS)
TSession IBSession
{
IBSession = Sessions->OpenSession("InterBaseSession");
Database->SessionName = "InterBaseSession";
}
(NOW)
TSession* IBSession=new TSession(this);
TDatabase* MyDatabase=new TDatabase(this);
IBSession=Sessions->OpenSession("InterBaseSession");
Database->SessionName="InterBaseSession";
(WAS)
MaxDbCount = Session1->DatabaseCount - 1;
while (Session1->Databases[MaxDbCount]->Name = "InterBase1")
{
(NOW)
MaxDbCount = Session1->DatabaseCount - 1;
while (Session1->Databases[MaxDbCount]->Name == "InterBase1")
{
PAGE 4-11
(WAS)
{
TDatabase MyDatabase[10];
int MyDbCount;
(NOW)
{
TDatabase* MyDatabase[10];
int MyDbCount;
PAGE 4-14
(WAS)
for (int i = 0; i < DataSetCount; i++)
{
if (DataSets[i] == TTable)
DataSets[i]->CachedUpdates = true;
}
(NOW)
TDatabase* MyDatabase=new TDatabase(this);
for(int i=0;iDataSetCount;i++)
{
if( dynamic_cast< TTable* >(MyDatabase->DataSets[i] ) )
MyDatabase->DataSets[i]->CachedUpdates=true;
}
PAGE 4-18
(WAS)
LoginParams->Values["USER NAME"] = UserName;
LoginParams->Values["PASSWORD"] = PasswordSearch(UserName);
(NOW)
Database->Params->Values["USER NAME"]="UserName";
Database->Params->Values["PASSWORD"]= PasswordSearch(UserName);
PAGE 6-16
(WAS)
Some other filter examples are:
CustTable->Filter = "State = California";
CustTable->Filter = "PatientAge >= 18";
(NOW)
CustTable->Filter="[State]='California '";
/* or */
//CustTable->Filter="[PatientAge] >=18";
CustTable->Filtered=true;
CustTable->Refresh();
PAGE 6-20
(WAS)
{
Variant tmp(OPENARRAY(int, (0,1)), vtInteger);
tmp << (int)("Sight Diver");
tmp << (int)("P");
VarArrayOf(&tmp,1);
}
(NOW)
MySearchOptions << loCaseInsensitive;
Variant values[]={"Sight Diver","P"};
LocateSuccess=CustTable->Locate("Company;City", Variant(values,ARRAYSIZE(values)-1),
MySearchOptions);
PAGE 6-21
(WAS)
{
Variant LookupResults;
LookupResults = CustTable->Lookup("Company", "Professional Divers, Ltd.",
"Company; Contact; Phone");
}
(NOW)
Variant LookupResults;
{
LookupResults=CustTable->Lookup("Company", "Professional Divers, Ltd.", "Company;
Contact; Phone");
RichEdit1->Lines->Add(LookupResults.GetElement(0));
RichEdit1->Lines->Add(LookupResults.GetElement(1));
RichEdit1->Lines->Add(LookupResults.GetElement(2));
}
(WAS)
{
Variant tmp(OPENARRAY(int, (0, 1)), vtInteger);
tmp << (int)("Sight Diver", 0);
tmp << ("Christiansted", 1);
Variant LookupResults;
LookupResults = CustTable->Lookup("Company;City", tmp,
"Company;Addr1;Addr2;State;Zip");
}
(NOW)
Variant Values[]={"Sight Diver "," Christiansted "};
Variant LookupResults;
LookupResults=CustTable->Lookup("Company;City ",
Variant(Values,ARRAYSIZE(Values) -1),
"Company;Addr1;Addr2;State;Zip ");
RichEdit1->Lines->Add(LookupResults.GetElement(0));
RichEdit1->Lines->Add(LookupResults.GetElement(1));
RichEdit1->Lines->Add(LookupResults.GetElement(2));
RichEdit1->Lines->Add(LookupResults.GetElement(3));
RichEdit1->Lines->Add(LookupResults.GetElement(4));
PAGE 6-24
(WAS)
TVarRec* Item1=new TVarRec("Japan");
TVarRec* Item2=new TVarRec("Japan");
TVarRec* Item3=new TVarRec("Japan");
CountryTable->InsertRecord((Item1, Item2, Item3),3);
delete Item1;
delete Item2;
delete Item3;
(NOW)
TVarRec Items[]={"Japan","Tokyo","Asia"};
CountryTable->InsertRecord(Items,2);
(WAS)
{
TLocateOptions tlo;
tlo << loCaseInsensitive;
if (CountryTable->Locate("Name", "Japan", tlo))
{
CountryTable->Edit();
TVarRec *tvr1 = new TVarRec(344567);
TvarRec *tvr2 = new TVarRec(164700000);
NULL, tvr1, tvr2), 5);
CountryTable->Post();
delete tvr1;
delete tvr2;
}
}
(NOW)
if(CountryTable->Locate("Name","Japan",MySearchOptions))
{
MySearchOptions << loCaseInsensitive;
CountryTable->Edit();
TVarRec NewValues[]={NULL,NULL,NULL,344567,164700000};
CountryTable->SetFields(NewValues,4);
CountryTable->Post();
}
PAGE 7-5
(WAS)
void __fastcall TForm1::StateChange(TObject *Sender)
{
char S[10];
switch (CustTable->State)
{
case dsInactive: strcpy(S,"Inactive");
case dsBrowse: strcpy(S, "Browse");
case dsEdit: strcpy(S, "Edit");
case dsInsert: strcpy(S, "Insert");
case dsSetKey: strcpy(S, "SetKey");
}
}
(NOW)
void __fastcall TForm1::StateChange(TObject *Sender)
{
char S[10];
switch(CustTable->State)
{
case dsInactive:strcpy(S,"Inactive");break;
case dsBrowse:strcpy(S,"Browse");break;
case dsEdit:strcpy(S,"Edit");break;
case dsInsert:strcpy(S,"Insert");break;
case dsSetKey:strcpy(S,"SetKey"); break;
}
Form1->Caption=S;
}
(WAS)
void __fastcall TForm1::StateChange( TObject *Sender)
{
if (CustTable->State == dsBrowse)
CustTableEditBtn->Enabled;
if (CustTable->State == (dsInsert|dsEdit|dsSetKey))
CustTableCancelBtn->Enabled;
...
}
(NOW)
if (CustTable->State==dsBrowse)
{
CustTableEditBtn->Enabled=true;
}
if ((CustTable->State==dsInsert)||(CustTable->State==dsEdit)||(CustTable->State==dsSetKey))
{
CustTableCancelBtn->Enabled=true;
}
PAGE 8-20
(WAS)
Customers->Edit();
Customers.Fields[6]->AsString=Edit1->Text;
(NOW)
Customers->Edit();
Customers->Fields[6]->AsString=Edit1->Text;
PAGE 9-8
(WAS)
Table1->FindKey(new TVarRec(Edit1->Text),vtPChar);
(NOW)
Table1->FindKey(new TVarRec(Edit1->Text),0);
PAGE 9-12
(WAS)
if (EndVal != "")
Customers->SetRange(OPENARRAY(TVarRec, (StartVal->Text)),OPENARRAY(TVarRec, (EndVal->Text)));
Customers->ApplyRange();
(NOW)
Customers->ApplyRange(); // is not needed
PAGE 9-13
(WAS)
TList* IndexList=new TList();
(NOW)
TStringList* IndexList=new TStringList();
PAGE 11-5
(WAS)
StoredProc1->Params[0]->Items[0]->AsString=Edit1->Text;
(NOW)
StoredProc1->Params[0].Items[0]->AsString=Edit1->Text;
(WAS)
Edit1.Text=StoredProc1->Params[6]->Items[0]->AsString;
(NOW)
Edit1.Text=StoredProc1->Params[6].Items[0]->AsString;
PAGE 13-4
(WAS)
else
{
DBNavigatorAll->DataSource = OrderNum->DataSource;
Set<TNavigateBtn, 0, 3> btnShow;
(NOW)
else
{
DBNavigatorAll->DataSource = OrderNum->DataSource;
Set<TNavigateBtn, 0, 9> btnShow;
PAGE 15-8
(WAS)
while(!Table1->Eof)
{
Table1->RevertRecord();
}
(NOW)
while(!Table1->Eof)
{
Table1->RevertRecord();
Table1->Next();
}
PAGE 15-9
(WAS)
void __fastcall TForm1::CalcFields(TDataSet DataSet)
{
TStringField *Table1ModifiedRow = new TStringField(this);
if (DataSet->UpdateStatus() != usUnmodified)
Table1ModifiedRow->Value = "*";
else
Table1ModifiedRow->Value = NULL;
}
(NOW)
void __fastcall TForm1::CalcFields(TDataSet DataSet)
{
TTable* Table1=new TTable(this);
.
.
.
.
TStringField *Table1ModifiedRow = new TStringField(this);
if (DataSet->UpdateStatus() != usUnmodified)
Table1ModifiedRow->Value = "*";
else
Table1ModifiedRow->Value = NULL;
}
PAGE 15-11
(WAS)
{
if (E->Errors[E->ErrorCount-1] == MyError)
UpdateAction = uaSkip //Key violation, just skip this record
else
UpdateAction = uaAbort //Don’t know what’s wrong, abort the update
(NOW)
{
if (E->Errors[E->ErrorCount-1] == MyError)
UpdateAction = uaSkip; //Key violation, just skip this record
else
UpdateAction = uaAbort; //Don’t know what’s wrong, abort the update
PAGE 15-18
(WAS)
DataSet->UpdateObject)->Apply(UpdateKind);
(NOW)
((TUpdateSQL*)DataSet->UpdateObject)->Apply(UpdateKind);
PAGE 15-19
(WAS)
void __fastcall TForm1::EmpAuditUpdateRecord(TDataSet *DataSet, TUpdateKind UpdateKind, TUpdateAction &UpdateAction)
{
TUpdateSQL *MyUpdateSQL = new TUpdateSQL(this);
TStringField *EmpAuditSalary = new TStringField(this);
TStringField *EmpAuditEmpNo = new TStringField(this);
TVarRec *Field0 = new TVarRec(DataSet->Fields[0]->OldValue);
TVarRec *Field1 = new TVarRec(DataSet->Fields[1]->NewValue);
TLocateOptions MyLocateOptions;
MyLocateOptions << loPartialKey;
if (UpdateKind == ukInsert)
{
UpdateTable->AppendRecord((Field0,Fields1),2);
}
else
if (UpdateTable->Locate("KeyField", DataSet->Fields[0]->OldValue,MyLocateOptions))
{
switch (UpdateKind)
{
case ukModify:
UpdateTable->Edit();
UpdateTable->Fields[1]->Value = DataSet->Fields[1]->Value;
UpdateTable->Post();
}
case ukModify:
UpdateTable->Delete();
}
UpdateAction = uaApplied;
}
(NOW)
void __fastcall TForm1::Table1UpdateRecord(TDataSet *DataSet,
TUpdateKind UpdateKind, TUpdateAction &UpdateAction)
{
TUpdateSQL *MyUpdateSQL = new TUpdateSQL(this);
TStringField *EmpAuditSalary = new TStringField(this);
TStringField *EmpAuditEmpNo = new TStringField(this);
TVarRec *Field0 = new TVarRec(DataSet->Fields[0]->OldValue);
TVarRec *Field1 = new TVarRec(DataSet->Fields[1]->NewValue);
TLocateOptions MyLocateOptions;
MyLocateOptions << loPartialKey;
if (UpdateKind == ukInsert)
{
Table1->AppendRecord((Field0,Field1),2);
}
else
if (Table1->Locate("KeyField", DataSet->Fields[0]->OldValue,MyLocateOptions))
{
switch (UpdateKind)
{
case ukModify:
Table1->Edit();
Table1->Fields[1]->Value = DataSet->Fields[1]->Value;
Table1->Post();
break;
case ukDelete:
Table1->Delete();
break;
}
UpdateAction = uaApplied;
}
}
PAGE 15-20
(WAS)
UpdateSQL1->SQL(ukModify)=ukModify;
(NOW)
UpdateSQL1->SQL[ukModify]=ukModify;