Does anyone know what this happens?
I have declared all my database objects as integers as well as my dataset objects as integer
when I run my ado query, I get values, from here, im trying to assign it as to a dataset, which is also declared as integers. But it keeps giving me
incompatible types: widestring and tintegerfield
Here is the exact code:
dxMemData1.FieldByName(dxMemData1RetailCalendarPeriodID) :=
adoTreeWindow.FieldByName('RetailCalendarPeriodID').AsInteger;
dxMemData1.FieldByName(dxMemData1RetailCalendarPeriodID) := adoTreeWindow.FieldByName('RetailCalendarPeriodID').AsInteger
should not compile.
It looks like dxMemData1RetailCalendarPeriodID
is a persistent field object you've created on you dxMemData1 dataset. The FieldByName
method is used to find a field by its name, but you don't need to do that because you already have the field, dxMemData1RetailCalendarPeriodID
!
So, what you need is simply
dxMemData1RetailCalendarPeriodID.AsInteger := adoTreeWindow.FieldByName('RetailCalendarPeriodID').AsInteger
The reason for the compiler error is that FieldByName
expects to be passed a string giving the name of a field whereas you were trying to pass the field itself, which is a TObject descendant not a string. The following would have worked, but is unnecessary because of the code I've already shown:
dxMemData1.FieldByName(dxMemData1RetailCalendarPeriodID.FieldName) := adoTreeWindow.FieldByName('RetailCalendarPeriodID').AsInteger;
Update You say you are getting an "Invalid variant operation" error. Do you still get it if you use this code:
if not adoTreeWindow.FieldByName('RetailCalendarPeriodID').IsNull then
dxMemData1RetailCalendarPeriodID.AsInteger := adoTreeWindow.FieldByName('RetailCalendarPeriodID').AsInteger
?