Board index » cppbuilder » Get field value

Get field value


2006-07-28 08:16:04 PM
cppbuilder58
Hello there all,
I am using quick reports built in with C++ builder 6.0.
I am linking the DBText fields to the TQuery at the design time.
The problem is if date field in the database is NULL
it is displaying defualt date 30-Jul-1899.
I want to display empty
Thanks
Regards
SA
 
 

Re:Get field value

You can create an event handler for OnPrint of the field. Then you can set
the text to what you would like it to be.
HTH,
- Clayton
 

Re:Get field value

Hello Clayton,
thanks for the reply.
I am bounding the control at the design time to the TQuery.
In the OnPrint event handler, how can i get the field value,
Any idea
Best Regards
SA
"Clayton Arends" < XXXX@XXXXX.COM >wrote in message
Quote
You can create an event handler for OnPrint of the field. Then you can
set the text to what you would like it to be.

HTH,
- Clayton

 

{smallsort}

Re:Get field value

If the event handler will only be used for a specific field then you (as the
programmer) will already know which field you are referencing and can
evaluate it appropriately. For example:
void __fastcall TForm1::QRDBText1Print(TObject *sender,
AnsiString &Value)
{
// We know that QRDBText1 is the text field and we know
// the field of the query that we assigned to it. You
// can either access it by name via Query1->FieldByName
// or by index via Query1->Fields->Fields[index].
Db::TField* field = Query1->FieldByName("FieldName");
if (field->AsDateTime == TDateTime(0))
Value = "";
}
However, if you are going to create the event to handle multiple fields then
you can do things a bit more generic and still achieve the same goal:
void __fastcall TForm1::DateFieldPrint(TObject *sender,
AnsiString &Value)
{
TQRDBText* textField = static_cast <TQRDBText*>(sender);
Db::TField* field = textField->DataSet->FieldByName(
textField->DataField);
if (field->AsDateTime == TDateTime(0))
Value = "";
}
Does this help?
- Clayton
 

Re:Get field value

thanks Clayton for your inputs.
this helps me.
cheers :)
SA
"Clayton Arends" < XXXX@XXXXX.COM >wrote in message
Quote
If the event handler will only be used for a specific field then you (as
the programmer) will already know which field you are referencing and can
evaluate it appropriately. For example:

void __fastcall TForm1::QRDBText1Print(TObject *sender,
AnsiString &Value)
{
// We know that QRDBText1 is the text field and we know
// the field of the query that we assigned to it. You
// can either access it by name via Query1->FieldByName
// or by index via Query1->Fields->Fields[index].

Db::TField* field = Query1->FieldByName("FieldName");
if (field->AsDateTime == TDateTime(0))
Value = "";
}

However, if you are going to create the event to handle multiple fields
then you can do things a bit more generic and still achieve the same goal:

void __fastcall TForm1::DateFieldPrint(TObject *sender,
AnsiString &Value)
{
TQRDBText* textField = static_cast <TQRDBText*>(sender);
Db::TField* field = textField->DataSet->FieldByName(
textField->DataField);
if (field->AsDateTime == TDateTime(0))
Value = "";
}

Does this help?
- Clayton