 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Lutz Kutscher Guest
|
Posted: Wed Dec 03, 2003 1:38 pm Post subject: Adding calculated fields at run time |
|
|
Hi,
I've got a form, that enables the user to select fields for a query:
PartNo, SalesCount, Date ...
If the user selects "PartNo" to be displayed in the result, I want to add a
field "PartName".
The data shown in PartName is loaded from a table that's not part of the
query,
so I wanted to add it as calculated field.
How can I add a calculated field at runtime?
--
_____________________________________
Lutz Kutscher
Pattburg Poetzsch GmbH & Co KG
Tel. +49 461 773 15 60
Fax +49 461 773 15 15
[email]LKutscher (AT) graensen (DOT) dk[/email]
|
|
| Back to top |
|
 |
Ross B. Guest
|
Posted: Wed Dec 03, 2003 3:08 pm Post subject: Re: Adding calculated fields at run time |
|
|
"Lutz Kutscher" <LKutscher (AT) Graensen (DOT) dk> wrote
| Quote: | Hi,
I've got a form, that enables the user to select fields for a query:
PartNo, SalesCount, Date ...
If the user selects "PartNo" to be displayed in the result, I want to add
a
field "PartName".
The data shown in PartName is loaded from a table that's not part of the
query,
so I wanted to add it as calculated field.
How can I add a calculated field at runtime?
--
_____________________________________
Lutz Kutscher
Pattburg Poetzsch GmbH & Co KG
Tel. +49 461 773 15 60
Fax +49 461 773 15 15
[email]LKutscher (AT) graensen (DOT) dk[/email]
|
You can add calced fields at runtime. By creating and instance of the Field.
procedure AddCalcedField(aDataSet,aFieldName,aDataType);
F:TField;
begin
F:=TField.Create(aDataSet);
// F.FieldKind:=fkInternalCalc; <--- Look at the diff btw fkInternal and
ftCalcl
F.FieldKind:=fkCalc;
F.FieldName:=aFieldName;
case aDataType of
ftInteger:F.DataType:=ftInteger;
...
ftString:F.DataType:=ftString;
end;
.....
Note if you are opening and closing a query and possibly
selecting/deselecting multiple dynamically calced fields then be sure to
remove the fields you may no longer need while adding the ones you do need.
Ross B.
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Wed Dec 03, 2003 5:44 pm Post subject: Re: Adding calculated fields at run time |
|
|
Lutz Kutscher wrote:
| Quote: |
I've got a form, that enables the user to select fields for a query:
PartNo, SalesCount, Date ...
If the user selects "PartNo" to be displayed in the result, I want to
add a field "PartName".
The data shown in PartName is loaded from a table that's not part of
the query,
so I wanted to add it as calculated field.
How can I add a calculated field at runtime?
|
If you are generating the query dynamically anyway, why not add it (a join)
to the query itself?
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"It is error alone which needs the support of government. Truth can
stand by itself." - Thomas Jefferson
|
|
| Back to top |
|
 |
Lutz Kutscher Guest
|
Posted: Thu Dec 04, 2003 2:08 pm Post subject: Re: Adding calculated fields at run time |
|
|
"Wayne Niddery [TeamB]" <wniddery (AT) chaffaci (DOT) on.ca> schrieb im Newsbeitrag
news:3fce212e$1 (AT) newsgroups (DOT) borland.com...
| Quote: | If you are generating the query dynamically anyway, why not add it (a
join)
to the query itself?
.... because the data in that field originates from a database on a different |
server.
Anyway, I found a solution.
I added the following code to the BeforeOpen-Handler of the query:
Query.FieldDefs.Update;
if Query.FieldDefs.IndexOf('PartNo') > -1 then
begin
TDataSetCracker(Query).CreateFields;
with TStringField.Create(Query) do begin
Name := PartNameComponent; //defined as constant
FieldName := PartNameField;//defined as constant
DataSet := Query;
FieldKind := fkCalculated;
end;
end;
In the AfterClose-Handler I added:
Query.Fields.Clear;
.... now it works.
| Quote: | Lutz Kutscher wrote:
I've got a form, that enables the user to select fields for a query:
PartNo, SalesCount, Date ...
If the user selects "PartNo" to be displayed in the result, I want to
add a field "PartName".
The data shown in PartName is loaded from a table that's not part of
the query,
so I wanted to add it as calculated field.
How can I add a calculated field at runtime?
|
|
|
| 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
|
|