I've got two ClientDatasets which get their records from a query from
Firebird database using ZEOS library.
The first CDS holds all fields from a contacts table and one additional
field, manually added: FIRSTLASTNAME. This field is of type fkCalculated
and has assigned an OnGetText event:
procedure TdmCustomer.cdsCustContactsLASTFIRSTNAMEGetText(Sender: TField;
var Text: string; DisplayText: Boolean);
begin
Text := Sender.DataSet.FieldByName('LASTNAME').AsString + ' ' +
Sender.DataSet.FieldByName('FIRSTNAME').AsString;
end;
This works well when displaying this field inside a TDBGrid.
This does not work, when I try to perform a lookup like this one:
Val := dmCustomer.cdsCustContacts.Lookup('CONTACTSNO',
VarArrayOf([Value]), 'FIRSTLASTNAME');
1) I would expect to get the calculated value of the OnGetText event, but
get a blank string back.
2) Next, I'm trying to use this calculated field in the second CDS.
I've manually added a lookup field, FieldKind := fkLookup. The KeyField is
correctly set as well as the LookupKeyFields property.
I would like to use the calculated field 'FIRSTLASTNAME' from the first CDS
as the LookupResultField.
But I too get a blank string back instead.
Did I made something wrong or is this not possible at all?
--
cu,
Michael
>
--
Brian Bushay (TeamB)
Bbu...@NMPLS.com
>>1) I would expect to get the calculated value of the OnGetText event, but
>>get a blank string back.
> That would be an unreasonable expectation.
> The value of calculated fields should be set in the dataSet's OnCalcField event
Brian,
yes that sound at least more reasonable ;-) I now did set this event, eg:
procedure TdmCustomer.cdsCustContactsCalcFields(DataSet: TDataSet);
begin
if DataSet.State = dsCalcFields then
begin
cdsCustContactsLASTFIRSTNAME.Value := cdsCustContactsLASTNAME.Value +
cdsCustContactsFIRSTNAME.Value;
cdsCustContactsFIRSTLASTNAME.Value := cdsCustContactsFIRSTNAME.Value +
cdsCustContactsLASTNAME.Value;
end;
end;
But this event is not fired at all. As mentioned before I set FieldKind to
fkCalculated. The client dataset property AutoCalcFields is set to True,
setting it to False does not change anything though.
I'm using a TClientDateset with a TDataSetProvider which gets its records
from a query using the ZEOS library to access a Firebird database.
--
cu,
Michael
> I'm using a TClientDateset with a TDataSetProvider which gets its records
> from a query using the ZEOS library to access a Firebird database.
It seems that this does not work if I us the OnCalcEvent with the
TClientDataset. When assigning the event to the query itself and do the
calculating there it works flawlessly.
--
cu,
Michael
I hope you are right! I have used CalcFields events thousands of times
since Delphi 1, and I have never referenced "State = dsCalcFields" from
within a CalcFields event.
Loren sZendre
Regards, Paul.
"Michael Fritz" <spam_...@yahoo.de> wrote in message
news:9gr7jhth4mob.6...@40tude.net...
> When supplying an OnCalcFields procedure, I would not normally check that
> State = dsCalcFields. The code will only be called when its doing the
> CalcFields anyway. I don't know if the State will be dsCalcFields at the
> point your code is called and your check may be preventing it getting to the
> point where you assign values.
May be but I set a break point at the line where I check for dsCalcFields
and this break is never reached either.
--
cu,
Michael
If not, then the CDS will not call its OnCalcFields.
Also see the help on the difference between the types of calculated fields
for a CDS (fkInternalCalc and fkCalculated).
Paul.
"Michael Fritz" <spam_...@yahoo.de> wrote in message
news:ea4k0jz8i3pf.1jxr1sh5d0wnl$.dlg@40tude.net...
Sounds like you have defined the calculated field at the ZEOS dataset but then
trying to catch onCalcFields on your ClientDataset. Be aware that your
clientdataset will handle serverside calculated fields as fkData(IIRC all
serverside fields will become fkData fields on the clientdataset). You have to
define the calculated field at the clientdataset to to get the onCalcFields
event fired.
--
Ralf Jansen
deepinvent Software GmbH - Viersen, Germany - http://www.deepinvent.com
Archiving E-mails with MailStore: http://www.mailstore.com
Then you must have the calculated field defined in the query not in the
TclientDataset. Move the calculated field to the TclientDataset if you don't
want to set its value in the Query