Board index » cppbuilder » Cannot attach OnValidate event to TField

Cannot attach OnValidate event to TField


2004-10-15 09:40:11 PM
cppbuilder69
I have been trying to find a way of validating data input into a DBGrid
before it updates the database. It seems the best way is to use the
OnValidate event on the fields I want to validate.
My problem is that I cannot find a way of attaching the event to the
table. Double-clicking on the DBGrid shows the Columns of the database.
When I select a field I can see its properties in the object inspector,
but the events tab is blank.
Why is OnValidate not in the events tab?
Any ideas are appreciated.
 
 

Re:Cannot attach OnValidate event to TField

Hello Ulrich,
Have you considered creating persistent fields on your data set ?
HTH
Jayme.
"Ulrich" < XXXX@XXXXX.COM >escreveu na mensagem
Quote
I have been trying to find a way of validating data input into a DBGrid
before it updates the database. It seems the best way is to use the
OnValidate event on the fields I want to validate.

My problem is that I cannot find a way of attaching the event to the
table. Double-clicking on the DBGrid shows the Columns of the database.
When I select a field I can see its properties in the object inspector,
but the events tab is blank.
Why is OnValidate not in the events tab?

Any ideas are appreciated.
 

Re:Cannot attach OnValidate event to TField

Hello Jayme,
thanks for your reply.
What do you mean, create persistent fields on the data set?
The database has several persistent fields, so the data set
has persistent fields. Or am I wrong?
Ulrich
Jayme Jeffman Filho wrote:
Quote
Hello Ulrich,

Have you considered creating persistent fields on your data set ?

HTH

Jayme.

"Ulrich" < XXXX@XXXXX.COM >escreveu na mensagem
news: XXXX@XXXXX.COM ...

>I have been trying to find a way of validating data input into a DBGrid
>before it updates the database. It seems the best way is to use the
>OnValidate event on the fields I want to validate.
>
>My problem is that I cannot find a way of attaching the event to the
>table. Double-clicking on the DBGrid shows the Columns of the database.
>When I select a field I can see its properties in the object inspector,
>but the events tab is blank.
>Why is OnValidate not in the events tab?
>
>Any ideas are appreciated.



 

{smallsort}

Re:Cannot attach OnValidate event to TField

Hello Ulrich,
We call persistent fields those which are created when
you right click a TDataSet component like TQuery or
TTable and click on the "Fields Editor" option and ask
to add all fields. The TDataSet::Database must be
connected.
This action creates the TFields you've asked to, adding
their definition on the header file of the form that contains
the TDataSet component.
HTH
Jayme.
"Ulrich" < XXXX@XXXXX.COM >escreveu na mensagem
Quote
Hello Jayme,

thanks for your reply.
What do you mean, create persistent fields on the data set?
The database has several persistent fields, so the data set
has persistent fields. Or am I wrong?

Ulrich



Jayme Jeffman Filho wrote:
>Hello Ulrich,
>
>Have you considered creating persistent fields on your data set ?
>
>HTH
>
>Jayme.
>
>"Ulrich" < XXXX@XXXXX.COM >escreveu na mensagem
>news: XXXX@XXXXX.COM ...
>
>>I have been trying to find a way of validating data input into a DBGrid
>>before it updates the database. It seems the best way is to use the
>>OnValidate event on the fields I want to validate.
>>
>>My problem is that I cannot find a way of attaching the event to the
>>table. Double-clicking on the DBGrid shows the Columns of the database.
>>When I select a field I can see its properties in the object inspector,
>>but the events tab is blank.
>>Why is OnValidate not in the events tab?
>>
>>Any ideas are appreciated.
>
>
>
 

Re:Cannot attach OnValidate event to TField

Hello,
thanks so far for your help. I managed to attatch the OnValidate-Event
to all TFields.
But now I have another problem: In my program it is possible to add an
new field dynamicly at runtime. I do this by executing an SQL-statement.
Up to now the new field was shown in the DBGrid and was editable. Now
the field is not shown in the DBGrid. And when I try to set a value (
for example: DataSet->FindField(name)->Text = "a" ) there is always an
error, because the field can not be found.
I have another question. After solving the upper problem, how can I
attatch the OnValidate-Event to the new added field dynamicly at runtime?
Thanks for any solutions.
Ulrich
Jayme Jeffman Filho wrote:
Quote
Hello Ulrich,

We call persistent fields those which are created when
you right click a TDataSet component like TQuery or
TTable and click on the "Fields Editor" option and ask
to add all fields. The TDataSet::Database must be
connected.

This action creates the TFields you've asked to, adding
their definition on the header file of the form that contains
the TDataSet component.

HTH

Jayme.

 

Re:Cannot attach OnValidate event to TField

Hello Ulrich,
From the Help file : "When you create persistent fields for
a dataset, only those fields you select are available to your
application at design time and runtime."
I don't know how to create persistent fields at runtime. So
I think you should not use persistent fields if your application
needs to add fields to the data set at runtime. So delete all
persistent fields you've created, I'm sorry.
There are other ways of getting access to the TField object :
1. TFielld *aField = DataSet->Fields->Fiels[i] ;
// where i is the field order in the data set.
2. TFielld *aField = DBGrid->Fields[i] ;
// where i is the column order in the DBGrid.
Setting aField->ReadOnly = true has the same result that
you've got using persistent fields.
You can set any event handler by setting it to the name of
the function which is intend to be a event handler
void myFunction (TField *Sender);
aField->OnValidate = myFunction ;
HTH
Jayme.
"Ulrich" < XXXX@XXXXX.COM >escreveu na mensagem
Quote
Hello,

thanks so far for your help. I managed to attatch the OnValidate-Event
to all TFields.

But now I have another problem: In my program it is possible to add an
new field dynamicly at runtime. I do this by executing an SQL-statement.
Up to now the new field was shown in the DBGrid and was editable. Now
the field is not shown in the DBGrid. And when I try to set a value
for example: DataSet->FindField(name)->Text = "a" ) there is always an
error, because the field can not be found.

I have another question. After solving the upper problem, how can I
attatch the OnValidate-Event to the new added field dynamicly at runtime?

Thanks for any solutions.

Ulrich



Jayme Jeffman Filho wrote:
>Hello Ulrich,
>
>We call persistent fields those which are created when
>you right click a TDataSet component like TQuery or
>TTable and click on the "Fields Editor" option and ask
>to add all fields. The TDataSet::Database must be
>connected.
>
>This action creates the TFields you've asked to, adding
>their definition on the header file of the form that contains
>the TDataSet component.
>
>HTH
>
>Jayme.
>