Discussion:
Losing fields on second pass
(too old to reply)
Mark
2008-01-10 12:56:01 UTC
Permalink
MySQL 5 with Corelab dbExpress drivers

See my code below. This is used in an Edit window to copy address data from
one table into another after the user has selected the ID for an address
from a Search window.

The first time the user selects an address all data is copied as it should.
However when the user chooses another address, the code is executed up to
the line I have marked "1:". When trying to perform the next line (marked
with "2:"), I get a "Field TATASTRA not found".

As you can see I have inserted a ShowMessage loop to confirm that after the
select all fields are there. And they are !

When inspecting dsTA with ALT+F5 I can see FieldCount = 16. Right after
executing the line marked with "1:" the FieldCount jumps to 0. So that
probably is the reason why the next field can't be found... But why is this
happening and why only on the second (or subsequent) pass as it doesn't
occur on the first pass. THen it all works fine...


Anyone has any ideas on why this could be happening ?


Code:

dsTA := Fdm.TATRANP;
qry := 'Select * from TATRANP where '
+ 'TATANUMM = ' + IntToStr(TANUMM);
dsTA.DataSet.CommandType := ctQuery;
dsTA.DataSet.CommandText := qry;
dsTA.Open;

dsVO := Fdm.VOVERVP;

if dsTA.RecordCount > 0 then begin
for i := 0 to dsTA.FieldCount - 1 do
ShowMessage(dsTA.Fields[i].FieldName);

1: dsVO.FieldByName('VOVONAAM22').AsString :=
dsTA.FieldByName('TATANAAM').AsString;
2: dsVO.FieldByName('VOVOSTRA22').AsString :=
dsTA.FieldByName('TATASTRA').AsString;
dsVO.FieldByName('VOVOHSNR22').AsString :=
dsTA.FieldByName('TATAHSNR').AsString;
dsVO.FieldByName('VOVOHSTV22').AsString :=
dsTA.FieldByName('TATAHSTV').AsString;
dsVO.FieldByName('VOVOADRS22').AsString :=
dsTA.FieldByName('TATAADRS').AsString;
dsVO.FieldByName('VOQLCODE22').AsString :=
dsTA.FieldByName('TAQLCODE').AsString;
dsVO.FieldByName('VOQPCODE22').AsString :=
dsTA.FieldByName('TAQPCODE').AsString;
dsVO.FieldByName('VOVOPLAA22').AsString :=
dsTA.FieldByName('TATAPLAA').AsString;
dsVO.FieldByName('VOTANUMM22').AsString :=
dsTA.FieldByName('TATANUMM').AsString;

if OGNUMM = 0 then
dsVO.FieldByName('VOOGNUMM22').Clear
else
dsVO.FieldByName('VOOGNUMM22').AsInteger := OGNUMM;

end;
dsTA.Close;
Mark
2008-01-11 10:45:10 UTC
Permalink
Problem solved.

The first datafield I am assigning to is linked to a DBEdit. Somewhere
buried in the code an OnChange event is assigned to this DBEDit which didn't
get documented. Within the chain of events that is occuring by me assigning
a value, the same datacomponent is being used and being closed at some
point.
Post by Mark
MySQL 5 with Corelab dbExpress drivers
See my code below. This is used in an Edit window to copy address data from
one table into another after the user has selected the ID for an address
from a Search window.
The first time the user selects an address all data is copied as it should.
However when the user chooses another address, the code is executed up to
the line I have marked "1:". When trying to perform the next line (marked
with "2:"), I get a "Field TATASTRA not found".
As you can see I have inserted a ShowMessage loop to confirm that after the
select all fields are there. And they are !
When inspecting dsTA with ALT+F5 I can see FieldCount = 16. Right after
executing the line marked with "1:" the FieldCount jumps to 0. So that
probably is the reason why the next field can't be found... But why is this
happening and why only on the second (or subsequent) pass as it doesn't
occur on the first pass. THen it all works fine...
Anyone has any ideas on why this could be happening ?
dsTA := Fdm.TATRANP;
qry := 'Select * from TATRANP where '
+ 'TATANUMM = ' + IntToStr(TANUMM);
dsTA.DataSet.CommandType := ctQuery;
dsTA.DataSet.CommandText := qry;
dsTA.Open;
dsVO := Fdm.VOVERVP;
if dsTA.RecordCount > 0 then begin
for i := 0 to dsTA.FieldCount - 1 do
ShowMessage(dsTA.Fields[i].FieldName);
1: dsVO.FieldByName('VOVONAAM22').AsString :=
dsTA.FieldByName('TATANAAM').AsString;
2: dsVO.FieldByName('VOVOSTRA22').AsString :=
dsTA.FieldByName('TATASTRA').AsString;
dsVO.FieldByName('VOVOHSNR22').AsString :=
dsTA.FieldByName('TATAHSNR').AsString;
dsVO.FieldByName('VOVOHSTV22').AsString :=
dsTA.FieldByName('TATAHSTV').AsString;
dsVO.FieldByName('VOVOADRS22').AsString :=
dsTA.FieldByName('TATAADRS').AsString;
dsVO.FieldByName('VOQLCODE22').AsString :=
dsTA.FieldByName('TAQLCODE').AsString;
dsVO.FieldByName('VOQPCODE22').AsString :=
dsTA.FieldByName('TAQPCODE').AsString;
dsVO.FieldByName('VOVOPLAA22').AsString :=
dsTA.FieldByName('TATAPLAA').AsString;
dsVO.FieldByName('VOTANUMM22').AsString :=
dsTA.FieldByName('TATANUMM').AsString;
if OGNUMM = 0 then
dsVO.FieldByName('VOOGNUMM22').Clear
else
dsVO.FieldByName('VOOGNUMM22').AsInteger := OGNUMM;
end;
dsTA.Close;
Loading...