🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.vdbase.forms
3 messages
3 total messages Started by Calciotel Fri, 12 Mar 1999 00:00
Calculate fields in a grid
#51
Author: Calciotel
Date: Fri, 12 Mar 1999 00:00
10 lines
698 bytes
Hi,
It's possible insert in a grid of a form a column with the result of a
function calculated??

Example:
A column with the number of record's of a child table of the rowset display
in this grid
(form.rowset.query2.count())???

Thank's. Andrea.
Re: Calculate fields in a grid
#53
Author: Peter Rorlick
Date: Fri, 12 Mar 1999 00:00
86 lines
3800 bytes
This is a multi-part message in MIME format.
--------------582860273D0CED10A31FB0BA
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Transfer-Encoding: 7bit

Calciotel wrote:

> It's possible insert in a grid of a form a column with the result of a
>
> function calculated??

Yes.  See the attached file.

-------------------------
Peter Rorlick
Montreal Business Software


--------------582860273D0CED10A31FB0BA
Content-Type: text/plain; charset=us-ascii; name="calcfiel.how"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="calcfiel.how"

CalcFiel.How  -  How to put a calculated field onto a grid

Visual dBase 7 HOW file

Author: Peter Rorlick
Date: Dec 16 1997
*----------------------------------------------------

Here's a step-by-step example of how to create a calculated field and
how to get that field to show up on a grid.
(Note: a similar technique can be used to get calculated fields onto
reports.)

Begin designing a new form.

Using the navigator, switch to the \Samples\Fleet\Tables directory.

Click on the Tables tab and drag and drop Aircraft.dbf onto your form.
This will create a query object on the form, called Aircraft1.

Using the inspector, go the Events tab for the query object and click on
the tool button of the OnOpen event.
In the function called Aircraft1_OnOpen, type:
      oField=new Field()
      oField.FieldName := "Make and model"
      This.Rowset.Fields.Add(oField)
      oField.BeforeGetValue := {; Return Trim(This.Parent["Make"].Value)
+ space(1) + This.Parent["Model"].Value }

You have just instructed the query to add a calculated field, showing
Make and Model in a single column.

Note that you can sometimes create calculated fields more simply, in the
SQL "SELECT...FROM..." statement.  But the way we're doing it here is
much more powerful, because the .BeforeGetValue is handled by VdB rather
than by the SQL engine. This means that you can use xbase functions and
UDFs to construct your calculated fields - and this is a vital
difference. SQL is nice but it is sometimes not flexible enough.

From the Component Palette, drop a grid onto the form, and enlarge it.
Select the grid, and using the inspector, click on the dropdown button
of the DataLink property, and set it to Aircraft1.
As soon as you do this, you'll notice that the grid becomes populated
with rows from the table.

Now, our goal is to get the calculated field onto the grid. To do this
you will need to run the query again so that "Make and model" will be
available in the Column Selector tool.  Unfortunately, if you try to set
the query's Active property to false and then back to true, you'll get
an error.  But you can effectively run the query again by saving the
form (call it MyGrid.WFM) and then open it again with the designer.
Once you have done that, click on the grid, bring up the inspector, and
click on the tool button of the Columns property.  Double-click on the
"Make and model" field, and then double-click on the "Layout Image"
field. Click on the OK button.

Save the form and run it.  Voila!



--------------582860273D0CED10A31FB0BA--
Re: Calculate fields in a grid
#109
Author: Calciotel
Date: Sun, 14 Mar 1999 00:00
22 lines
1115 bytes
This is OK for a calculate field of the same query but I would like insert
in a grid of the father table the number of records content in the child
table for the record selected with the function form.query2.rowset.count().
How i can do???
Thank's
 Andrea.

Peter Rorlick ha scritto nel messaggio
<36E92320.325B3054@InjuryTracker.com>...
>Calciotel wrote:
>
>> It's possible insert in a grid of a form a column with the result of a
>>
>> function calculated??
>
>Yes.  See the attached file.
>
>-------------------------
>Peter Rorlick
>Montreal Business Software
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads