Previous Topic

Next Topic

Inhoudsopgave

Book Index

Create A Calculated (Persistent) Field

Dim fldDescription, fldLUB, fldCalculated

Sub Main()

Call frmCalcFieldsExample_InitializeComponents()

frmCalcFieldsExample.ShowModal

Set fldDescription = nothing

Set fldLUB = nothing

Set fldCalculated = nothing

End Sub

Sub btnOpenDatasetClick(Sender)

Rem When using calculated fields, all dataset fields have to be persistent.

Rem Each field to be shown in the grid has to be created explicitly.

Set fldDescription = IsahObjects.Get("TIsahStringField")

fldDescription.Name = "fldDescription"

fldDescription.FieldName = "Description"

fldDescription.DataSet = IsahCDSQuery1

Set fldLUB = IsahObjects.Get("TIsahStringField")

fldLUB.Name = "fldLUB"

fldLUB.FieldName = "LastUpdatedBy"

fldLUB.DataSet = IsahCDSQuery1

Set fldCalculated = IsahObjects.Get("TIsahStringField")

fldCalculated.Name = "fldCalculated"

fldCalculated.FieldName = "MyCalcField"

fldCalculated.FieldKind = 1 'This field is calculated

fldCalculated.DataSet = IsahCDSQuery1

IsahCDSQuery1.OnCalcFields = "OnCalcFields" 'This procedure assigns values to calculated fields

IsahCDSQuery1.Open

End Sub

Sub OnCalcFields(DataSet)

fldCalculated.AsString = DataSet.FieldByName("Description").AsString & ";" & DataSet.FieldByName("LastUpdatedBy").AsString

End Sub

'--- Designer generated code. Do not modify ---

Dim frmCalcFieldsExample, StatusBar1, btnOpenDataset, DBEdit1, DBGrid1, IsahDBNavigator1, DataSource1

Dim IsahCDSQuery1

Sub frmCalcFieldsExample_InitializeComponents()

Set frmCalcFieldsExample = IsahObjects.Get("TForm")

With frmCalcFieldsExample

.Loading = True

.Name = "frmCalcFieldsExample"

.Left = 311

.Top = 180

.Width = 462

.Height = 388

.Caption = "Calculated fields examples"

.Color = -16777201

.Font.Charset = 1

.Font.Color = -16777208

.Font.Height = -11

.Font.Name = "MS Sans Serif"

.Font.Style = 0

.OldCreateOrder = 0

.PixelsPerInch = 96

.TextHeight = 13

.OnCreate = "frmCalcFieldsExampleCreate"

End With

Set StatusBar1 = IsahObjects.Get("TStatusBar")

With StatusBar1

.Parent = frmCalcFieldsExample

.Name = "StatusBar1"

.Left = 0

.Top = 335

.Width = 454

.Height = 19

End With

Set btnOpenDataset = IsahObjects.Get("TButton")

With btnOpenDataset

.Parent = frmCalcFieldsExample

.Name = "btnOpenDataset"

.Left = 12

.Top = 16

.Width = 91

.Height = 25

.Caption = "Open T_Country"

.TabOrder = 1

.OnClick = "btnOpenDatasetClick"

End With

Set DBEdit1 = IsahObjects.Get("TDBEdit")

With DBEdit1

.Parent = frmCalcFieldsExample

.Name = "DBEdit1"

.Left = 114

.Top = 20

.Width = 121

.Height = 21

.DataField = "Description"

.DataSource = "DataSource1"

.TabOrder = 3

End With

Set DBGrid1 = IsahObjects.Get("TDBGrid")

With DBGrid1

.Parent = frmCalcFieldsExample

.Name = "DBGrid1"

.Left = 12

.Top = 62

.Width = 432

.Height = 260

.DataSource = "DataSource1"

.TabOrder = 2

.TitleFont.Charset = 1

.TitleFont.Color = -16777208

.TitleFont.Height = -11

.TitleFont.Name = "MS Sans Serif"

.TitleFont.Style = 0

End With

Set IsahDBNavigator1 = IsahObjects.Get("TIsahDBNavigator")

With IsahDBNavigator1

.Parent = frmCalcFieldsExample

.Name = "IsahDBNavigator1"

.Left = 248

.Top = 16

.Width = 168

.Height = 25

.DataSource = "DataSource1"

.VisibleButtons = 15

.Flat = 1

.TabOrder = 6

End With

Set DataSource1 = IsahObjects.Get("TDataSource")

With DataSource1

.Name = "DataSource1"

.DataSet = "IsahCDSQuery1"

.Left = 412

.Top = 40

End With

Set IsahCDSQuery1 = IsahObjects.Get("IsahCDSQuery1")

With IsahCDSQuery1

.Name = "IsahCDSQuery1"

.DatabaseName = "dbIsahAdmin"

.SQL.Add "Select * From T_Country"

.Left = 376

.Top = 40

End With

frmCalcFieldsExample.Loading = False

End Sub

'--- End generated code -----------------------