Subject | Locate() goes to wrong record |
---|---|
Author | Joe Martinez |
Post date | 2005-11-30T00:55:19Z |
I am trying to use Locate() on a TIBOTable object. The call to
Locate() returns True, as if it succeeded, but the cursor is NOT
positioned on the correct record. Here is my code:
bool __fastcall TMainForm::LocateSomethingByGUID(TIBODataset*
TheDataset,String keyname,String theguidkey)
{
bool result;
String VerifyKey = "NOTHING";
int retrycount = 0;
TLocateOptions Opts;
Opts.Clear();
Variant locvalues[1];
locvalues[0] = Variant(theguidkey);
TheDataset->Refresh();
while (VerifyKey != theguidkey && retrycount < 100)
{
result = TheDataset->Locate(keyname, VarArrayOf(locvalues, 0),
Opts);
if (result == false)
return false;
retrycount++;
VerifyKey = TheDataset->FieldByName(keyname)->AsString;
}
return result;
}
The loop was added for debugging purposes. Every time Locate() is
called, VerifyKey gets set to the key of an apparently random record.
In my test case, it finally finds the correct record after 47
iterations through the loop. In another test case, it doesn't find
it, and the loop ends after the 100 tries.
Here is the definition of the TIBOTable (being passed in as the
TheDataset param).
object LayawayTable: TIBOTable
DatabaseName = 'SMRDBS_MAN'
FetchWholeRows = False
IB_Connection = TheDB
RecordCountAccurate = True
BeforeDelete = LayawayTableBeforeDelete
AfterDelete = LayawayTableAfterDelete
BeforePost = LayawayTableBeforePost
AfterPost = LayawayTableAfterPost
OnCalcFields = LayawayTableCalcFields
OnFilterRecord = TableFilterRecord
OnNewRecord = LayawayTableNewRecord
OnPostError = LayawayTablePostError
TableName = 'LAYAWAYS'
FieldOptions = []
Left = 420
Top = 187
object LayawayTableLAYID: TIntegerField
FieldName = 'LAYID'
Required = True
end
object LayawayTableCUSTID: TIntegerField
FieldName = 'CUSTID'
end
object LayawayTableLAYDESC: TStringField
FieldName = 'LAYDESC'
Size = 100
end
object LayawayTableLAYOPENDATE: TDateTimeField
FieldName = 'LAYOPENDATE'
OnSetText = LayawayTableLAYOPENDATESetText
end
object LayawayTableLAYSPERSON: TStringField
FieldName = 'LAYSPERSON'
end
object LayawayTableLAYCHARGE: TStringField
FieldName = 'LAYCHARGE'
Size = 1
end
object LayawayTableOwed: TCurrencyField
FieldKind = fkCalculated
FieldName = 'Owed'
Calculated = True
end
object LayawayTableBalance: TCurrencyField
FieldKind = fkCalculated
FieldName = 'Balance'
Calculated = True
end
object LayawayTableCustFname: TStringField
DisplayWidth = 25
FieldKind = fkLookup
FieldName = 'CustFname'
LookupDataSet = CustTable
LookupKeyFields = 'CUSTKEY'
LookupResultField = 'CUSTFNAME'
KeyFields = 'CUSTKEY'
Lookup = True
end
object LayawayTableCustLname: TStringField
DisplayWidth = 25
FieldKind = fkLookup
FieldName = 'CustLname'
LookupDataSet = CustTable
LookupKeyFields = 'CUSTKEY'
LookupResultField = 'CUSTLNAME'
KeyFields = 'CUSTKEY'
Lookup = True
end
object LayawayTableLAYAMOUNT: TCurrencyField
FieldName = 'LAYAMOUNT'
end
object LayawayTableSTOREID: TIntegerField
FieldName = 'STOREID'
Required = True
end
object LayawayTableLAYNOTES: TMemoField
FieldName = 'LAYNOTES'
BlobType = ftMemo
Size = 10000
end
object LayawayTableLAYBALANCE: TFloatField
FieldName = 'LAYBALANCE'
end
object LayawayTableLAYDUEDATE: TDateTimeField
FieldName = 'LAYDUEDATE'
OnSetText = LayawayTableLAYDUEDATESetText
end
object LayawayTableLAYAWAYSKEY: TStringField
FieldName = 'LAYAWAYSKEY'
Size = 36
end
object LayawayTableLAYAWAYSTIMESTAMP: TDateTimeField
FieldName = 'LAYAWAYSTIMESTAMP'
end
object LayawayTableCUSTKEY: TStringField
FieldName = 'CUSTKEY'
Required = True
Size = 36
end
object LayawayTableLayawaysCode: TStringField
FieldKind = fkCalculated
FieldName = 'LayawaysCode'
Calculated = True
end
end
Help! Am I doing something wrong, or is this a bug in IBO?
I am using IBO 4.3.Aa with BCB 4 if that makes a difference.
-Joe
Locate() returns True, as if it succeeded, but the cursor is NOT
positioned on the correct record. Here is my code:
bool __fastcall TMainForm::LocateSomethingByGUID(TIBODataset*
TheDataset,String keyname,String theguidkey)
{
bool result;
String VerifyKey = "NOTHING";
int retrycount = 0;
TLocateOptions Opts;
Opts.Clear();
Variant locvalues[1];
locvalues[0] = Variant(theguidkey);
TheDataset->Refresh();
while (VerifyKey != theguidkey && retrycount < 100)
{
result = TheDataset->Locate(keyname, VarArrayOf(locvalues, 0),
Opts);
if (result == false)
return false;
retrycount++;
VerifyKey = TheDataset->FieldByName(keyname)->AsString;
}
return result;
}
The loop was added for debugging purposes. Every time Locate() is
called, VerifyKey gets set to the key of an apparently random record.
In my test case, it finally finds the correct record after 47
iterations through the loop. In another test case, it doesn't find
it, and the loop ends after the 100 tries.
Here is the definition of the TIBOTable (being passed in as the
TheDataset param).
object LayawayTable: TIBOTable
DatabaseName = 'SMRDBS_MAN'
FetchWholeRows = False
IB_Connection = TheDB
RecordCountAccurate = True
BeforeDelete = LayawayTableBeforeDelete
AfterDelete = LayawayTableAfterDelete
BeforePost = LayawayTableBeforePost
AfterPost = LayawayTableAfterPost
OnCalcFields = LayawayTableCalcFields
OnFilterRecord = TableFilterRecord
OnNewRecord = LayawayTableNewRecord
OnPostError = LayawayTablePostError
TableName = 'LAYAWAYS'
FieldOptions = []
Left = 420
Top = 187
object LayawayTableLAYID: TIntegerField
FieldName = 'LAYID'
Required = True
end
object LayawayTableCUSTID: TIntegerField
FieldName = 'CUSTID'
end
object LayawayTableLAYDESC: TStringField
FieldName = 'LAYDESC'
Size = 100
end
object LayawayTableLAYOPENDATE: TDateTimeField
FieldName = 'LAYOPENDATE'
OnSetText = LayawayTableLAYOPENDATESetText
end
object LayawayTableLAYSPERSON: TStringField
FieldName = 'LAYSPERSON'
end
object LayawayTableLAYCHARGE: TStringField
FieldName = 'LAYCHARGE'
Size = 1
end
object LayawayTableOwed: TCurrencyField
FieldKind = fkCalculated
FieldName = 'Owed'
Calculated = True
end
object LayawayTableBalance: TCurrencyField
FieldKind = fkCalculated
FieldName = 'Balance'
Calculated = True
end
object LayawayTableCustFname: TStringField
DisplayWidth = 25
FieldKind = fkLookup
FieldName = 'CustFname'
LookupDataSet = CustTable
LookupKeyFields = 'CUSTKEY'
LookupResultField = 'CUSTFNAME'
KeyFields = 'CUSTKEY'
Lookup = True
end
object LayawayTableCustLname: TStringField
DisplayWidth = 25
FieldKind = fkLookup
FieldName = 'CustLname'
LookupDataSet = CustTable
LookupKeyFields = 'CUSTKEY'
LookupResultField = 'CUSTLNAME'
KeyFields = 'CUSTKEY'
Lookup = True
end
object LayawayTableLAYAMOUNT: TCurrencyField
FieldName = 'LAYAMOUNT'
end
object LayawayTableSTOREID: TIntegerField
FieldName = 'STOREID'
Required = True
end
object LayawayTableLAYNOTES: TMemoField
FieldName = 'LAYNOTES'
BlobType = ftMemo
Size = 10000
end
object LayawayTableLAYBALANCE: TFloatField
FieldName = 'LAYBALANCE'
end
object LayawayTableLAYDUEDATE: TDateTimeField
FieldName = 'LAYDUEDATE'
OnSetText = LayawayTableLAYDUEDATESetText
end
object LayawayTableLAYAWAYSKEY: TStringField
FieldName = 'LAYAWAYSKEY'
Size = 36
end
object LayawayTableLAYAWAYSTIMESTAMP: TDateTimeField
FieldName = 'LAYAWAYSTIMESTAMP'
end
object LayawayTableCUSTKEY: TStringField
FieldName = 'CUSTKEY'
Required = True
Size = 36
end
object LayawayTableLayawaysCode: TStringField
FieldKind = fkCalculated
FieldName = 'LayawaysCode'
Calculated = True
end
end
Help! Am I doing something wrong, or is this a bug in IBO?
I am using IBO 4.3.Aa with BCB 4 if that makes a difference.
-Joe