Difference between revisions of "TSqlite3 Master Detail Example"

From Lazarus wiki
Jump to navigationJump to search
Line 233: Line 233:
 
   {$I uMain.lrs}
 
   {$I uMain.lrs}
  
end.   
+
end.
 +
 
 +
object fMain: TfMain
 +
   Left = 395
 +
  Height = 332
 +
  Top = 218
 +
  Width = 534
 +
  ActiveControl = nbMain
 +
  BorderIcons = [biSystemMenu, biMinimize]
 +
  BorderStyle = bsSingle
 +
  Caption = 'Master Detail Example - SQLLite3'
 +
  ClientHeight = 305
 +
  ClientWidth = 534
 +
  Font.Height = -13
 +
  Font.Name = 'Sans'
 +
  Menu = mmMain
 +
  OnCloseQuery = FormCloseQuery
 +
  OnCreate = FormCreate
 +
  OnDestroy = FormDestroy
 +
  OnShow = FormShow
 +
  Position = poScreenCenter
 +
  LCLVersion = '0.9.27'
 +
  object sbMain: TStatusBar
 +
    Left = 0
 +
    Height = 19
 +
    Top = 286
 +
    Width = 534
 +
    AutoHint = True
 +
    Panels = <>
 +
  end
 +
  object nbMain: TNotebook
 +
    Left = 0
 +
    Height = 286
 +
    Top = 0
 +
    Width = 534
 +
    Align = alClient
 +
    PageIndex = 0
 +
    TabOrder = 1
 +
    object pSales: TPage
 +
      Caption = 'Sales'
 +
      ClientWidth = 532
 +
      ClientHeight = 259
 +
      object Label3: TLabel
 +
        Left = 0
 +
        Height = 18
 +
        Top = 241
 +
        Width = 532
 +
        Align = alBottom
 +
        Caption = 'Select Customer First, then click in item number field to select item, then save'
 +
        ParentColor = False
 +
      end
 +
      object pnlSelectCust: TPanel
 +
        Left = 15
 +
        Height = 216
 +
        Top = 14
 +
        Width = 232
 +
        BevelInner = bvLowered
 +
        BevelWidth = 2
 +
        ClientHeight = 216
 +
        ClientWidth = 232
 +
        TabOrder = 0
 +
        object Label1: TLabel
 +
          Left = 4
 +
          Height = 18
 +
          Top = 4
 +
          Width = 224
 +
          Align = alTop
 +
          Alignment = taCenter
 +
          Caption = 'Customer Detail'
 +
          Font.Height = -13
 +
          Font.Name = 'Sans'
 +
          Font.Style = [fsBold, fsItalic]
 +
          ParentColor = False
 +
          ParentFont = False
 +
        end
 +
        object Label2: TLabel
 +
          Left = 24
 +
          Height = 18
 +
          Top = 31
 +
          Width = 73
 +
          Caption = 'First Name'
 +
          Font.Height = -13
 +
          Font.Name = 'Sans'
 +
          Font.Style = [fsItalic]
 +
          ParentColor = False
 +
          ParentFont = False
 +
        end
 +
        object DBEdit1: TDBEdit
 +
          Left = 24
 +
          Height = 23
 +
          Hint = 'Cust name'
 +
          Top = 48
 +
          Width = 184
 +
          DataField = 'CustName'
 +
          DataSource = dsCust
 +
          ReadOnly = True
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 0
 +
        end
 +
        object DBEdit3: TDBEdit
 +
          Left = 24
 +
          Height = 23
 +
          Hint = 'Address'
 +
          Top = 72
 +
          Width = 184
 +
          DataField = 'Addr'
 +
          DataSource = dsCust
 +
          ReadOnly = True
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 1
 +
        end
 +
        object DBEdit4: TDBEdit
 +
          Left = 24
 +
          Height = 23
 +
          Hint = 'Suburb/Town'
 +
          Top = 96
 +
          Width = 184
 +
          DataField = 'Suburb'
 +
          DataSource = dsCust
 +
          ReadOnly = True
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 2
 +
        end
 +
        object DBEdit5: TDBEdit
 +
          Left = 24
 +
          Height = 23
 +
          Hint = 'Postal Code'
 +
          Top = 120
 +
          Width = 80
 +
          DataField = 'postCode'
 +
          DataSource = dsCust
 +
          ReadOnly = True
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 3
 +
        end
 +
        object DBEdit6: TDBEdit
 +
          Left = 128
 +
          Height = 23
 +
          Hint = 'State'
 +
          Top = 119
 +
          Width = 80
 +
          DataField = 'custState'
 +
          DataSource = dsCust
 +
          ReadOnly = True
 +
          CharCase = ecUppercase
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 4
 +
        end
 +
        object btnSelCust: TButton
 +
          Left = 24
 +
          Height = 25
 +
          Hint = 'Click to select a Customer'
 +
          Top = 176
 +
          Width = 184
 +
          Caption = 'Select Customer'
 +
          OnClick = btnSelCustClick
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 5
 +
        end
 +
        object DBNavigator3: TDBNavigator
 +
          Left = 30
 +
          Height = 22
 +
          Top = 150
 +
          Width = 170
 +
          BevelOuter = bvNone
 +
          ClientHeight = 22
 +
          ClientWidth = 170
 +
          DataSource = dsCust
 +
          TabOrder = 6
 +
          VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]
 +
        end
 +
      end
 +
      object pnlSales: TPanel
 +
        Left = 255
 +
        Height = 216
 +
        Top = 14
 +
        Width = 260
 +
        BevelInner = bvLowered
 +
        BevelWidth = 2
 +
        ClientHeight = 216
 +
        ClientWidth = 260
 +
        TabOrder = 1
 +
        object Label4: TLabel
 +
          Left = 4
 +
          Height = 18
 +
          Top = 4
 +
          Width = 252
 +
          Align = alTop
 +
          Alignment = taCenter
 +
          Caption = 'Sales Detail'
 +
          Font.Height = -13
 +
          Font.Name = 'Sans'
 +
          Font.Style = [fsBold, fsItalic]
 +
          ParentColor = False
 +
          ParentFont = False
 +
        end
 +
        object btnAddSale: TButton
 +
          Left = 16
 +
          Height = 25
 +
          Hint = 'Add Another Sale'
 +
          Top = 176
 +
          Width = 72
 +
          Caption = 'Add Sale'
 +
          OnClick = btnAddSaleClick
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 0
 +
        end
 +
        object Panel1: TPanel
 +
          Left = 4
 +
          Height = 13
 +
          Top = 22
 +
          Width = 252
 +
          Align = alTop
 +
          BevelOuter = bvNone
 +
          TabOrder = 1
 +
        end
 +
        object dgSales: TDBGrid
 +
          Left = 4
 +
          Height = 125
 +
          Hint = 'Click Item Number Button to Select Item'
 +
          Top = 35
 +
          Width = 252
 +
          Align = alTop
 +
          Columns = <         
 +
            item
 +
              ButtonStyle = cbsEllipsis
 +
              Title.Caption = 'item Number'
 +
              Width = 100
 +
              FieldName = 'itemNum'
 +
            end         
 +
            item
 +
              Width = 150
 +
              FieldName = 'item'
 +
            end         
 +
            item
 +
              FieldName = 'price'
 +
            end         
 +
            item
 +
              Title.Caption = 'sale Date'
 +
              FieldName = 'saleDate'
 +
            end         
 +
            item
 +
              Title.Caption = 'ship Date'
 +
              FieldName = 'shipDate'
 +
            end>
 +
          DataSource = dsSales
 +
          ShowHint = True
 +
          TabOrder = 2
 +
          TitleFont.Height = -13
 +
          TitleFont.Name = 'Sans'
 +
          OnEditButtonClick = dgSalesEditButtonClick
 +
        end
 +
        object btnSaveEntry: TButton
 +
          Left = 95
 +
          Height = 25
 +
          Hint = 'Save Entry'
 +
          Top = 176
 +
          Width = 51
 +
          Caption = 'Save'
 +
          OnClick = btnSaveEntryClick
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 3
 +
        end
 +
        object btnDelEntry: TButton
 +
          Left = 168
 +
          Height = 25
 +
          Hint = 'Delete Entry'
 +
          Top = 176
 +
          Width = 75
 +
          Caption = 'Delete'
 +
          OnClick = btnDelEntryClick
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 4
 +
        end
 +
      end
 +
    end
 +
    object pCustomer: TPage
 +
      Caption = 'Customer'
 +
      ClientWidth = 532
 +
      ClientHeight = 259
 +
      object pnlCustomer: TPanel
 +
        Left = 95
 +
        Height = 194
 +
        Top = 30
 +
        Width = 339
 +
        BevelInner = bvLowered
 +
        BevelWidth = 2
 +
        ClientHeight = 194
 +
        ClientWidth = 339
 +
        TabOrder = 0
 +
        object Label5: TLabel
 +
          Left = 72
 +
          Height = 18
 +
          Top = 31
 +
          Width = 73
 +
          Caption = 'First Name'
 +
          Font.Height = -13
 +
          Font.Name = 'Sans'
 +
          Font.Style = [fsItalic]
 +
          ParentColor = False
 +
          ParentFont = False
 +
        end
 +
        object Label7: TLabel
 +
          Left = 4
 +
          Height = 18
 +
          Top = 4
 +
          Width = 331
 +
          Align = alTop
 +
          Alignment = taCenter
 +
          Caption = 'Customer Entry'
 +
          Font.Height = -13
 +
          Font.Name = 'Sans'
 +
          Font.Style = [fsBold, fsItalic]
 +
          ParentColor = False
 +
          ParentFont = False
 +
        end
 +
        object DBEdit10: TDBEdit
 +
          Left = 72
 +
          Height = 23
 +
          Hint = 'Cust name'
 +
          Top = 48
 +
          Width = 184
 +
          DataField = 'CustName'
 +
          DataSource = dsCust
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 0
 +
        end
 +
        object DBEdit12: TDBEdit
 +
          Left = 72
 +
          Height = 23
 +
          Hint = 'Address'
 +
          Top = 72
 +
          Width = 184
 +
          DataField = 'Addr'
 +
          DataSource = dsCust
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 1
 +
        end
 +
        object DBEdit13: TDBEdit
 +
          Left = 72
 +
          Height = 23
 +
          Hint = 'Suburb/Town'
 +
          Top = 96
 +
          Width = 184
 +
          DataField = 'Suburb'
 +
          DataSource = dsCust
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 2
 +
        end
 +
        object DBEdit14: TDBEdit
 +
          Left = 72
 +
          Height = 23
 +
          Hint = 'Postal Code'
 +
          Top = 120
 +
          Width = 80
 +
          DataField = 'postCode'
 +
          DataSource = dsCust
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 3
 +
        end
 +
        object DBEdit15: TDBEdit
 +
          Left = 176
 +
          Height = 23
 +
          Hint = 'State'
 +
          Top = 119
 +
          Width = 80
 +
          DataField = 'custState'
 +
          DataSource = dsCust
 +
          CharCase = ecUppercase
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 4
 +
        end
 +
        object DBNavigator2: TDBNavigator
 +
          Left = 45
 +
          Height = 25
 +
          Top = 154
 +
          Width = 241
 +
          BevelOuter = bvNone
 +
          ClientHeight = 25
 +
          ClientWidth = 241
 +
          DataSource = dsCust
 +
          TabOrder = 5
 +
        end
 +
      end
 +
    end
 +
    object pStock: TPage
 +
      Caption = 'Stock'
 +
      ClientWidth = 532
 +
      ClientHeight = 259
 +
      object pnlStock: TPanel
 +
        Left = 95
 +
        Height = 218
 +
        Top = 22
 +
        Width = 339
 +
        BevelInner = bvLowered
 +
        BevelWidth = 2
 +
        ClientHeight = 218
 +
        ClientWidth = 339
 +
        TabOrder = 0
 +
        object Label8: TLabel
 +
          Left = 4
 +
          Height = 18
 +
          Top = 4
 +
          Width = 331
 +
          Align = alTop
 +
          Alignment = taCenter
 +
          Caption = 'Stock Entry'
 +
          Font.Height = -13
 +
          Font.Name = 'Sans'
 +
          Font.Style = [fsBold, fsItalic]
 +
          ParentColor = False
 +
          ParentFont = False
 +
        end
 +
        object Label9: TLabel
 +
          Left = 75
 +
          Height = 18
 +
          Top = 24
 +
          Width = 83
 +
          Caption = 'Part Number'
 +
          Font.Height = -13
 +
          Font.Name = 'Sans'
 +
          Font.Style = [fsItalic]
 +
          ParentColor = False
 +
          ParentFont = False
 +
        end
 +
        object Label10: TLabel
 +
          Left = 75
 +
          Height = 18
 +
          Top = 72
 +
          Width = 75
 +
          Caption = 'Description'
 +
          Font.Height = -13
 +
          Font.Name = 'Sans'
 +
          Font.Style = [fsItalic]
 +
          ParentColor = False
 +
          ParentFont = False
 +
        end
 +
        object Label11: TLabel
 +
          Left = 75
 +
          Height = 18
 +
          Top = 128
 +
          Width = 33
 +
          Caption = 'Price'
 +
          Font.Height = -13
 +
          Font.Name = 'Sans'
 +
          Font.Style = [fsItalic]
 +
          ParentColor = False
 +
          ParentFont = False
 +
        end
 +
        object DBEdit7: TDBEdit
 +
          Left = 75
 +
          Height = 23
 +
          Top = 40
 +
          Width = 181
 +
          DataField = 'itemNum'
 +
          DataSource = dsStock
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 0
 +
        end
 +
        object DBEdit8: TDBEdit
 +
          Left = 75
 +
          Height = 23
 +
          Top = 89
 +
          Width = 181
 +
          DataField = 'item'
 +
          DataSource = dsStock
 +
          MaxLength = 8192
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 1
 +
        end
 +
        object DBEdit9: TDBEdit
 +
          Left = 75
 +
          Height = 23
 +
          Top = 145
 +
          Width = 181
 +
          DataField = 'price'
 +
          DataSource = dsStock
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 2
 +
        end
 +
        object DBNavigator1: TDBNavigator
 +
          Left = 48
 +
          Height = 25
 +
          Top = 183
 +
          Width = 241
 +
          BevelOuter = bvNone
 +
          ClientHeight = 25
 +
          ClientWidth = 241
 +
          DataSource = dsStock
 +
          ParentShowHint = False
 +
          ShowHint = True
 +
          TabOrder = 3
 +
        end
 +
      end
 +
    end
 +
  end
 +
  object mmMain: TMainMenu
 +
    left = 16
 +
    top = 277
 +
    object miFile: TMenuItem
 +
      Caption = '&File'
 +
      object miClose: TMenuItem
 +
        Caption = '&Close'
 +
        Bitmap.Data = {
 +
          36040000424D3604000000000000360000002800000010000000100000000100
 +
          2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
 +
          FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF001D63
 +
          9B1619609839145D9562105A92880D5890A4135C92FC0C578FED999999FF7171
 +
          71FF545454FF515151FF4F4F4FFF4C4C4CFF4A4A4AFF474747FF454545FF2567
 +
          9DFF3274A8FF3D7CAFFF4784B5FF4E8ABAFF3E7EADFF0C578FEAFFFFFF00FFFF
 +
          FF00585858FFA2A2A2FFA2A2A2FFA3A3A3FFA4A4A4FFA4A4A4FFA5A5A5FF2F6F
 +
          A5FF78ABD2FF78ABD3FF73A7D1FF69A0CDFF407FAEFF0F5991EAFFFFFF00FFFF
 +
          FF005C5C5CFFA1A1A1FF3C7340FFA0A1A1FFA3A3A3FFA3A3A3FFA4A4A4FF3674
 +
          AAFF7DAFD4FF5B9AC9FF5495C7FF5896C8FF4180AEFF135C94EAFFFFFF00FFFF
 +
          FF00606060FFA0A0A0FF3D7641FF367139FFA2A2A2FFA2A2A2FFA3A3A3FF3D79
 +
          B0FF82B3D7FF629FCCFF5A9AC9FF5E9BCAFF4381AFFF196098EA37823EFF347E
 +
          3BFF317937FF2E7534FF499150FF468F4CFF39733DFFA1A1A1FFA2A2A2FF457E
 +
          B4FF88B7D9FF67A3CFFF619ECCFF639FCCFF4583B1FF1F649CEA3B8742FF89CB
 +
          92FF84C88DFF80C688FF7BC383FF77C17FFF478F4DFF3B743FFFA1A1A1FF4C84
 +
          BAFF8DBBDBFF6EA8D1FF66A6D1FF5FB4DFFF4785B1FF2569A1EA3E8B46FF8FCE
 +
          99FF7DC687FF78C381FF73C07CFF74C07CFF79C281FF49904FFF547F57FF5489
 +
          BFFF94BFDDFF75ADD4FF63B8E1FF4BD4FFFF428BB8FF2C6EA6EA41904AFF94D2
 +
          9FFF91D09AFF8DCD96FF89CB92FF84C88DFF519858FF417C46FF9F9F9FFF5A8E
 +
          C4FF98C3E0FF7CB3D7FF74AFD6FF5EC4EDFF4B88B3FF3473ABEA44944DFF4291
 +
          4BFF3F8D48FF3D8945FF5DA465FF5AA061FF45834BFF9E9E9EFF9E9E9EFF6092
 +
          C9FF9EC7E2FF83B8DAFF7DB4D7FF7EB3D7FF4F89B4FF3B79B1EAFFFFFF00FFFF
 +
          FF00777777FF9A9A9AFF3D8A45FF498A4FFF9C9C9CFF9D9D9DFF9D9D9DFF6696
 +
          CCFFA2CBE3FF89BDDCFF83B9DAFF84B9DAFF518BB5FF437EB6EAFFFFFF00FFFF
 +
          FF007A7A7AFF999999FF529159FF999A99FF9B9B9BFF9C9C9CFF9C9C9CFF6C9A
 +
          D0FFA7CEE5FF8FC1DFFF89BDDCFF8BBDDCFF538DB6FF4B84BCEAFFFFFF00FFFF
 +
          FF007D7D7DFF999999FF999999FF9A9A9AFF9A9A9AFF9B9B9BFF9B9B9BFF6F9D
 +
          D3FFAAD1E7FFABD1E7FF98C7E1FF91C2DEFF568FB7FF5289C1EAFFFFFF00FFFF
 +
          FF00808080FF7E7E7EFF7C7C7CFF7A7A7AFF777777FF757575FF727272FF719E
 +
          D4FF6F9ED6FF87B2DCFFABD3E8FFA9D0E6FF5890B8FF598EC6EAFFFFFF00FFFF
 +
          FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
 +
          FF00FFFFFF00709ED6DB6D9CD4FF85B1DAFF5A91B9FF6093CBEAFFFFFF00FFFF
 +
          FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
 +
          FF00FFFFFF00FFFFFF00FFFFFF006D9CD4896A9AD2FB6697CFEE
 +
        }
 +
        GlyphShowMode = gsmAlways
 +
        Hint = 'Close Application'
 +
        OnClick = miCloseClick
 +
      end
 +
    end
 +
  end
 +
  object dsCust: TDatasource
 +
    DataSet = TCust
 +
    left = 16
 +
    top = 53
 +
  end
 +
  object dsSales: TDatasource
 +
    DataSet = TSales
 +
    left = 16
 +
    top = 141
 +
  end
 +
  object dsStock: TDatasource
 +
    DataSet = TStock
 +
    left = 16
 +
    top = 214
 +
  end
 +
  object TCust: TSqlite3Dataset
 +
    AutoIncrementKey = True
 +
    Options = []
 +
    PrimaryKey = 'ID'
 +
    SaveOnClose = True
 +
    SaveOnRefetch = True
 +
    SQL = 'Select * from cust;'
 +
    TableName = 'cust'
 +
    FieldDefs = <   
 +
      item
 +
        Name = 'ID'
 +
        DataType = ftAutoInc
 +
        Precision = -1
 +
        Size = 0
 +
      end   
 +
      item
 +
        Name = 'CustName'
 +
        DataType = ftString
 +
        Precision = -1
 +
        Size = 8192
 +
      end   
 +
      item
 +
        Name = 'Addr'
 +
        DataType = ftString
 +
        Precision = -1
 +
        Size = 8192
 +
      end   
 +
      item
 +
        Name = 'Suburb'
 +
        DataType = ftString
 +
        Precision = -1
 +
        Size = 8192
 +
      end   
 +
      item
 +
        Name = 'postCode'
 +
        DataType = ftString
 +
        Precision = -1
 +
        Size = 8192
 +
      end   
 +
      item
 +
        Name = 'custState'
 +
        DataType = ftString
 +
        Precision = -1
 +
        Size = 8192
 +
      end>
 +
    left = 66
 +
    top = 53
 +
    object TCustID: TAutoIncField
 +
      DisplayWidth = 10
 +
      FieldKind = fkData
 +
      FieldName = 'ID'
 +
      Index = 0
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
    end
 +
    object TCustCustName: TStringField
 +
      DisplayWidth = 8192
 +
      FieldKind = fkData
 +
      FieldName = 'CustName'
 +
      Index = 1
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Size = 8192
 +
    end
 +
    object TCustAddr: TStringField
 +
      DisplayWidth = 8192
 +
      FieldKind = fkData
 +
      FieldName = 'Addr'
 +
      Index = 2
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Size = 8192
 +
    end
 +
    object TCustSuburb: TStringField
 +
      DisplayWidth = 8192
 +
      FieldKind = fkData
 +
      FieldName = 'Suburb'
 +
      Index = 3
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Size = 8192
 +
    end
 +
    object TCustpostCode: TStringField
 +
      DisplayWidth = 8192
 +
      FieldKind = fkData
 +
      FieldName = 'postCode'
 +
      Index = 4
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Size = 8192
 +
    end
 +
    object TCustcustState: TStringField
 +
      DisplayWidth = 8192
 +
      FieldKind = fkData
 +
      FieldName = 'custState'
 +
      Index = 5
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Size = 8192
 +
    end
 +
  end
 +
  object TSales: TSqlite3Dataset
 +
    AutoIncrementKey = True
 +
    IndexFieldNames = 'CustID'
 +
    Options = []
 +
    PrimaryKey = 'ID'
 +
    SaveOnClose = True
 +
    SaveOnRefetch = True
 +
    SQL = 'Select * from sales;'
 +
    TableName = 'sales'
 +
    MasterSource = dsCust
 +
    MasterFields = 'ID'
 +
    FieldDefs = <   
 +
      item
 +
        Name = 'itemNum'
 +
        DataType = ftString
 +
        Precision = -1
 +
        Size = 8192
 +
      end   
 +
      item
 +
        Name = 'ID'
 +
        DataType = ftAutoInc
 +
        Precision = -1
 +
        Size = 0
 +
      end   
 +
      item
 +
        Name = 'custID'
 +
        DataType = ftInteger
 +
        Precision = -1
 +
        Size = 0
 +
      end   
 +
      item
 +
        Name = 'saleDate'
 +
        DataType = ftDate
 +
        Precision = -1
 +
        Size = 0
 +
      end   
 +
      item
 +
        Name = 'shipDate'
 +
        DataType = ftDate
 +
        Precision = -1
 +
        Size = 0
 +
      end   
 +
      item
 +
        Name = 'item'
 +
        DataType = ftString
 +
        Precision = -1
 +
        Size = 8192
 +
      end   
 +
      item
 +
        Name = 'price'
 +
        DataType = ftFloat
 +
        Precision = -1
 +
        Size = 0
 +
      end>
 +
    left = 66
 +
    top = 141
 +
    object TSalesitemNum: TStringField
 +
      DisplayWidth = 8192
 +
      FieldKind = fkData
 +
      FieldName = 'itemNum'
 +
      Index = 0
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Size = 8192
 +
    end
 +
    object TSalesID: TAutoIncField
 +
      DisplayWidth = 10
 +
      FieldKind = fkData
 +
      FieldName = 'ID'
 +
      Index = 1
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
    end
 +
    object TSalescustID: TLongintField
 +
      DisplayWidth = 10
 +
      FieldKind = fkData
 +
      FieldName = 'custID'
 +
      Index = 2
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
    end
 +
    object TSalessaleDate: TDateField
 +
      DisplayWidth = 10
 +
      FieldKind = fkData
 +
      FieldName = 'saleDate'
 +
      Index = 3
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
    end
 +
    object TSalesshipDate: TDateField
 +
      DisplayWidth = 10
 +
      FieldKind = fkData
 +
      FieldName = 'shipDate'
 +
      Index = 4
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
    end
 +
    object TSalesitem: TStringField
 +
      DisplayWidth = 8192
 +
      FieldKind = fkData
 +
      FieldName = 'item'
 +
      Index = 5
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Size = 8192
 +
    end
 +
    object TSalesprice: TFloatField
 +
      DisplayWidth = 10
 +
      FieldKind = fkData
 +
      FieldName = 'price'
 +
      Index = 6
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Currency = True
 +
      MaxValue = 0
 +
      MinValue = 0
 +
      Precision = -1
 +
    end
 +
  end
 +
  object TStock: TSqlite3Dataset
 +
    AutoIncrementKey = True
 +
    Options = []
 +
    PrimaryKey = 'ID'
 +
    SaveOnClose = True
 +
    SaveOnRefetch = True
 +
    SQL = 'Select * from stock;'
 +
    TableName = 'stock'
 +
    FieldDefs = <   
 +
      item
 +
        Name = 'ID'
 +
        DataType = ftAutoInc
 +
        Precision = -1
 +
        Size = 0
 +
      end   
 +
      item
 +
        Name = 'item'
 +
        DataType = ftString
 +
        Precision = -1
 +
        Size = 8192
 +
      end   
 +
      item
 +
        Name = 'price'
 +
        DataType = ftFloat
 +
        Precision = -1
 +
        Size = 0
 +
      end   
 +
      item
 +
        Name = 'itemNum'
 +
        DataType = ftString
 +
        Precision = -1
 +
        Size = 8192
 +
      end>
 +
    left = 66
 +
    top = 214
 +
    object TStockID: TAutoIncField
 +
      DisplayWidth = 10
 +
      FieldKind = fkData
 +
      FieldName = 'ID'
 +
      Index = 0
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
    end
 +
    object TStockitem: TStringField
 +
      DisplayWidth = 8192
 +
      FieldKind = fkData
 +
      FieldName = 'item'
 +
      Index = 1
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Size = 8192
 +
    end
 +
    object TStockprice: TFloatField
 +
      DisplayWidth = 10
 +
      FieldKind = fkData
 +
      FieldName = 'price'
 +
      Index = 2
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Currency = True
 +
      MaxValue = 0
 +
      MinValue = 0
 +
      Precision = -1
 +
    end
 +
    object TStockitemNum: TStringField
 +
      DisplayWidth = 8192
 +
      FieldKind = fkData
 +
      FieldName = 'itemNum'
 +
      Index = 3
 +
      LookupCache = False
 +
      ProviderFlags = [pfInUpdate, pfInWhere]
 +
      ReadOnly = False
 +
      Required = False
 +
      Size = 8192
 +
    end
 +
  end
 +
end
  
 
unit uCust;
 
unit uCust;

Revision as of 01:50, 20 September 2009

TSqlite3 Master Detail Example

About Demo

This demo is a working example of how to use the TSqlite3 component in a master detail relationship.


Author

David Stewart .. davesimplewear at yahoo dot com


Components Used

  • TSqlite3
  • Standard Lazarus database components

Licence

  • Free to use as you will


Download

The TSQLite3 example can be downloaded from The Lazarus -ccr sf download location.


Screen shots of Example Program

Screenshot-Master Detail Example - SQLLite3.png

Screenshot-Master Detail Example - SQLLite3-1.png

Screenshot-Master Detail Example - SQLLite3-2.png

Screenshot-Select Customer Name.png

Screenshot-Select Item Number.png

This Screenshot shows the Table setting for master detail

Screenshot.png

Example Code

unit uMain;

{$mode objfpc}{$H+}

interface

uses

 Classes, SysUtils, db, sqlite3ds, FileUtil, LResources, Forms, Controls,
 Graphics, Dialogs, ComCtrls, ExtCtrls, Menus, DbCtrls, StdCtrls, DBGrids;

type

 { TfMain }
 TfMain = class(TForm)
   btnSelCust: TButton;
   btnAddSale: TButton;
   btnSaveEntry: TButton;
   btnDelEntry: TButton;
   DBNavigator3: TDBNavigator;
   dsCust: TDatasource;
   dsSales: TDatasource;
   dsStock: TDatasource;
   DBEdit1: TDBEdit;
   DBEdit10: TDBEdit;
   DBEdit12: TDBEdit;
   DBEdit13: TDBEdit;
   DBEdit14: TDBEdit;
   DBEdit15: TDBEdit;
   DBEdit3: TDBEdit;
   DBEdit4: TDBEdit;
   DBEdit5: TDBEdit;
   DBEdit6: TDBEdit;
   DBEdit7: TDBEdit;
   DBEdit8: TDBEdit;
   DBEdit9: TDBEdit;
   dgSales: TDBGrid;
   DBNavigator1: TDBNavigator;
   DBNavigator2: TDBNavigator;
   Label1: TLabel;
   Label10: TLabel;
   Label11: TLabel;
   Label2: TLabel;
   Label3: TLabel;
   Label4: TLabel;
   Label5: TLabel;
   Label7: TLabel;
   Label8: TLabel;
   Label9: TLabel;
   miClose: TMenuItem;
   miFile: TMenuItem;
   mmMain: TMainMenu;
   nbMain: TNotebook;
   Panel1: TPanel;
   pnlSales: TPanel;
   pnlStock: TPanel;
   pnlCustomer: TPanel;
   pnlSelectCust: TPanel;
   pStock: TPage;
   pCustomer: TPage;
   pSales: TPage;
   sbMain: TStatusBar;
   TCustAddr: TStringField;
   TCustCustName: TStringField;
   TCustcustState: TStringField;
   TCustID: TAutoIncField;
   TCustpostCode: TStringField;
   TCustSuburb: TStringField;
   TSalescustID: TLongintField;
   TSalesID: TAutoIncField;
   TSalesitem: TStringField;
   TSalesitemNum: TStringField;
   TSalesprice: TFloatField;
   TSalessaleDate: TDateField;
   TSalesshipDate: TDateField;
   TStock: TSqlite3Dataset;
   TSales: TSqlite3Dataset;
   TCust: TSqlite3Dataset;
   TStockID: TAutoIncField;
   TStockitem: TStringField;
   TStockitemNum: TStringField;
   TStockprice: TFloatField;
   procedure btnAddSaleClick(Sender: TObject);
   procedure btnDelEntryClick(Sender: TObject);
   procedure btnSaveEntryClick(Sender: TObject);
   procedure btnSelCustClick(Sender: TObject);
   procedure dgSalesEditButtonClick(Sender: TObject);
   procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
   procedure FormCreate(Sender: TObject);
   procedure FormDestroy(Sender: TObject);
   procedure FormShow(Sender: TObject);
   procedure miCloseClick(Sender: TObject);
   private
   { private declarations }
 public
   { public declarations }
 end; 

var

 fMain: TfMain;

implementation uses uCust, uSales; { TfMain }

procedure TfMain.miCloseClick(Sender: TObject); begin

 Close;

end;

procedure TfMain.FormCloseQuery(Sender: TObject; var CanClose: boolean); begin

  CanClose := MessageDlg('Are You Sure ?',mtConfirmation,[mbYes,mbNo],0)=mrYes;

end;

procedure TfMain.FormCreate(Sender: TObject); var n:integer; c:TComponent; FName:string; begin

   fName := ExtractFilePath(ParamStr(0)) +'data/md.db3';

for n := 0 to ComponentCount -1 do

   begin
    c := Components[n];
    if c is TSqlite3Dataset then
    TSqlite3Dataset(c).FileName:= fName;
   end;
for n := 0 to ComponentCount -1 do
   begin
    c := Components[n];
    if c is TSqlite3Dataset then
    TSqlite3Dataset(c).Open;
   end;

end;

procedure TfMain.FormDestroy(Sender: TObject); var n:integer; c:TComponent; begin

 for n := 0 to ComponentCount -1 do
   begin
    c := Components[n];
    if c is TSqlite3Dataset then
    TSqlite3Dataset(c).Close;
   end;

end;

procedure TfMain.FormShow(Sender: TObject); begin

 nbMain.PageIndex:=0;

end;

procedure TfMain.dgSalesEditButtonClick(Sender: TObject); begin

 if SearchDlg.ShowModalParts =mrOk then
    begin
      TSales.Edit;
      TSalesItemNum.Value := SearchDlg.PartNum;
      TSalesItem.Value := TStockitem.Value;
      TSalesPRICE.Value:= TStockPrice.Value;
    end;

end;

procedure TfMain.btnSelCustClick(Sender: TObject); begin

 custDlg.CustName := TCustCUSTNAME.Value ;
    if CustDlg.ShowModalCust =mrOk then
    begin
      TCust.Edit;
      TCustCUSTNAME.Value := custDlg.CustName;
   end;

end;

procedure TfMain.btnAddSaleClick(Sender: TObject); begin

 TSales.Append;

end;

procedure TfMain.btnDelEntryClick(Sender: TObject); begin

 TSales.Delete;

end;

procedure TfMain.btnSaveEntryClick(Sender: TObject); begin

 TSales.ApplyUpdates;

end;

initialization

 {$I uMain.lrs}

end.

object fMain: TfMain

 Left = 395
 Height = 332
 Top = 218
 Width = 534
 ActiveControl = nbMain
 BorderIcons = [biSystemMenu, biMinimize]
 BorderStyle = bsSingle
 Caption = 'Master Detail Example - SQLLite3'
 ClientHeight = 305
 ClientWidth = 534
 Font.Height = -13
 Font.Name = 'Sans'
 Menu = mmMain
 OnCloseQuery = FormCloseQuery
 OnCreate = FormCreate
 OnDestroy = FormDestroy
 OnShow = FormShow
 Position = poScreenCenter
 LCLVersion = '0.9.27'
 object sbMain: TStatusBar
   Left = 0
   Height = 19
   Top = 286
   Width = 534
   AutoHint = True
   Panels = <>
 end
 object nbMain: TNotebook
   Left = 0
   Height = 286
   Top = 0
   Width = 534
   Align = alClient
   PageIndex = 0
   TabOrder = 1
   object pSales: TPage
     Caption = 'Sales'
     ClientWidth = 532
     ClientHeight = 259
     object Label3: TLabel
       Left = 0
       Height = 18
       Top = 241
       Width = 532
       Align = alBottom
       Caption = 'Select Customer First, then click in item number field to select item, then save'
       ParentColor = False
     end
     object pnlSelectCust: TPanel
       Left = 15
       Height = 216
       Top = 14
       Width = 232
       BevelInner = bvLowered
       BevelWidth = 2
       ClientHeight = 216
       ClientWidth = 232
       TabOrder = 0
       object Label1: TLabel
         Left = 4
         Height = 18
         Top = 4
         Width = 224
         Align = alTop
         Alignment = taCenter
         Caption = 'Customer Detail'
         Font.Height = -13
         Font.Name = 'Sans'
         Font.Style = [fsBold, fsItalic]
         ParentColor = False
         ParentFont = False
       end
       object Label2: TLabel
         Left = 24
         Height = 18
         Top = 31
         Width = 73
         Caption = 'First Name'
         Font.Height = -13
         Font.Name = 'Sans'
         Font.Style = [fsItalic]
         ParentColor = False
         ParentFont = False
       end
       object DBEdit1: TDBEdit
         Left = 24
         Height = 23
         Hint = 'Cust name'
         Top = 48
         Width = 184
         DataField = 'CustName'
         DataSource = dsCust
         ReadOnly = True
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 0
       end
       object DBEdit3: TDBEdit
         Left = 24
         Height = 23
         Hint = 'Address'
         Top = 72
         Width = 184
         DataField = 'Addr'
         DataSource = dsCust
         ReadOnly = True
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 1
       end
       object DBEdit4: TDBEdit
         Left = 24
         Height = 23
         Hint = 'Suburb/Town'
         Top = 96
         Width = 184
         DataField = 'Suburb'
         DataSource = dsCust
         ReadOnly = True
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 2
       end
       object DBEdit5: TDBEdit
         Left = 24
         Height = 23
         Hint = 'Postal Code'
         Top = 120
         Width = 80
         DataField = 'postCode'
         DataSource = dsCust
         ReadOnly = True
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 3
       end
       object DBEdit6: TDBEdit
         Left = 128
         Height = 23
         Hint = 'State'
         Top = 119
         Width = 80
         DataField = 'custState'
         DataSource = dsCust
         ReadOnly = True
         CharCase = ecUppercase
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 4
       end
       object btnSelCust: TButton
         Left = 24
         Height = 25
         Hint = 'Click to select a Customer'
         Top = 176
         Width = 184
         Caption = 'Select Customer'
         OnClick = btnSelCustClick
         ParentShowHint = False
         ShowHint = True
         TabOrder = 5
       end
       object DBNavigator3: TDBNavigator
         Left = 30
         Height = 22
         Top = 150
         Width = 170
         BevelOuter = bvNone
         ClientHeight = 22
         ClientWidth = 170
         DataSource = dsCust
         TabOrder = 6
         VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]
       end
     end
     object pnlSales: TPanel
       Left = 255
       Height = 216
       Top = 14
       Width = 260
       BevelInner = bvLowered
       BevelWidth = 2
       ClientHeight = 216
       ClientWidth = 260
       TabOrder = 1
       object Label4: TLabel
         Left = 4
         Height = 18
         Top = 4
         Width = 252
         Align = alTop
         Alignment = taCenter
         Caption = 'Sales Detail'
         Font.Height = -13
         Font.Name = 'Sans'
         Font.Style = [fsBold, fsItalic]
         ParentColor = False
         ParentFont = False
       end
       object btnAddSale: TButton
         Left = 16
         Height = 25
         Hint = 'Add Another Sale'
         Top = 176
         Width = 72
         Caption = 'Add Sale'
         OnClick = btnAddSaleClick
         ParentShowHint = False
         ShowHint = True
         TabOrder = 0
       end
       object Panel1: TPanel
         Left = 4
         Height = 13
         Top = 22
         Width = 252
         Align = alTop
         BevelOuter = bvNone
         TabOrder = 1
       end
       object dgSales: TDBGrid
         Left = 4
         Height = 125
         Hint = 'Click Item Number Button to Select Item'
         Top = 35
         Width = 252
         Align = alTop
         Columns = <          
           item
             ButtonStyle = cbsEllipsis
             Title.Caption = 'item Number'
             Width = 100
             FieldName = 'itemNum'
           end          
           item
             Width = 150
             FieldName = 'item'
           end          
           item
             FieldName = 'price'
           end          
           item
             Title.Caption = 'sale Date'
             FieldName = 'saleDate'
           end          
           item
             Title.Caption = 'ship Date'
             FieldName = 'shipDate'
           end>
         DataSource = dsSales
         ShowHint = True
         TabOrder = 2
         TitleFont.Height = -13
         TitleFont.Name = 'Sans'
         OnEditButtonClick = dgSalesEditButtonClick
       end
       object btnSaveEntry: TButton
         Left = 95
         Height = 25
         Hint = 'Save Entry'
         Top = 176
         Width = 51
         Caption = 'Save'
         OnClick = btnSaveEntryClick
         ParentShowHint = False
         ShowHint = True
         TabOrder = 3
       end
       object btnDelEntry: TButton
         Left = 168
         Height = 25
         Hint = 'Delete Entry'
         Top = 176
         Width = 75
         Caption = 'Delete'
         OnClick = btnDelEntryClick
         ParentShowHint = False
         ShowHint = True
         TabOrder = 4
       end
     end
   end
   object pCustomer: TPage
     Caption = 'Customer'
     ClientWidth = 532
     ClientHeight = 259
     object pnlCustomer: TPanel
       Left = 95
       Height = 194
       Top = 30
       Width = 339
       BevelInner = bvLowered
       BevelWidth = 2
       ClientHeight = 194
       ClientWidth = 339
       TabOrder = 0
       object Label5: TLabel
         Left = 72
         Height = 18
         Top = 31
         Width = 73
         Caption = 'First Name'
         Font.Height = -13
         Font.Name = 'Sans'
         Font.Style = [fsItalic]
         ParentColor = False
         ParentFont = False
       end
       object Label7: TLabel
         Left = 4
         Height = 18
         Top = 4
         Width = 331
         Align = alTop
         Alignment = taCenter
         Caption = 'Customer Entry'
         Font.Height = -13
         Font.Name = 'Sans'
         Font.Style = [fsBold, fsItalic]
         ParentColor = False
         ParentFont = False
       end
       object DBEdit10: TDBEdit
         Left = 72
         Height = 23
         Hint = 'Cust name'
         Top = 48
         Width = 184
         DataField = 'CustName'
         DataSource = dsCust
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 0
       end
       object DBEdit12: TDBEdit
         Left = 72
         Height = 23
         Hint = 'Address'
         Top = 72
         Width = 184
         DataField = 'Addr'
         DataSource = dsCust
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 1
       end
       object DBEdit13: TDBEdit
         Left = 72
         Height = 23
         Hint = 'Suburb/Town'
         Top = 96
         Width = 184
         DataField = 'Suburb'
         DataSource = dsCust
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 2
       end
       object DBEdit14: TDBEdit
         Left = 72
         Height = 23
         Hint = 'Postal Code'
         Top = 120
         Width = 80
         DataField = 'postCode'
         DataSource = dsCust
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 3
       end
       object DBEdit15: TDBEdit
         Left = 176
         Height = 23
         Hint = 'State'
         Top = 119
         Width = 80
         DataField = 'custState'
         DataSource = dsCust
         CharCase = ecUppercase
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 4
       end
       object DBNavigator2: TDBNavigator
         Left = 45
         Height = 25
         Top = 154
         Width = 241
         BevelOuter = bvNone
         ClientHeight = 25
         ClientWidth = 241
         DataSource = dsCust
         TabOrder = 5
       end
     end
   end
   object pStock: TPage
     Caption = 'Stock'
     ClientWidth = 532
     ClientHeight = 259
     object pnlStock: TPanel
       Left = 95
       Height = 218
       Top = 22
       Width = 339
       BevelInner = bvLowered
       BevelWidth = 2
       ClientHeight = 218
       ClientWidth = 339
       TabOrder = 0
       object Label8: TLabel
         Left = 4
         Height = 18
         Top = 4
         Width = 331
         Align = alTop
         Alignment = taCenter
         Caption = 'Stock Entry'
         Font.Height = -13
         Font.Name = 'Sans'
         Font.Style = [fsBold, fsItalic]
         ParentColor = False
         ParentFont = False
       end
       object Label9: TLabel
         Left = 75
         Height = 18
         Top = 24
         Width = 83
         Caption = 'Part Number'
         Font.Height = -13
         Font.Name = 'Sans'
         Font.Style = [fsItalic]
         ParentColor = False
         ParentFont = False
       end
       object Label10: TLabel
         Left = 75
         Height = 18
         Top = 72
         Width = 75
         Caption = 'Description'
         Font.Height = -13
         Font.Name = 'Sans'
         Font.Style = [fsItalic]
         ParentColor = False
         ParentFont = False
       end
       object Label11: TLabel
         Left = 75
         Height = 18
         Top = 128
         Width = 33
         Caption = 'Price'
         Font.Height = -13
         Font.Name = 'Sans'
         Font.Style = [fsItalic]
         ParentColor = False
         ParentFont = False
       end
       object DBEdit7: TDBEdit
         Left = 75
         Height = 23
         Top = 40
         Width = 181
         DataField = 'itemNum'
         DataSource = dsStock
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 0
       end
       object DBEdit8: TDBEdit
         Left = 75
         Height = 23
         Top = 89
         Width = 181
         DataField = 'item'
         DataSource = dsStock
         MaxLength = 8192
         ParentShowHint = False
         ShowHint = True
         TabOrder = 1
       end
       object DBEdit9: TDBEdit
         Left = 75
         Height = 23
         Top = 145
         Width = 181
         DataField = 'price'
         DataSource = dsStock
         ParentShowHint = False
         ShowHint = True
         TabOrder = 2
       end
       object DBNavigator1: TDBNavigator
         Left = 48
         Height = 25
         Top = 183
         Width = 241
         BevelOuter = bvNone
         ClientHeight = 25
         ClientWidth = 241
         DataSource = dsStock
         ParentShowHint = False
         ShowHint = True
         TabOrder = 3
       end
     end
   end
 end
 object mmMain: TMainMenu
   left = 16
   top = 277
   object miFile: TMenuItem
     Caption = '&File'
     object miClose: TMenuItem
       Caption = '&Close'
       Bitmap.Data = {
         36040000424D3604000000000000360000002800000010000000100000000100
         2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
         FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF001D63
         9B1619609839145D9562105A92880D5890A4135C92FC0C578FED999999FF7171
         71FF545454FF515151FF4F4F4FFF4C4C4CFF4A4A4AFF474747FF454545FF2567
         9DFF3274A8FF3D7CAFFF4784B5FF4E8ABAFF3E7EADFF0C578FEAFFFFFF00FFFF
         FF00585858FFA2A2A2FFA2A2A2FFA3A3A3FFA4A4A4FFA4A4A4FFA5A5A5FF2F6F
         A5FF78ABD2FF78ABD3FF73A7D1FF69A0CDFF407FAEFF0F5991EAFFFFFF00FFFF
         FF005C5C5CFFA1A1A1FF3C7340FFA0A1A1FFA3A3A3FFA3A3A3FFA4A4A4FF3674
         AAFF7DAFD4FF5B9AC9FF5495C7FF5896C8FF4180AEFF135C94EAFFFFFF00FFFF
         FF00606060FFA0A0A0FF3D7641FF367139FFA2A2A2FFA2A2A2FFA3A3A3FF3D79
         B0FF82B3D7FF629FCCFF5A9AC9FF5E9BCAFF4381AFFF196098EA37823EFF347E
         3BFF317937FF2E7534FF499150FF468F4CFF39733DFFA1A1A1FFA2A2A2FF457E
         B4FF88B7D9FF67A3CFFF619ECCFF639FCCFF4583B1FF1F649CEA3B8742FF89CB
         92FF84C88DFF80C688FF7BC383FF77C17FFF478F4DFF3B743FFFA1A1A1FF4C84
         BAFF8DBBDBFF6EA8D1FF66A6D1FF5FB4DFFF4785B1FF2569A1EA3E8B46FF8FCE
         99FF7DC687FF78C381FF73C07CFF74C07CFF79C281FF49904FFF547F57FF5489
         BFFF94BFDDFF75ADD4FF63B8E1FF4BD4FFFF428BB8FF2C6EA6EA41904AFF94D2
         9FFF91D09AFF8DCD96FF89CB92FF84C88DFF519858FF417C46FF9F9F9FFF5A8E
         C4FF98C3E0FF7CB3D7FF74AFD6FF5EC4EDFF4B88B3FF3473ABEA44944DFF4291
         4BFF3F8D48FF3D8945FF5DA465FF5AA061FF45834BFF9E9E9EFF9E9E9EFF6092
         C9FF9EC7E2FF83B8DAFF7DB4D7FF7EB3D7FF4F89B4FF3B79B1EAFFFFFF00FFFF
         FF00777777FF9A9A9AFF3D8A45FF498A4FFF9C9C9CFF9D9D9DFF9D9D9DFF6696
         CCFFA2CBE3FF89BDDCFF83B9DAFF84B9DAFF518BB5FF437EB6EAFFFFFF00FFFF
         FF007A7A7AFF999999FF529159FF999A99FF9B9B9BFF9C9C9CFF9C9C9CFF6C9A
         D0FFA7CEE5FF8FC1DFFF89BDDCFF8BBDDCFF538DB6FF4B84BCEAFFFFFF00FFFF
         FF007D7D7DFF999999FF999999FF9A9A9AFF9A9A9AFF9B9B9BFF9B9B9BFF6F9D
         D3FFAAD1E7FFABD1E7FF98C7E1FF91C2DEFF568FB7FF5289C1EAFFFFFF00FFFF
         FF00808080FF7E7E7EFF7C7C7CFF7A7A7AFF777777FF757575FF727272FF719E
         D4FF6F9ED6FF87B2DCFFABD3E8FFA9D0E6FF5890B8FF598EC6EAFFFFFF00FFFF
         FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
         FF00FFFFFF00709ED6DB6D9CD4FF85B1DAFF5A91B9FF6093CBEAFFFFFF00FFFF
         FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
         FF00FFFFFF00FFFFFF00FFFFFF006D9CD4896A9AD2FB6697CFEE
       }
       GlyphShowMode = gsmAlways
       Hint = 'Close Application'
       OnClick = miCloseClick
     end
   end
 end
 object dsCust: TDatasource
   DataSet = TCust
   left = 16
   top = 53
 end
 object dsSales: TDatasource
   DataSet = TSales
   left = 16
   top = 141
 end
 object dsStock: TDatasource
   DataSet = TStock
   left = 16
   top = 214
 end
 object TCust: TSqlite3Dataset
   AutoIncrementKey = True
   Options = []
   PrimaryKey = 'ID'
   SaveOnClose = True
   SaveOnRefetch = True
   SQL = 'Select * from cust;'
   TableName = 'cust'
   FieldDefs = <    
     item
       Name = 'ID'
       DataType = ftAutoInc
       Precision = -1
       Size = 0
     end    
     item
       Name = 'CustName'
       DataType = ftString
       Precision = -1
       Size = 8192
     end    
     item
       Name = 'Addr'
       DataType = ftString
       Precision = -1
       Size = 8192
     end    
     item
       Name = 'Suburb'
       DataType = ftString
       Precision = -1
       Size = 8192
     end    
     item
       Name = 'postCode'
       DataType = ftString
       Precision = -1
       Size = 8192
     end    
     item
       Name = 'custState'
       DataType = ftString
       Precision = -1
       Size = 8192
     end>
   left = 66
   top = 53
   object TCustID: TAutoIncField
     DisplayWidth = 10
     FieldKind = fkData
     FieldName = 'ID'
     Index = 0
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
   end
   object TCustCustName: TStringField
     DisplayWidth = 8192
     FieldKind = fkData
     FieldName = 'CustName'
     Index = 1
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Size = 8192
   end
   object TCustAddr: TStringField
     DisplayWidth = 8192
     FieldKind = fkData
     FieldName = 'Addr'
     Index = 2
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Size = 8192
   end
   object TCustSuburb: TStringField
     DisplayWidth = 8192
     FieldKind = fkData
     FieldName = 'Suburb'
     Index = 3
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Size = 8192
   end
   object TCustpostCode: TStringField
     DisplayWidth = 8192
     FieldKind = fkData
     FieldName = 'postCode'
     Index = 4
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Size = 8192
   end
   object TCustcustState: TStringField
     DisplayWidth = 8192
     FieldKind = fkData
     FieldName = 'custState'
     Index = 5
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Size = 8192
   end
 end
 object TSales: TSqlite3Dataset
   AutoIncrementKey = True
   IndexFieldNames = 'CustID'
   Options = []
   PrimaryKey = 'ID'
   SaveOnClose = True
   SaveOnRefetch = True
   SQL = 'Select * from sales;'
   TableName = 'sales'
   MasterSource = dsCust
   MasterFields = 'ID'
   FieldDefs = <    
     item
       Name = 'itemNum'
       DataType = ftString
       Precision = -1
       Size = 8192
     end    
     item
       Name = 'ID'
       DataType = ftAutoInc
       Precision = -1
       Size = 0
     end    
     item
       Name = 'custID'
       DataType = ftInteger
       Precision = -1
       Size = 0
     end    
     item
       Name = 'saleDate'
       DataType = ftDate
       Precision = -1
       Size = 0
     end    
     item
       Name = 'shipDate'
       DataType = ftDate
       Precision = -1
       Size = 0
     end    
     item
       Name = 'item'
       DataType = ftString
       Precision = -1
       Size = 8192
     end    
     item
       Name = 'price'
       DataType = ftFloat
       Precision = -1
       Size = 0
     end>
   left = 66
   top = 141
   object TSalesitemNum: TStringField
     DisplayWidth = 8192
     FieldKind = fkData
     FieldName = 'itemNum'
     Index = 0
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Size = 8192
   end
   object TSalesID: TAutoIncField
     DisplayWidth = 10
     FieldKind = fkData
     FieldName = 'ID'
     Index = 1
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
   end
   object TSalescustID: TLongintField
     DisplayWidth = 10
     FieldKind = fkData
     FieldName = 'custID'
     Index = 2
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
   end
   object TSalessaleDate: TDateField
     DisplayWidth = 10
     FieldKind = fkData
     FieldName = 'saleDate'
     Index = 3
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
   end
   object TSalesshipDate: TDateField
     DisplayWidth = 10
     FieldKind = fkData
     FieldName = 'shipDate'
     Index = 4
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
   end
   object TSalesitem: TStringField
     DisplayWidth = 8192
     FieldKind = fkData
     FieldName = 'item'
     Index = 5
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Size = 8192
   end
   object TSalesprice: TFloatField
     DisplayWidth = 10
     FieldKind = fkData
     FieldName = 'price'
     Index = 6
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Currency = True
     MaxValue = 0
     MinValue = 0
     Precision = -1
   end
 end
 object TStock: TSqlite3Dataset
   AutoIncrementKey = True
   Options = []
   PrimaryKey = 'ID'
   SaveOnClose = True
   SaveOnRefetch = True
   SQL = 'Select * from stock;'
   TableName = 'stock'
   FieldDefs = <    
     item
       Name = 'ID'
       DataType = ftAutoInc
       Precision = -1
       Size = 0
     end    
     item
       Name = 'item'
       DataType = ftString
       Precision = -1
       Size = 8192
     end    
     item
       Name = 'price'
       DataType = ftFloat
       Precision = -1
       Size = 0
     end    
     item
       Name = 'itemNum'
       DataType = ftString
       Precision = -1
       Size = 8192
     end>
   left = 66
   top = 214
   object TStockID: TAutoIncField
     DisplayWidth = 10
     FieldKind = fkData
     FieldName = 'ID'
     Index = 0
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
   end
   object TStockitem: TStringField
     DisplayWidth = 8192
     FieldKind = fkData
     FieldName = 'item'
     Index = 1
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Size = 8192
   end
   object TStockprice: TFloatField
     DisplayWidth = 10
     FieldKind = fkData
     FieldName = 'price'
     Index = 2
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Currency = True
     MaxValue = 0
     MinValue = 0
     Precision = -1
   end
   object TStockitemNum: TStringField
     DisplayWidth = 8192
     FieldKind = fkData
     FieldName = 'itemNum'
     Index = 3
     LookupCache = False
     ProviderFlags = [pfInUpdate, pfInWhere]
     ReadOnly = False
     Required = False
     Size = 8192
   end
 end

end

unit uCust;

{$mode objfpc}{$H+}

interface

uses

 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
 StdCtrls, ExtCtrls, Buttons, DBGrids,DB;

type

 { TcustDlg }
 TcustDlg = class(TForm)
   cancelBtn: TButton;
   dgCust: TDBGrid;
   edSearch: TEdit;
   Label1: TLabel;
   okBtn: TButton;
   pnlCust: TPanel;
   sbSearch: TSpeedButton;
   procedure dgCustDblClick(Sender: TObject);
   procedure edSearchChange(Sender: TObject);
   procedure sbSearchClick(Sender: TObject);
 private
   function GetCust: String;
   procedure SetCust(const AValue: String);
   { private declarations }
 public
   { public declarations }
   property CustName: String Read GetCust Write SetCust;
   function ShowModalCust:integer;
 end; 

var

 custDlg: TcustDlg;

implementation uses uMain; { TcustDlg }

procedure TcustDlg.edSearchChange(Sender: TObject); begin

 sbSearch.Enabled:=edSearch.Text<>;

end;

procedure TcustDlg.dgCustDblClick(Sender: TObject); begin

 ModalResult := mrOk;

end;

procedure TcustDlg.sbSearchClick(Sender: TObject); begin

 if not fMain.TCust.Locate('CustName', edSearch.Text,[loCaseInsensitive, loPartialKey])
  then
     MessageDlg('No matching record found.', mtInformation, [mbOK], 0);
     edSearch.Color:=clRed;

end;

function TcustDlg.GetCust: String; begin

 Result := fMain.TCustCustName.Value;

end;

procedure TcustDlg.SetCust(const AValue: String); begin

 fMain.TCust.Locate('CustName',AValue,[loPartialKey,loCaseInsensitive]);

end;

function TcustDlg.ShowModalCust: integer; begin

 Caption:='Select Customer Name';
 Result := ShowModal;

end;

initialization

 {$I uCust.lrs}

end.

unit uSales;

{$mode objfpc}{$H+}

interface

uses

 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
 StdCtrls, ExtCtrls, Buttons, DBGrids, DB;

type

 { TsearchDlg }
 TsearchDlg = class(TForm)
   cancelBtn: TButton;
   dgParts: TDBGrid;
   edSearch: TEdit;
   Label1: TLabel;
   okBtn: TButton;
   pnlParts: TPanel;
   sbSearch: TSpeedButton;
   procedure dgPartsDblClick(Sender: TObject);
   procedure edSearchChange(Sender: TObject);
   procedure sbSearchClick(Sender: TObject);
 private
   function GetPartNum: String;
   procedure SetPartNum(const AValue: String);
   { private declarations }
 public
   { public declarations }
   property PartNum:String Read GetPartNum Write SetPartNum;
   function ShowModalParts: Integer;
 end; 

var

 searchDlg: TsearchDlg;

implementation uses uMain; { TsearchDlg }

procedure TsearchDlg.edSearchChange(Sender: TObject); begin

 sbSearch.Enabled:=edSearch.Text<>;

end;

procedure TsearchDlg.dgPartsDblClick(Sender: TObject); begin

 ModalResult := mrOk;

end;

procedure TsearchDlg.sbSearchClick(Sender: TObject); begin

 if not fMain.TStock.Locate('itemNum', edSearch.Text,[loCaseInsensitive, loPartialKey])
  then
     MessageDlg('No matching record found.', mtInformation, [mbOK], 0);
     edSearch.Color:=clRed;

end;

function TsearchDlg.GetPartNum: String; begin

 Result := fMain.TStockitemNum.Value;

end;

procedure TsearchDlg.SetPartNum(const AValue: String); begin

 fMain.TStock.Locate('itemNum',AValue,[loPartialKey,loCaseInsensitive]);

end;

function TsearchDlg.ShowModalParts: Integer; begin

 Caption:='Select Item Number';
 Result := ShowModal;

end;

initialization

 {$I uSales.lrs}

end.