 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Marcio Ehrlich Guest
|
Posted: Sun May 02, 2004 3:08 am Post subject: How can I declare a TField at runtime? |
|
|
I am facing a problem that suggests I would need to include some TField as a
property a form, depending on the SQL of a TQuery (it may or not return that
field).
For example, with this form which type is declared as:
TFormQRSelecao = class(TQuickRep)
if according to some condition my TQueryCasting returns a currency field
named "Extras", how can I include this declaration:
QueryCastingExtras: TCurrencyField;
so I will be able to later retrieve QueryCasting['Extras'] value?
Is this the question or I am making a big mess?
Thanks,
Marcio
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Sun May 02, 2004 3:46 am Post subject: Re: How can I declare a TField at runtime? |
|
|
Marcio Ehrlich wrote:
| Quote: | For example, with this form which type is declared as:
TFormQRSelecao = class(TQuickRep)
if according to some condition my TQueryCasting returns a currency
field named "Extras", how can I include this declaration:
QueryCastingExtras: TCurrencyField;
so I will be able to later retrieve QueryCasting['Extras'] value?
|
If you have a query component where the Select statement may change with
regard to selected fields, then you do not want or need persistent field
components. By not having persistent fields, when you open TQueryCasting, it
will create TField objects for you for all the fields you have selected.
There are at least a couple of ways to determine if a field was selected or
not, one way is:
if Assigned(TQueryCasting .FieldByName('Extras')) then
ShowMessage(TQueryCasting .FieldByName('Extras').AsString);
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"True peace is not the absence of tension, but the presence of
justice." - Martin Luther King, Jr.
|
|
| Back to top |
|
 |
Marcio Ehrlich Guest
|
Posted: Sun May 02, 2004 4:44 pm Post subject: Re: How can I declare a TField at runtime? |
|
|
"Wayne Niddery [TeamB]" <wniddery (AT) chaffaci (DOT) on.ca> wrote:
| Quote: | (...) when you open TQueryCasting, it
will create TField objects for you
|
Wayne,
That's what I expected to happen. Nevertheless, when a Band.BeforePrint was
called with something like:
QRLabelExtras.Caption := QueryCasting.FieldByName('Extras').AsString;
I got the "field not found" error.
Finally I came to one conclusion: if you can't include ALL fields at design
time, it is better to declare none.
Once you have declared even one field, when you open your query no other
TField object will be created and you will get that "field not found" error.
So, I erased all TFields objects from the Interface section and now the
application runs ok independently of the queries' fields.
Is that what was supposed to be?
Marcio
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Sun May 02, 2004 5:34 pm Post subject: Re: How can I declare a TField at runtime? |
|
|
Marcio Ehrlich wrote:
| Quote: |
Finally I came to one conclusion: if you can't include ALL fields at
design time, it is better to declare none.
Once you have declared even one field, when you open your query no
other TField object will be created and you will get that "field not
found" error.
|
Correct. This is exactly the trade off of using persistent fields - those
are all that will exist. If the fields in your query are unchanging, then
persistent fields are fine (but still unecessary).
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"True peace is not the absence of tension, but the presence of
justice." - Martin Luther King, Jr.
|
|
| Back to top |
|
 |
Marcio Ehrlich Guest
|
Posted: Tue May 04, 2004 12:43 pm Post subject: Re: How can I declare a TField at runtime? |
|
|
"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote:
| Quote: | //create persistent field that do not exist
if Query1.FindField(Query1.FieldDefs[i].Name) = nil then
Query1.FieldDefs.Items[i].CreateField(Query1);
|
Very interesting, Brian, thank you.
Marcio
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|