Subject | Interbase and Arrays |
---|---|
Author | Chris at Visible Changes |
Post date | 2000-11-21T19:45:56Z |
Hello Geno,
Looks like you got the old array "gotcha". Not to worry
it got me too!. Basically what you need to do is create a VARIANT
structure to move to and from your Interbase Table. I am unsure whether
you are a Delphi or C++ Builder user though. If you use Delphi look at the
sample provided by Jason that is installed under the default directory
\IBOBJECTS\Samples\Arrays\FRM_Arrays.pas. If you are a C++ Builder user
then you can have some of my sample code below:
// Save Commission Record
void __fastcall TForm_StraightCommission::SaveCommissionRecord()
{
// Move from Variant Arrays to Database
DBSysSetup->Query_StraightCommission->FieldValues["Commission_Percentage"] = Commission_Percentage;
DBSysSetup->Query_StraightCommission->FieldValues["Chargeback_Percentage"] = Chargeback_Percentage;
DBSysSetup->Query_StraightCommission->FieldValues["Chargeback_Dollar" ] = Chargeback_Dollar;
DBSysSetup->Query_StraightCommission->Post();
void __fastcall TForm_StraightCommission::SaveCommissionRecord()
{
// Move from Variant Arrays to Database
DBSysSetup->Query_StraightCommission->FieldValues["Commission_Percentage"] = Commission_Percentage;
DBSysSetup->Query_StraightCommission->FieldValues["Chargeback_Percentage"] = Chargeback_Percentage;
DBSysSetup->Query_StraightCommission->FieldValues["Chargeback_Dollar" ] = Chargeback_Dollar;
DBSysSetup->Query_StraightCommission->Post();
}
// First Time Screen is Loaded
void __fastcall TForm_StraightCommission::FirstTime()
{
AnsiString String_Value;
int loop;
int Bounds[2] = {1,100};
Variant Value;
void __fastcall TForm_StraightCommission::FirstTime()
{
AnsiString String_Value;
int loop;
int Bounds[2] = {1,100};
Variant Value;
//
// Declare Variant Arrays GLOBAL
// Commission_Percentage,Chargeback_Percentage,
Chargeback_Dollar previously defined as VARIANT
//
Commission_Percentage = VarArrayCreate(Bounds,1,varInteger);
Chargeback_Percentage = VarArrayCreate(Bounds,1,varInteger);
Chargeback_Dollar = VarArrayCreate(Bounds,1,varInteger);
DBSysSetup->Query_StraightCommission->Open();
// Execute SQL
statement
DBSysSetup->Query_StraightCommission->First();
DBSysSetup->Query_StraightCommission->First();
if
(!DBSysSetup->Query_StraightCommission->Eof)
{
// Load Variant Arrays from Database
Commission_Percentage = DBSysSetup->Query_StraightCommission->FieldValues["Commission_Percentage"];
Chargeback_Percentage = DBSysSetup->Query_StraightCommission->FieldValues["Chargeback_Percentage"];
Chargeback_Dollar = DBSysSetup->Query_StraightCommission->FieldValues["Chargeback_Dollar"];
{
// Load Variant Arrays from Database
Commission_Percentage = DBSysSetup->Query_StraightCommission->FieldValues["Commission_Percentage"];
Chargeback_Percentage = DBSysSetup->Query_StraightCommission->FieldValues["Chargeback_Percentage"];
Chargeback_Dollar = DBSysSetup->Query_StraightCommission->FieldValues["Chargeback_Dollar"];
// Load Grid from Variant
Arrays
for (loop = 0;loop < Button_Grid->RowCount;loop++)
{
Value = Commission_Percentage.GetElement(loop+1);
String_Value = SPStrings->IntToPercent(Value.VInteger,2);
Button_Grid->Cells [1][loop] = String_Value;
Button_Grid->Objects[1][loop] = (TObject*)Value.VInteger;
for (loop = 0;loop < Button_Grid->RowCount;loop++)
{
Value = Commission_Percentage.GetElement(loop+1);
String_Value = SPStrings->IntToPercent(Value.VInteger,2);
Button_Grid->Cells [1][loop] = String_Value;
Button_Grid->Objects[1][loop] = (TObject*)Value.VInteger;
Value =
Chargeback_Percentage.GetElement(loop+1);
String_Value = SPStrings->IntToPercent(Value.VInteger,2);
Button_Grid->Cells [2][loop] = String_Value;
Button_Grid->Objects[2][loop] = (TObject*)Value.VInteger;
String_Value = SPStrings->IntToPercent(Value.VInteger,2);
Button_Grid->Cells [2][loop] = String_Value;
Button_Grid->Objects[2][loop] = (TObject*)Value.VInteger;
Value =
Chargeback_Dollar.GetElement(loop+1);
String_Value = SPStrings->IntToMoney(Value.VInteger,2);
Button_Grid->Cells [3][loop] = String_Value;
Button_Grid->Objects[3][loop] = (TObject*)Value.VInteger;
}
}
String_Value = SPStrings->IntToMoney(Value.VInteger,2);
Button_Grid->Cells [3][loop] = String_Value;
Button_Grid->Objects[3][loop] = (TObject*)Value.VInteger;
}
}
Button_Grid->Row = 0;
Button_Grid->Col = 0;
Button_Grid->Col = 0;
}
This sample above loads a Interbase defined Table into a grid
named Button_Grid that is a custom control that I developed that is not data
aware. The Interbase Objects that I used was the TIB_Query. Hope
this helps.