Sign in Join
Wiki copytemporary

TSqlite3 Master Detail Example: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11TSqlite3 Master Detail Example
22
33## About Demo
44
55This demo is a working example of how to use the [[SQLite]] TSqlite3 dataset component in a master detail relationship.
66
77> **Note:** this component is not part of the general SQLDB database components. SQLDB provides TSQLite3Connection that match other databases connectors. You are strongly recommended to look into using TSQLite3Connection because of the ease of switching to other databases; only use TSQlite3 if it is really needed.
88
99See [[MasterDetail]] for instructions on how to implement master/detail relationships using standard sqldb (e.g. sqlite3) components.
1010
1111## Author
1212
1313David Stewart .. davesimplewear at yahoo dot com
1414
1515## Components Used
1616
1717- TSqlite3
1818- Standard Lazarus database components
1919
2020## Licence
2121
2222- Free to use as you will
2323
2424## Download
2525
2626The TSQLite3 example can be downloaded from [The Lazarus -ccr sf download location](http://sourceforge.net/projects/lazarus-ccr/files/Demos%20and%20examples/). Also from [David's Freeware](http://www.users.on.net/~dave.stewart/index.html).
2727
2828### Screen shots
2929
3030![](/wiki-images/b/b8/Screenshot-Master_Detail_Example_-_SQLLite3.png)
3131
3232![](/wiki-images/8/82/Screenshot-Master_Detail_Example_-_SQLLite3-1.png)
3333
3434![](/wiki-images/7/71/Screenshot-Master_Detail_Example_-_SQLLite3-2.png)
3535
3636![](/wiki-images/1/14/Screenshot-Select_Customer_Name.png)
3737
3838![](/wiki-images/2/2e/Screenshot-Select_Item_Number.png)
3939
4040This screenshot shows the table setting for master detail
4141
4242![](/wiki-images/e/e6/Screenshot.png)
4343
4444### Example program code
4545
4646``` pascal
4747unit uMain;
4848
4949{$mode objfpc}{$H+}
5050
5151interface
5252
5353uses
5454 Classes, SysUtils, db, sqlite3ds, FileUtil, LResources, Forms, Controls,
5555 Graphics, Dialogs, ComCtrls, ExtCtrls, Menus, DbCtrls, StdCtrls, DBGrids;
5656
5757type
5858
5959 { TfMain }
6060
6161 TfMain = class(TForm)
6262 btnSelCust: TButton;
6363 btnAddSale: TButton;
6464 btnSaveEntry: TButton;
6565 btnDelEntry: TButton;
6666 DBNavigator3: TDBNavigator;
6767 dsCust: TDatasource;
6868 dsSales: TDatasource;
6969 dsStock: TDatasource;
7070 DBEdit1: TDBEdit;
7171 DBEdit10: TDBEdit;
7272 DBEdit12: TDBEdit;
7373 DBEdit13: TDBEdit;
7474 DBEdit14: TDBEdit;
7575 DBEdit15: TDBEdit;
7676 DBEdit3: TDBEdit;
7777 DBEdit4: TDBEdit;
7878 DBEdit5: TDBEdit;
7979 DBEdit6: TDBEdit;
8080 DBEdit7: TDBEdit;
8181 DBEdit8: TDBEdit;
8282 DBEdit9: TDBEdit;
8383 dgSales: TDBGrid;
8484 DBNavigator1: TDBNavigator;
8585 DBNavigator2: TDBNavigator;
8686 Label1: TLabel;
8787 Label10: TLabel;
8888 Label11: TLabel;
8989 Label2: TLabel;
9090 Label3: TLabel;
9191 Label4: TLabel;
9292 Label5: TLabel;
9393 Label7: TLabel;
9494 Label8: TLabel;
9595 Label9: TLabel;
9696 miClose: TMenuItem;
9797 miFile: TMenuItem;
9898 mmMain: TMainMenu;
9999 nbMain: TNotebook;
100100 Panel1: TPanel;
101101 pnlSales: TPanel;
102102 pnlStock: TPanel;
103103 pnlCustomer: TPanel;
104104 pnlSelectCust: TPanel;
105105 pStock: TPage;
106106 pCustomer: TPage;
107107 pSales: TPage;
108108 sbMain: TStatusBar;
109109 TCustAddr: TStringField;
110110 TCustCustName: TStringField;
111111 TCustcustState: TStringField;
112112 TCustID: TAutoIncField;
113113 TCustpostCode: TStringField;
114114 TCustSuburb: TStringField;
115115 TSalescustID: TLongintField;
116116 TSalesID: TAutoIncField;
117117 TSalesitem: TStringField;
118118 TSalesitemNum: TStringField;
119119 TSalesprice: TFloatField;
120120 TSalessaleDate: TDateField;
121121 TSalesshipDate: TDateField;
122122 TStock: TSqlite3Dataset;
123123 TSales: TSqlite3Dataset;
124124 TCust: TSqlite3Dataset;
125125 TStockID: TAutoIncField;
126126 TStockitem: TStringField;
127127 TStockitemNum: TStringField;
128128 TStockprice: TFloatField;
129129 procedure btnAddSaleClick(Sender: TObject);
130130 procedure btnDelEntryClick(Sender: TObject);
131131 procedure btnSaveEntryClick(Sender: TObject);
132132 procedure btnSelCustClick(Sender: TObject);
133133 procedure dgSalesEditButtonClick(Sender: TObject);
134134 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
135135 procedure FormCreate(Sender: TObject);
136136 procedure FormDestroy(Sender: TObject);
137137 procedure FormShow(Sender: TObject);
138138 procedure miCloseClick(Sender: TObject);
139139 private
140140 { private declarations }
141141 public
142142 { public declarations }
143143 end;
144144
145145var
146146 fMain: TfMain;
147147
148148implementation
149149uses uCust, uSales;
150150{ TfMain }
151151
152152procedure TfMain.miCloseClick(Sender: TObject);
153153begin
154154 Close;
155155end;
156156
157157procedure TfMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
158158begin
159159 CanClose := MessageDlg('Are You Sure ?',mtConfirmation,[mbYes,mbNo],0)=mrYes;
160160end;
161161
162162procedure TfMain.FormCreate(Sender: TObject);
163163var
164164n:integer;
165165c:TComponent;
166166FName:string;
167167begin
168168 fName := ExtractFilePath(ParamStr(0)) +'data/md.db3';
169169for n := 0 to ComponentCount -1 do
170170 begin
171171 c := Components[n];
172172 if c is TSqlite3Dataset then
173173 TSqlite3Dataset(c).FileName:= fName;
174174 end;
175175 for n := 0 to ComponentCount -1 do
176176 begin
177177 c := Components[n];
178178 if c is TSqlite3Dataset then
179179 TSqlite3Dataset(c).Open;
180180 end;
181181end;
182182
183183procedure TfMain.FormDestroy(Sender: TObject);
184184var
185185n:integer;
186186c:TComponent;
187187begin
188188 for n := 0 to ComponentCount -1 do
189189 begin
190190 c := Components[n];
191191 if c is TSqlite3Dataset then
192192 TSqlite3Dataset(c).Close;
193193 end;
194194end;
195195
196196procedure TfMain.FormShow(Sender: TObject);
197197begin
198198 nbMain.PageIndex:=0;
199199end;
200200
201201procedure TfMain.dgSalesEditButtonClick(Sender: TObject);
202202begin
203203 if SearchDlg.ShowModalParts =mrOk then
204204 begin
205205 TSales.Edit;
206206 TSalesItemNum.Value := SearchDlg.PartNum;
207207 TSalesItem.Value := TStockitem.Value;
208208 TSalesPRICE.Value:= TStockPrice.Value;
209209 end;
210210end;
211211
212212procedure TfMain.btnSelCustClick(Sender: TObject);
213213begin
214214 custDlg.CustName := TCustCUSTNAME.Value ;
215215 if CustDlg.ShowModalCust =mrOk then
216216 begin
217217 TCust.Edit;
218218 TCustCUSTNAME.Value := custDlg.CustName;
219219 end;
220220end;
221221
222222procedure TfMain.btnAddSaleClick(Sender: TObject);
223223begin
224224 TSales.Append;
225225end;
226226
227227procedure TfMain.btnDelEntryClick(Sender: TObject);
228228begin
229229 TSales.Delete;
230230end;
231231
232232procedure TfMain.btnSaveEntryClick(Sender: TObject);
233233begin
234234 TSales.ApplyUpdates;
235235end;
236236
237237initialization
238238 {$I uMain.lrs}
239239
240240end.
241241```
242242
243-uMain.lfm (edited) object fMain: TfMain
244-
245-` Left = 395`\
246-` Height = 332`\
247-` Top = 218`\
248-` Width = 534`\
249-` ActiveControl = nbMain`\
250-` BorderIcons = [biSystemMenu, biMinimize]`\
251-` BorderStyle = bsSingle`\
252-` Caption = 'Master Detail Example - SQLLite3'`\
253-` ClientHeight = 305`\
254-` ClientWidth = 534`\
255-` Font.Height = -13`\
256-` Font.Name = 'Sans'`\
257-` Menu = mmMain`\
258-` OnCloseQuery = FormCloseQuery`\
259-` OnCreate = FormCreate`\
260-` OnDestroy = FormDestroy`\
261-` OnShow = FormShow`\
262-` Position = poScreenCenter`\
263-` LCLVersion = '0.9.27'`\
264-` object sbMain: TStatusBar`\
265-`   Left = 0`\
266-`   Height = 19`\
267-`   Top = 286`\
268-`   Width = 534`\
269-`   AutoHint = True`\
270-`   Panels = <>`\
271-` end`\
272-` object nbMain: TNotebook`\
273-`   Left = 0`\
274-`   Height = 286`\
275-`   Top = 0`\
276-`   Width = 534`\
277-`   Align = alClient`\
278-`   PageIndex = 0`\
279-`   TabOrder = 1`\
280-`   object pSales: TPage`\
281-`     Caption = 'Sales'`\
282-`     ClientWidth = 532`\
283-`     ClientHeight = 259`\
284-`     object Label3: TLabel`\
285-`       Left = 0`\
286-`       Height = 18`\
287-`       Top = 241`\
288-`       Width = 532`\
289-`       Align = alBottom`\
290-`       Caption = 'Select Customer First, then click in item number field to select item, then save'`\
291-`       ParentColor = False`\
292-`     end`\
293-`     object pnlSelectCust: TPanel`\
294-`       Left = 15`\
295-`       Height = 216`\
296-`       Top = 14`\
297-`       Width = 232`\
298-`       BevelInner = bvLowered`\
299-`       BevelWidth = 2`\
300-`       ClientHeight = 216`\
301-`       ClientWidth = 232`\
302-`       TabOrder = 0`\
303-`       object Label1: TLabel`\
304-`         Left = 4`\
305-`         Height = 18`\
306-`         Top = 4`\
307-`         Width = 224`\
308-`         Align = alTop`\
309-`         Alignment = taCenter`\
310-`         Caption = 'Customer Detail'`\
311-`         Font.Height = -13`\
312-`         Font.Name = 'Sans'`\
313-`         Font.Style = [fsBold, fsItalic]`\
314-`         ParentColor = False`\
315-`         ParentFont = False`\
316-`       end`\
317-`       object Label2: TLabel`\
318-`         Left = 24`\
319-`         Height = 18`\
320-`         Top = 31`\
321-`         Width = 73`\
322-`         Caption = 'First Name'`\
323-`         Font.Height = -13`\
324-`         Font.Name = 'Sans'`\
325-`         Font.Style = [fsItalic]`\
326-`         ParentColor = False`\
327-`         ParentFont = False`\
328-`       end`\
329-`       object DBEdit1: TDBEdit`\
330-`         Left = 24`\
331-`         Height = 23`\
332-`         Hint = 'Cust name'`\
333-`         Top = 48`\
334-`         Width = 184`\
335-`         DataField = 'CustName'`\
336-`         DataSource = dsCust`\
337-`         ReadOnly = True`\
338-`         MaxLength = 8192`\
339-`         ParentShowHint = False`\
340-`         ShowHint = True`\
341-`         TabOrder = 0`\
342-`       end`\
343-`       object DBEdit3: TDBEdit`\
344-`         Left = 24`\
345-`         Height = 23`\
346-`         Hint = 'Address'`\
347-`         Top = 72`\
348-`         Width = 184`\
349-`         DataField = 'Addr'`\
350-`         DataSource = dsCust`\
351-`         ReadOnly = True`\
352-`         MaxLength = 8192`\
353-`         ParentShowHint = False`\
354-`         ShowHint = True`\
355-`         TabOrder = 1`\
356-`       end`\
357-`       object DBEdit4: TDBEdit`\
358-`         Left = 24`\
359-`         Height = 23`\
360-`         Hint = 'Suburb/Town'`\
361-`         Top = 96`\
362-`         Width = 184`\
363-`         DataField = 'Suburb'`\
364-`         DataSource = dsCust`\
365-`         ReadOnly = True`\
366-`         MaxLength = 8192`\
367-`         ParentShowHint = False`\
368-`         ShowHint = True`\
369-`         TabOrder = 2`\
370-`       end`\
371-`       object DBEdit5: TDBEdit`\
372-`         Left = 24`\
373-`         Height = 23`\
374-`         Hint = 'Postal Code'`\
375-`         Top = 120`\
376-`         Width = 80`\
377-`         DataField = 'postCode'`\
378-`         DataSource = dsCust`\
379-`         ReadOnly = True`\
380-`         MaxLength = 8192`\
381-`         ParentShowHint = False`\
382-`         ShowHint = True`\
383-`         TabOrder = 3`\
384-`       end`\
385-`       object DBEdit6: TDBEdit`\
386-`         Left = 128`\
387-`         Height = 23`\
388-`         Hint = 'State'`\
389-`         Top = 119`\
390-`         Width = 80`\
391-`         DataField = 'custState'`\
392-`         DataSource = dsCust`\
393-`         ReadOnly = True`\
394-`         CharCase = ecUppercase`\
395-`         MaxLength = 8192`\
396-`         ParentShowHint = False`\
397-`         ShowHint = True`\
398-`         TabOrder = 4`\
399-`       end`\
400-`       object btnSelCust: TButton`\
401-`         Left = 24`\
402-`         Height = 25`\
403-`         Hint = 'Click to select a Customer'`\
404-`         Top = 176`\
405-`         Width = 184`\
406-`         Caption = 'Select Customer'`\
407-`         OnClick = btnSelCustClick`\
408-`         ParentShowHint = False`\
409-`         ShowHint = True`\
410-`         TabOrder = 5`\
411-`       end`\
412-`       object DBNavigator3: TDBNavigator`\
413-`         Left = 30`\
414-`         Height = 22`\
415-`         Top = 150`\
416-`         Width = 170`\
417-`         BevelOuter = bvNone`\
418-`         ClientHeight = 22`\
419-`         ClientWidth = 170`\
420-`         DataSource = dsCust`\
421-`         TabOrder = 6`\
422-`         VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]`\
423-`       end`\
424-`     end`\
425-`     object pnlSales: TPanel`\
426-`       Left = 255`\
427-`       Height = 216`\
428-`       Top = 14`\
429-`       Width = 260`\
430-`       BevelInner = bvLowered`\
431-`       BevelWidth = 2`\
432-`       ClientHeight = 216`\
433-`       ClientWidth = 260`\
434-`       TabOrder = 1`\
435-`       object Label4: TLabel`\
436-`         Left = 4`\
437-`         Height = 18`\
438-`         Top = 4`\
439-`         Width = 252`\
440-`         Align = alTop`\
441-`         Alignment = taCenter`\
442-`         Caption = 'Sales Detail'`\
443-`         Font.Height = -13`\
444-`         Font.Name = 'Sans'`\
445-`         Font.Style = [fsBold, fsItalic]`\
446-`         ParentColor = False`\
447-`         ParentFont = False`\
448-`       end`\
449-`       object btnAddSale: TButton`\
450-`         Left = 16`\
451-`         Height = 25`\
452-`         Hint = 'Add Another Sale'`\
453-`         Top = 176`\
454-`         Width = 72`\
455-`         Caption = 'Add Sale'`\
456-`         OnClick = btnAddSaleClick`\
457-`         ParentShowHint = False`\
458-`         ShowHint = True`\
459-`         TabOrder = 0`\
460-`       end`\
461-`       object Panel1: TPanel`\
462-`         Left = 4`\
463-`         Height = 13`\
464-`         Top = 22`\
465-`         Width = 252`\
466-`         Align = alTop`\
467-`         BevelOuter = bvNone`\
468-`         TabOrder = 1`\
469-`       end`\
470-`       object dgSales: TDBGrid`\
471-`         Left = 4`\
472-`         Height = 125`\
473-`         Hint = 'Click Item Number Button to Select Item'`\
474-`         Top = 35`\
475-`         Width = 252`\
476-`         Align = alTop`\
477-`         Columns = <          `\
478-`           item`\
479-`             ButtonStyle = cbsEllipsis`\
480-`             Title.Caption = 'item Number'`\
481-`             Width = 100`\
482-`             FieldName = 'itemNum'`\
483-`           end          `\
484-`           item`\
485-`             Width = 150`\
486-`             FieldName = 'item'`\
487-`           end          `\
488-`           item`\
489-`             FieldName = 'price'`\
490-`           end          `\
491-`           item`\
492-`             Title.Caption = 'sale Date'`\
493-`             FieldName = 'saleDate'`\
494-`           end          `\
495-`           item`\
496-`             Title.Caption = 'ship Date'`\
497-`             FieldName = 'shipDate'`\
498-`           end>`\
499-`         DataSource = dsSales`\
500-`         ShowHint = True`\
501-`         TabOrder = 2`\
502-`         TitleFont.Height = -13`\
503-`         TitleFont.Name = 'Sans'`\
504-`         OnEditButtonClick = dgSalesEditButtonClick`\
505-`       end`\
506-`       object btnSaveEntry: TButton`\
507-`         Left = 95`\
508-`         Height = 25`\
509-`         Hint = 'Save Entry'`\
510-`         Top = 176`\
511-`         Width = 51`\
512-`         Caption = 'Save'`\
513-`         OnClick = btnSaveEntryClick`\
514-`         ParentShowHint = False`\
515-`         ShowHint = True`\
516-`         TabOrder = 3`\
517-`       end`\
518-`       object btnDelEntry: TButton`\
519-`         Left = 168`\
520-`         Height = 25`\
521-`         Hint = 'Delete Entry'`\
522-`         Top = 176`\
523-`         Width = 75`\
524-`         Caption = 'Delete'`\
525-`         OnClick = btnDelEntryClick`\
526-`         ParentShowHint = False`\
527-`         ShowHint = True`\
528-`         TabOrder = 4`\
529-`       end`\
530-`     end`\
531-`   end`\
532-`   object pCustomer: TPage`\
533-`     Caption = 'Customer'`\
534-`     ClientWidth = 532`\
535-`     ClientHeight = 259`\
536-`     object pnlCustomer: TPanel`\
537-`       Left = 95`\
538-`       Height = 194`\
539-`       Top = 30`\
540-`       Width = 339`\
541-`       BevelInner = bvLowered`\
542-`       BevelWidth = 2`\
543-`       ClientHeight = 194`\
544-`       ClientWidth = 339`\
545-`       TabOrder = 0`\
546-`       object Label5: TLabel`\
547-`         Left = 72`\
548-`         Height = 18`\
549-`         Top = 31`\
550-`         Width = 73`\
551-`         Caption = 'First Name'`\
552-`         Font.Height = -13`\
553-`         Font.Name = 'Sans'`\
554-`         Font.Style = [fsItalic]`\
555-`         ParentColor = False`\
556-`         ParentFont = False`\
557-`       end`\
558-`       object Label7: TLabel`\
559-`         Left = 4`\
560-`         Height = 18`\
561-`         Top = 4`\
562-`         Width = 331`\
563-`         Align = alTop`\
564-`         Alignment = taCenter`\
565-`         Caption = 'Customer Entry'`\
566-`         Font.Height = -13`\
567-`         Font.Name = 'Sans'`\
568-`         Font.Style = [fsBold, fsItalic]`\
569-`         ParentColor = False`\
570-`         ParentFont = False`\
571-`       end`\
572-`       object DBEdit10: TDBEdit`\
573-`         Left = 72`\
574-`         Height = 23`\
575-`         Hint = 'Cust name'`\
576-`         Top = 48`\
577-`         Width = 184`\
578-`         DataField = 'CustName'`\
579-`         DataSource = dsCust`\
580-`         MaxLength = 8192`\
581-`         ParentShowHint = False`\
582-`         ShowHint = True`\
583-`         TabOrder = 0`\
584-`       end`\
585-`       object DBEdit12: TDBEdit`\
586-`         Left = 72`\
587-`         Height = 23`\
588-`         Hint = 'Address'`\
589-`         Top = 72`\
590-`         Width = 184`\
591-`         DataField = 'Addr'`\
592-`         DataSource = dsCust`\
593-`         MaxLength = 8192`\
594-`         ParentShowHint = False`\
595-`         ShowHint = True`\
596-`         TabOrder = 1`\
597-`       end`\
598-`       object DBEdit13: TDBEdit`\
599-`         Left = 72`\
600-`         Height = 23`\
601-`         Hint = 'Suburb/Town'`\
602-`         Top = 96`\
603-`         Width = 184`\
604-`         DataField = 'Suburb'`\
605-`         DataSource = dsCust`\
606-`         MaxLength = 8192`\
607-`         ParentShowHint = False`\
608-`         ShowHint = True`\
609-`         TabOrder = 2`\
610-`       end`\
611-`       object DBEdit14: TDBEdit`\
612-`         Left = 72`\
613-`         Height = 23`\
614-`         Hint = 'Postal Code'`\
615-`         Top = 120`\
616-`         Width = 80`\
617-`         DataField = 'postCode'`\
618-`         DataSource = dsCust`\
619-`         MaxLength = 8192`\
620-`         ParentShowHint = False`\
621-`         ShowHint = True`\
622-`         TabOrder = 3`\
623-`       end`\
624-`       object DBEdit15: TDBEdit`\
625-`         Left = 176`\
626-`         Height = 23`\
627-`         Hint = 'State'`\
628-`         Top = 119`\
629-`         Width = 80`\
630-`         DataField = 'custState'`\
631-`         DataSource = dsCust`\
632-`         CharCase = ecUppercase`\
633-`         MaxLength = 8192`\
634-`         ParentShowHint = False`\
635-`         ShowHint = True`\
636-`         TabOrder = 4`\
637-`       end`\
638-`       object DBNavigator2: TDBNavigator`\
639-`         Left = 45`\
640-`         Height = 25`\
641-`         Top = 154`\
642-`         Width = 241`\
643-`         BevelOuter = bvNone`\
644-`         ClientHeight = 25`\
645-`         ClientWidth = 241`\
646-`         DataSource = dsCust`\
647-`         TabOrder = 5`\
648-`       end`\
649-`     end`\
650-`   end`\
651-`   object pStock: TPage`\
652-`     Caption = 'Stock'`\
653-`     ClientWidth = 532`\
654-`     ClientHeight = 259`\
655-`     object pnlStock: TPanel`\
656-`       Left = 95`\
657-`       Height = 218`\
658-`       Top = 22`\
659-`       Width = 339`\
660-`       BevelInner = bvLowered`\
661-`       BevelWidth = 2`\
662-`       ClientHeight = 218`\
663-`       ClientWidth = 339`\
664-`       TabOrder = 0`\
665-`       object Label8: TLabel`\
666-`         Left = 4`\
667-`         Height = 18`\
668-`         Top = 4`\
669-`         Width = 331`\
670-`         Align = alTop`\
671-`         Alignment = taCenter`\
672-`         Caption = 'Stock Entry'`\
673-`         Font.Height = -13`\
674-`         Font.Name = 'Sans'`\
675-`         Font.Style = [fsBold, fsItalic]`\
676-`         ParentColor = False`\
677-`         ParentFont = False`\
678-`       end`\
679-`       object Label9: TLabel`\
680-`         Left = 75`\
681-`         Height = 18`\
682-`         Top = 24`\
683-`         Width = 83`\
684-`         Caption = 'Part Number'`\
685-`         Font.Height = -13`\
686-`         Font.Name = 'Sans'`\
687-`         Font.Style = [fsItalic]`\
688-`         ParentColor = False`\
689-`         ParentFont = False`\
690-`       end`\
691-`       object Label10: TLabel`\
692-`         Left = 75`\
693-`         Height = 18`\
694-`         Top = 72`\
695-`         Width = 75`\
696-`         Caption = 'Description'`\
697-`         Font.Height = -13`\
698-`         Font.Name = 'Sans'`\
699-`         Font.Style = [fsItalic]`\
700-`         ParentColor = False`\
701-`         ParentFont = False`\
702-`       end`\
703-`       object Label11: TLabel`\
704-`         Left = 75`\
705-`         Height = 18`\
706-`         Top = 128`\
707-`         Width = 33`\
708-`         Caption = 'Price'`\
709-`         Font.Height = -13`\
710-`         Font.Name = 'Sans'`\
711-`         Font.Style = [fsItalic]`\
712-`         ParentColor = False`\
713-`         ParentFont = False`\
714-`       end`\
715-`       object DBEdit7: TDBEdit`\
716-`         Left = 75`\
717-`         Height = 23`\
718-`         Top = 40`\
719-`         Width = 181`\
720-`         DataField = 'itemNum'`\
721-`         DataSource = dsStock`\
722-`         MaxLength = 8192`\
723-`         ParentShowHint = False`\
724-`         ShowHint = True`\
725-`         TabOrder = 0`\
726-`       end`\
727-`       object DBEdit8: TDBEdit`\
728-`         Left = 75`\
729-`         Height = 23`\
730-`         Top = 89`\
731-`         Width = 181`\
732-`         DataField = 'item'`\
733-`         DataSource = dsStock`\
734-`         MaxLength = 8192`\
735-`         ParentShowHint = False`\
736-`         ShowHint = True`\
737-`         TabOrder = 1`\
738-`       end`\
739-`       object DBEdit9: TDBEdit`\
740-`         Left = 75`\
741-`         Height = 23`\
742-`         Top = 145`\
743-`         Width = 181`\
744-`         DataField = 'price'`\
745-`         DataSource = dsStock`\
746-`         ParentShowHint = False`\
747-`         ShowHint = True`\
748-`         TabOrder = 2`\
749-`       end`\
750-`       object DBNavigator1: TDBNavigator`\
751-`         Left = 48`\
752-`         Height = 25`\
753-`         Top = 183`\
754-`         Width = 241`\
755-`         BevelOuter = bvNone`\
756-`         ClientHeight = 25`\
757-`         ClientWidth = 241`\
758-`         DataSource = dsStock`\
759-`         ParentShowHint = False`\
760-`         ShowHint = True`\
761-`         TabOrder = 3`\
762-`       end`\
763-`     end`\
764-`   end`\
765-` end`\
766-` object mmMain: TMainMenu`\
767-`   left = 16`\
768-`   top = 277`\
769-`   object miFile: TMenuItem`\
770-`     Caption = '&File'`\
771-`     object miClose: TMenuItem`\
772-`       Caption = '&Close'`\
773-`       GlyphShowMode = gsmAlways`\
774-`       Hint = 'Close Application'`\
775-`       OnClick = miCloseClick`\
776-`     end`\
777-`   end`\
778-` end`\
779-` object dsCust: TDatasource`\
780-`   DataSet = TCust`\
781-`   left = 16`\
782-`   top = 53`\
783-` end`\
784-` object dsSales: TDatasource`\
785-`   DataSet = TSales`\
786-`   left = 16`\
787-`   top = 141`\
788-` end`\
789-` object dsStock: TDatasource`\
790-`   DataSet = TStock`\
791-`   left = 16`\
792-`   top = 214`\
793-` end`\
794-` object TCust: TSqlite3Dataset`\
795-`   AutoIncrementKey = True`\
796-`   Options = []`\
797-`   PrimaryKey = 'ID'`\
798-`   SaveOnClose = True`\
799-`   SaveOnRefetch = True`\
800-`   SQL = 'Select * from cust;'`\
801-`   TableName = 'cust'`\
802-`   FieldDefs = <    `\
803-`     item`\
804-`       Name = 'ID'`\
805-`       DataType = ftAutoInc`\
806-`       Precision = -1`\
807-`       Size = 0`\
808-`     end    `\
809-`     item`\
810-`       Name = 'CustName'`\
811-`       DataType = ftString`\
812-`       Precision = -1`\
813-`       Size = 8192`\
814-`     end    `\
815-`     item`\
816-`       Name = 'Addr'`\
817-`       DataType = ftString`\
818-`       Precision = -1`\
819-`       Size = 8192`\
820-`     end    `\
821-`     item`\
822-`       Name = 'Suburb'`\
823-`       DataType = ftString`\
824-`       Precision = -1`\
825-`       Size = 8192`\
826-`     end    `\
827-`     item`\
828-`       Name = 'postCode'`\
829-`       DataType = ftString`\
830-`       Precision = -1`\
831-`       Size = 8192`\
832-`     end    `\
833-`     item`\
834-`       Name = 'custState'`\
835-`       DataType = ftString`\
836-`       Precision = -1`\
837-`       Size = 8192`\
838-`     end>`\
839-`   left = 66`\
840-`   top = 53`\
841-`   object TCustID: TAutoIncField`\
842-`     DisplayWidth = 10`\
843-`     FieldKind = fkData`\
844-`     FieldName = 'ID'`\
845-`     Index = 0`\
846-`     LookupCache = False`\
847-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
848-`     ReadOnly = False`\
849-`     Required = False`\
850-`   end`\
851-`   object TCustCustName: TStringField`\
852-`     DisplayWidth = 8192`\
853-`     FieldKind = fkData`\
854-`     FieldName = 'CustName'`\
855-`     Index = 1`\
856-`     LookupCache = False`\
857-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
858-`     ReadOnly = False`\
859-`     Required = False`\
860-`     Size = 8192`\
861-`   end`\
862-`   object TCustAddr: TStringField`\
863-`     DisplayWidth = 8192`\
864-`     FieldKind = fkData`\
865-`     FieldName = 'Addr'`\
866-`     Index = 2`\
867-`     LookupCache = False`\
868-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
869-`     ReadOnly = False`\
870-`     Required = False`\
871-`     Size = 8192`\
872-`   end`\
873-`   object TCustSuburb: TStringField`\
874-`     DisplayWidth = 8192`\
875-`     FieldKind = fkData`\
876-`     FieldName = 'Suburb'`\
877-`     Index = 3`\
878-`     LookupCache = False`\
879-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
880-`     ReadOnly = False`\
881-`     Required = False`\
882-`     Size = 8192`\
883-`   end`\
884-`   object TCustpostCode: TStringField`\
885-`     DisplayWidth = 8192`\
886-`     FieldKind = fkData`\
887-`     FieldName = 'postCode'`\
888-`     Index = 4`\
889-`     LookupCache = False`\
890-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
891-`     ReadOnly = False`\
892-`     Required = False`\
893-`     Size = 8192`\
894-`   end`\
895-`   object TCustcustState: TStringField`\
896-`     DisplayWidth = 8192`\
897-`     FieldKind = fkData`\
898-`     FieldName = 'custState'`\
899-`     Index = 5`\
900-`     LookupCache = False`\
901-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
902-`     ReadOnly = False`\
903-`     Required = False`\
904-`     Size = 8192`\
905-`   end`\
906-` end`\
907-` object TSales: TSqlite3Dataset`\
908-`   AutoIncrementKey = True`\
909-`   IndexFieldNames = 'CustID'`\
910-`   Options = []`\
911-`   PrimaryKey = 'ID'`\
912-`   SaveOnClose = True`\
913-`   SaveOnRefetch = True`\
914-`   SQL = 'Select * from sales;'`\
915-`   TableName = 'sales'`\
916-`   MasterSource = dsCust`\
917-`   MasterFields = 'ID'`\
918-`   FieldDefs = <    `\
919-`     item`\
920-`       Name = 'itemNum'`\
921-`       DataType = ftString`\
922-`       Precision = -1`\
923-`       Size = 8192`\
924-`     end    `\
925-`     item`\
926-`       Name = 'ID'`\
927-`       DataType = ftAutoInc`\
928-`       Precision = -1`\
929-`       Size = 0`\
930-`     end    `\
931-`     item`\
932-`       Name = 'custID'`\
933-`       DataType = ftInteger`\
934-`       Precision = -1`\
935-`       Size = 0`\
936-`     end    `\
937-`     item`\
938-`       Name = 'saleDate'`\
939-`       DataType = ftDate`\
940-`       Precision = -1`\
941-`       Size = 0`\
942-`     end    `\
943-`     item`\
944-`       Name = 'shipDate'`\
945-`       DataType = ftDate`\
946-`       Precision = -1`\
947-`       Size = 0`\
948-`     end    `\
949-`     item`\
950-`       Name = 'item'`\
951-`       DataType = ftString`\
952-`       Precision = -1`\
953-`       Size = 8192`\
954-`     end    `\
955-`     item`\
956-`       Name = 'price'`\
957-`       DataType = ftFloat`\
958-`       Precision = -1`\
959-`       Size = 0`\
960-`     end>`\
961-`   left = 66`\
962-`   top = 141`\
963-`   object TSalesitemNum: TStringField`\
964-`     DisplayWidth = 8192`\
965-`     FieldKind = fkData`\
966-`     FieldName = 'itemNum'`\
967-`     Index = 0`\
968-`     LookupCache = False`\
969-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
970-`     ReadOnly = False`\
971-`     Required = False`\
972-`     Size = 8192`\
973-`   end`\
974-`   object TSalesID: TAutoIncField`\
975-`     DisplayWidth = 10`\
976-`     FieldKind = fkData`\
977-`     FieldName = 'ID'`\
978-`     Index = 1`\
979-`     LookupCache = False`\
980-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
981-`     ReadOnly = False`\
982-`     Required = False`\
983-`   end`\
984-`   object TSalescustID: TLongintField`\
985-`     DisplayWidth = 10`\
986-`     FieldKind = fkData`\
987-`     FieldName = 'custID'`\
988-`     Index = 2`\
989-`     LookupCache = False`\
990-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
991-`     ReadOnly = False`\
992-`     Required = False`\
993-`   end`\
994-`   object TSalessaleDate: TDateField`\
995-`     DisplayWidth = 10`\
996-`     FieldKind = fkData`\
997-`     FieldName = 'saleDate'`\
998-`     Index = 3`\
999-`     LookupCache = False`\
1000-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
1001-`     ReadOnly = False`\
1002-`     Required = False`\
1003-`   end`\
1004-`   object TSalesshipDate: TDateField`\
1005-`     DisplayWidth = 10`\
1006-`     FieldKind = fkData`\
1007-`     FieldName = 'shipDate'`\
1008-`     Index = 4`\
1009-`     LookupCache = False`\
1010-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
1011-`     ReadOnly = False`\
1012-`     Required = False`\
1013-`   end`\
1014-`   object TSalesitem: TStringField`\
1015-`     DisplayWidth = 8192`\
1016-`     FieldKind = fkData`\
1017-`     FieldName = 'item'`\
1018-`     Index = 5`\
1019-`     LookupCache = False`\
1020-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
1021-`     ReadOnly = False`\
1022-`     Required = False`\
1023-`     Size = 8192`\
1024-`   end`\
1025-`   object TSalesprice: TFloatField`\
1026-`     DisplayWidth = 10`\
1027-`     FieldKind = fkData`\
1028-`     FieldName = 'price'`\
1029-`     Index = 6`\
1030-`     LookupCache = False`\
1031-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
1032-`     ReadOnly = False`\
1033-`     Required = False`\
1034-`     Currency = True`\
1035-`     MaxValue = 0`\
1036-`     MinValue = 0`\
1037-`     Precision = -1`\
1038-`   end`\
1039-` end`\
1040-` object TStock: TSqlite3Dataset`\
1041-`   AutoIncrementKey = True`\
1042-`   Options = []`\
1043-`   PrimaryKey = 'ID'`\
1044-`   SaveOnClose = True`\
1045-`   SaveOnRefetch = True`\
1046-`   SQL = 'Select * from stock;'`\
1047-`   TableName = 'stock'`\
1048-`   FieldDefs = <    `\
1049-`     item`\
1050-`       Name = 'ID'`\
1051-`       DataType = ftAutoInc`\
1052-`       Precision = -1`\
1053-`       Size = 0`\
1054-`     end    `\
1055-`     item`\
1056-`       Name = 'item'`\
1057-`       DataType = ftString`\
1058-`       Precision = -1`\
1059-`       Size = 8192`\
1060-`     end    `\
1061-`     item`\
1062-`       Name = 'price'`\
1063-`       DataType = ftFloat`\
1064-`       Precision = -1`\
1065-`       Size = 0`\
1066-`     end    `\
1067-`     item`\
1068-`       Name = 'itemNum'`\
1069-`       DataType = ftString`\
1070-`       Precision = -1`\
1071-`       Size = 8192`\
1072-`     end>`\
1073-`   left = 66`\
1074-`   top = 214`\
1075-`   object TStockID: TAutoIncField`\
1076-`     DisplayWidth = 10`\
1077-`     FieldKind = fkData`\
1078-`     FieldName = 'ID'`\
1079-`     Index = 0`\
1080-`     LookupCache = False`\
1081-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
1082-`     ReadOnly = False`\
1083-`     Required = False`\
1084-`   end`\
1085-`   object TStockitem: TStringField`\
1086-`     DisplayWidth = 8192`\
1087-`     FieldKind = fkData`\
1088-`     FieldName = 'item'`\
1089-`     Index = 1`\
1090-`     LookupCache = False`\
1091-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
1092-`     ReadOnly = False`\
1093-`     Required = False`\
1094-`     Size = 8192`\
1095-`   end`\
1096-`   object TStockprice: TFloatField`\
1097-`     DisplayWidth = 10`\
1098-`     FieldKind = fkData`\
1099-`     FieldName = 'price'`\
1100-`     Index = 2`\
1101-`     LookupCache = False`\
1102-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
1103-`     ReadOnly = False`\
1104-`     Required = False`\
1105-`     Currency = True`\
1106-`     MaxValue = 0`\
1107-`     MinValue = 0`\
1108-`     Precision = -1`\
1109-`   end`\
1110-`   object TStockitemNum: TStringField`\
1111-`     DisplayWidth = 8192`\
1112-`     FieldKind = fkData`\
1113-`     FieldName = 'itemNum'`\
1114-`     Index = 3`\
1115-`     LookupCache = False`\
1116-`     ProviderFlags = [pfInUpdate, pfInWhere]`\
1117-`     ReadOnly = False`\
1118-`     Required = False`\
1119-`     Size = 8192`\
1120-`   end`\
1121-` end`
243+uMain.lfm (edited)
1122244
245+``` pascal
246+object fMain: TfMain
247+ Left = 395
248+ Height = 332
249+ Top = 218
250+ Width = 534
251+ ActiveControl = nbMain
252+ BorderIcons = [biSystemMenu, biMinimize]
253+ BorderStyle = bsSingle
254+ Caption = 'Master Detail Example - SQLLite3'
255+ ClientHeight = 305
256+ ClientWidth = 534
257+ Font.Height = -13
258+ Font.Name = 'Sans'
259+ Menu = mmMain
260+ OnCloseQuery = FormCloseQuery
261+ OnCreate = FormCreate
262+ OnDestroy = FormDestroy
263+ OnShow = FormShow
264+ Position = poScreenCenter
265+ LCLVersion = '0.9.27'
266+ object sbMain: TStatusBar
267+ Left = 0
268+ Height = 19
269+ Top = 286
270+ Width = 534
271+ AutoHint = True
272+ Panels = <>
273+ end
274+ object nbMain: TNotebook
275+ Left = 0
276+ Height = 286
277+ Top = 0
278+ Width = 534
279+ Align = alClient
280+ PageIndex = 0
281+ TabOrder = 1
282+ object pSales: TPage
283+ Caption = 'Sales'
284+ ClientWidth = 532
285+ ClientHeight = 259
286+ object Label3: TLabel
287+ Left = 0
288+ Height = 18
289+ Top = 241
290+ Width = 532
291+ Align = alBottom
292+ Caption = 'Select Customer First, then click in item number field to select item, then save'
293+ ParentColor = False
294+ end
295+ object pnlSelectCust: TPanel
296+ Left = 15
297+ Height = 216
298+ Top = 14
299+ Width = 232
300+ BevelInner = bvLowered
301+ BevelWidth = 2
302+ ClientHeight = 216
303+ ClientWidth = 232
304+ TabOrder = 0
305+ object Label1: TLabel
306+ Left = 4
307+ Height = 18
308+ Top = 4
309+ Width = 224
310+ Align = alTop
311+ Alignment = taCenter
312+ Caption = 'Customer Detail'
313+ Font.Height = -13
314+ Font.Name = 'Sans'
315+ Font.Style = [fsBold, fsItalic]
316+ ParentColor = False
317+ ParentFont = False
318+ end
319+ object Label2: TLabel
320+ Left = 24
321+ Height = 18
322+ Top = 31
323+ Width = 73
324+ Caption = 'First Name'
325+ Font.Height = -13
326+ Font.Name = 'Sans'
327+ Font.Style = [fsItalic]
328+ ParentColor = False
329+ ParentFont = False
330+ end
331+ object DBEdit1: TDBEdit
332+ Left = 24
333+ Height = 23
334+ Hint = 'Cust name'
335+ Top = 48
336+ Width = 184
337+ DataField = 'CustName'
338+ DataSource = dsCust
339+ ReadOnly = True
340+ MaxLength = 8192
341+ ParentShowHint = False
342+ ShowHint = True
343+ TabOrder = 0
344+ end
345+ object DBEdit3: TDBEdit
346+ Left = 24
347+ Height = 23
348+ Hint = 'Address'
349+ Top = 72
350+ Width = 184
351+ DataField = 'Addr'
352+ DataSource = dsCust
353+ ReadOnly = True
354+ MaxLength = 8192
355+ ParentShowHint = False
356+ ShowHint = True
357+ TabOrder = 1
358+ end
359+ object DBEdit4: TDBEdit
360+ Left = 24
361+ Height = 23
362+ Hint = 'Suburb/Town'
363+ Top = 96
364+ Width = 184
365+ DataField = 'Suburb'
366+ DataSource = dsCust
367+ ReadOnly = True
368+ MaxLength = 8192
369+ ParentShowHint = False
370+ ShowHint = True
371+ TabOrder = 2
372+ end
373+ object DBEdit5: TDBEdit
374+ Left = 24
375+ Height = 23
376+ Hint = 'Postal Code'
377+ Top = 120
378+ Width = 80
379+ DataField = 'postCode'
380+ DataSource = dsCust
381+ ReadOnly = True
382+ MaxLength = 8192
383+ ParentShowHint = False
384+ ShowHint = True
385+ TabOrder = 3
386+ end
387+ object DBEdit6: TDBEdit
388+ Left = 128
389+ Height = 23
390+ Hint = 'State'
391+ Top = 119
392+ Width = 80
393+ DataField = 'custState'
394+ DataSource = dsCust
395+ ReadOnly = True
396+ CharCase = ecUppercase
397+ MaxLength = 8192
398+ ParentShowHint = False
399+ ShowHint = True
400+ TabOrder = 4
401+ end
402+ object btnSelCust: TButton
403+ Left = 24
404+ Height = 25
405+ Hint = 'Click to select a Customer'
406+ Top = 176
407+ Width = 184
408+ Caption = 'Select Customer'
409+ OnClick = btnSelCustClick
410+ ParentShowHint = False
411+ ShowHint = True
412+ TabOrder = 5
413+ end
414+ object DBNavigator3: TDBNavigator
415+ Left = 30
416+ Height = 22
417+ Top = 150
418+ Width = 170
419+ BevelOuter = bvNone
420+ ClientHeight = 22
421+ ClientWidth = 170
422+ DataSource = dsCust
423+ TabOrder = 6
424+ VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]
425+ end
426+ end
427+ object pnlSales: TPanel
428+ Left = 255
429+ Height = 216
430+ Top = 14
431+ Width = 260
432+ BevelInner = bvLowered
433+ BevelWidth = 2
434+ ClientHeight = 216
435+ ClientWidth = 260
436+ TabOrder = 1
437+ object Label4: TLabel
438+ Left = 4
439+ Height = 18
440+ Top = 4
441+ Width = 252
442+ Align = alTop
443+ Alignment = taCenter
444+ Caption = 'Sales Detail'
445+ Font.Height = -13
446+ Font.Name = 'Sans'
447+ Font.Style = [fsBold, fsItalic]
448+ ParentColor = False
449+ ParentFont = False
450+ end
451+ object btnAddSale: TButton
452+ Left = 16
453+ Height = 25
454+ Hint = 'Add Another Sale'
455+ Top = 176
456+ Width = 72
457+ Caption = 'Add Sale'
458+ OnClick = btnAddSaleClick
459+ ParentShowHint = False
460+ ShowHint = True
461+ TabOrder = 0
462+ end
463+ object Panel1: TPanel
464+ Left = 4
465+ Height = 13
466+ Top = 22
467+ Width = 252
468+ Align = alTop
469+ BevelOuter = bvNone
470+ TabOrder = 1
471+ end
472+ object dgSales: TDBGrid
473+ Left = 4
474+ Height = 125
475+ Hint = 'Click Item Number Button to Select Item'
476+ Top = 35
477+ Width = 252
478+ Align = alTop
479+ Columns = <
480+ item
481+ ButtonStyle = cbsEllipsis
482+ Title.Caption = 'item Number'
483+ Width = 100
484+ FieldName = 'itemNum'
485+ end
486+ item
487+ Width = 150
488+ FieldName = 'item'
489+ end
490+ item
491+ FieldName = 'price'
492+ end
493+ item
494+ Title.Caption = 'sale Date'
495+ FieldName = 'saleDate'
496+ end
497+ item
498+ Title.Caption = 'ship Date'
499+ FieldName = 'shipDate'
500+ end>
501+ DataSource = dsSales
502+ ShowHint = True
503+ TabOrder = 2
504+ TitleFont.Height = -13
505+ TitleFont.Name = 'Sans'
506+ OnEditButtonClick = dgSalesEditButtonClick
507+ end
508+ object btnSaveEntry: TButton
509+ Left = 95
510+ Height = 25
511+ Hint = 'Save Entry'
512+ Top = 176
513+ Width = 51
514+ Caption = 'Save'
515+ OnClick = btnSaveEntryClick
516+ ParentShowHint = False
517+ ShowHint = True
518+ TabOrder = 3
519+ end
520+ object btnDelEntry: TButton
521+ Left = 168
522+ Height = 25
523+ Hint = 'Delete Entry'
524+ Top = 176
525+ Width = 75
526+ Caption = 'Delete'
527+ OnClick = btnDelEntryClick
528+ ParentShowHint = False
529+ ShowHint = True
530+ TabOrder = 4
531+ end
532+ end
533+ end
534+ object pCustomer: TPage
535+ Caption = 'Customer'
536+ ClientWidth = 532
537+ ClientHeight = 259
538+ object pnlCustomer: TPanel
539+ Left = 95
540+ Height = 194
541+ Top = 30
542+ Width = 339
543+ BevelInner = bvLowered
544+ BevelWidth = 2
545+ ClientHeight = 194
546+ ClientWidth = 339
547+ TabOrder = 0
548+ object Label5: TLabel
549+ Left = 72
550+ Height = 18
551+ Top = 31
552+ Width = 73
553+ Caption = 'First Name'
554+ Font.Height = -13
555+ Font.Name = 'Sans'
556+ Font.Style = [fsItalic]
557+ ParentColor = False
558+ ParentFont = False
559+ end
560+ object Label7: TLabel
561+ Left = 4
562+ Height = 18
563+ Top = 4
564+ Width = 331
565+ Align = alTop
566+ Alignment = taCenter
567+ Caption = 'Customer Entry'
568+ Font.Height = -13
569+ Font.Name = 'Sans'
570+ Font.Style = [fsBold, fsItalic]
571+ ParentColor = False
572+ ParentFont = False
573+ end
574+ object DBEdit10: TDBEdit
575+ Left = 72
576+ Height = 23
577+ Hint = 'Cust name'
578+ Top = 48
579+ Width = 184
580+ DataField = 'CustName'
581+ DataSource = dsCust
582+ MaxLength = 8192
583+ ParentShowHint = False
584+ ShowHint = True
585+ TabOrder = 0
586+ end
587+ object DBEdit12: TDBEdit
588+ Left = 72
589+ Height = 23
590+ Hint = 'Address'
591+ Top = 72
592+ Width = 184
593+ DataField = 'Addr'
594+ DataSource = dsCust
595+ MaxLength = 8192
596+ ParentShowHint = False
597+ ShowHint = True
598+ TabOrder = 1
599+ end
600+ object DBEdit13: TDBEdit
601+ Left = 72
602+ Height = 23
603+ Hint = 'Suburb/Town'
604+ Top = 96
605+ Width = 184
606+ DataField = 'Suburb'
607+ DataSource = dsCust
608+ MaxLength = 8192
609+ ParentShowHint = False
610+ ShowHint = True
611+ TabOrder = 2
612+ end
613+ object DBEdit14: TDBEdit
614+ Left = 72
615+ Height = 23
616+ Hint = 'Postal Code'
617+ Top = 120
618+ Width = 80
619+ DataField = 'postCode'
620+ DataSource = dsCust
621+ MaxLength = 8192
622+ ParentShowHint = False
623+ ShowHint = True
624+ TabOrder = 3
625+ end
626+ object DBEdit15: TDBEdit
627+ Left = 176
628+ Height = 23
629+ Hint = 'State'
630+ Top = 119
631+ Width = 80
632+ DataField = 'custState'
633+ DataSource = dsCust
634+ CharCase = ecUppercase
635+ MaxLength = 8192
636+ ParentShowHint = False
637+ ShowHint = True
638+ TabOrder = 4
639+ end
640+ object DBNavigator2: TDBNavigator
641+ Left = 45
642+ Height = 25
643+ Top = 154
644+ Width = 241
645+ BevelOuter = bvNone
646+ ClientHeight = 25
647+ ClientWidth = 241
648+ DataSource = dsCust
649+ TabOrder = 5
650+ end
651+ end
652+ end
653+ object pStock: TPage
654+ Caption = 'Stock'
655+ ClientWidth = 532
656+ ClientHeight = 259
657+ object pnlStock: TPanel
658+ Left = 95
659+ Height = 218
660+ Top = 22
661+ Width = 339
662+ BevelInner = bvLowered
663+ BevelWidth = 2
664+ ClientHeight = 218
665+ ClientWidth = 339
666+ TabOrder = 0
667+ object Label8: TLabel
668+ Left = 4
669+ Height = 18
670+ Top = 4
671+ Width = 331
672+ Align = alTop
673+ Alignment = taCenter
674+ Caption = 'Stock Entry'
675+ Font.Height = -13
676+ Font.Name = 'Sans'
677+ Font.Style = [fsBold, fsItalic]
678+ ParentColor = False
679+ ParentFont = False
680+ end
681+ object Label9: TLabel
682+ Left = 75
683+ Height = 18
684+ Top = 24
685+ Width = 83
686+ Caption = 'Part Number'
687+ Font.Height = -13
688+ Font.Name = 'Sans'
689+ Font.Style = [fsItalic]
690+ ParentColor = False
691+ ParentFont = False
692+ end
693+ object Label10: TLabel
694+ Left = 75
695+ Height = 18
696+ Top = 72
697+ Width = 75
698+ Caption = 'Description'
699+ Font.Height = -13
700+ Font.Name = 'Sans'
701+ Font.Style = [fsItalic]
702+ ParentColor = False
703+ ParentFont = False
704+ end
705+ object Label11: TLabel
706+ Left = 75
707+ Height = 18
708+ Top = 128
709+ Width = 33
710+ Caption = 'Price'
711+ Font.Height = -13
712+ Font.Name = 'Sans'
713+ Font.Style = [fsItalic]
714+ ParentColor = False
715+ ParentFont = False
716+ end
717+ object DBEdit7: TDBEdit
718+ Left = 75
719+ Height = 23
720+ Top = 40
721+ Width = 181
722+ DataField = 'itemNum'
723+ DataSource = dsStock
724+ MaxLength = 8192
725+ ParentShowHint = False
726+ ShowHint = True
727+ TabOrder = 0
728+ end
729+ object DBEdit8: TDBEdit
730+ Left = 75
731+ Height = 23
732+ Top = 89
733+ Width = 181
734+ DataField = 'item'
735+ DataSource = dsStock
736+ MaxLength = 8192
737+ ParentShowHint = False
738+ ShowHint = True
739+ TabOrder = 1
740+ end
741+ object DBEdit9: TDBEdit
742+ Left = 75
743+ Height = 23
744+ Top = 145
745+ Width = 181
746+ DataField = 'price'
747+ DataSource = dsStock
748+ ParentShowHint = False
749+ ShowHint = True
750+ TabOrder = 2
751+ end
752+ object DBNavigator1: TDBNavigator
753+ Left = 48
754+ Height = 25
755+ Top = 183
756+ Width = 241
757+ BevelOuter = bvNone
758+ ClientHeight = 25
759+ ClientWidth = 241
760+ DataSource = dsStock
761+ ParentShowHint = False
762+ ShowHint = True
763+ TabOrder = 3
764+ end
765+ end
766+ end
767+ end
768+ object mmMain: TMainMenu
769+ left = 16
770+ top = 277
771+ object miFile: TMenuItem
772+ Caption = '&File'
773+ object miClose: TMenuItem
774+ Caption = '&Close'
775+ GlyphShowMode = gsmAlways
776+ Hint = 'Close Application'
777+ OnClick = miCloseClick
778+ end
779+ end
780+ end
781+ object dsCust: TDatasource
782+ DataSet = TCust
783+ left = 16
784+ top = 53
785+ end
786+ object dsSales: TDatasource
787+ DataSet = TSales
788+ left = 16
789+ top = 141
790+ end
791+ object dsStock: TDatasource
792+ DataSet = TStock
793+ left = 16
794+ top = 214
795+ end
796+ object TCust: TSqlite3Dataset
797+ AutoIncrementKey = True
798+ Options = []
799+ PrimaryKey = 'ID'
800+ SaveOnClose = True
801+ SaveOnRefetch = True
802+ SQL = 'Select * from cust;'
803+ TableName = 'cust'
804+ FieldDefs = <
805+ item
806+ Name = 'ID'
807+ DataType = ftAutoInc
808+ Precision = -1
809+ Size = 0
810+ end
811+ item
812+ Name = 'CustName'
813+ DataType = ftString
814+ Precision = -1
815+ Size = 8192
816+ end
817+ item
818+ Name = 'Addr'
819+ DataType = ftString
820+ Precision = -1
821+ Size = 8192
822+ end
823+ item
824+ Name = 'Suburb'
825+ DataType = ftString
826+ Precision = -1
827+ Size = 8192
828+ end
829+ item
830+ Name = 'postCode'
831+ DataType = ftString
832+ Precision = -1
833+ Size = 8192
834+ end
835+ item
836+ Name = 'custState'
837+ DataType = ftString
838+ Precision = -1
839+ Size = 8192
840+ end>
841+ left = 66
842+ top = 53
843+ object TCustID: TAutoIncField
844+ DisplayWidth = 10
845+ FieldKind = fkData
846+ FieldName = 'ID'
847+ Index = 0
848+ LookupCache = False
849+ ProviderFlags = [pfInUpdate, pfInWhere]
850+ ReadOnly = False
851+ Required = False
852+ end
853+ object TCustCustName: TStringField
854+ DisplayWidth = 8192
855+ FieldKind = fkData
856+ FieldName = 'CustName'
857+ Index = 1
858+ LookupCache = False
859+ ProviderFlags = [pfInUpdate, pfInWhere]
860+ ReadOnly = False
861+ Required = False
862+ Size = 8192
863+ end
864+ object TCustAddr: TStringField
865+ DisplayWidth = 8192
866+ FieldKind = fkData
867+ FieldName = 'Addr'
868+ Index = 2
869+ LookupCache = False
870+ ProviderFlags = [pfInUpdate, pfInWhere]
871+ ReadOnly = False
872+ Required = False
873+ Size = 8192
874+ end
875+ object TCustSuburb: TStringField
876+ DisplayWidth = 8192
877+ FieldKind = fkData
878+ FieldName = 'Suburb'
879+ Index = 3
880+ LookupCache = False
881+ ProviderFlags = [pfInUpdate, pfInWhere]
882+ ReadOnly = False
883+ Required = False
884+ Size = 8192
885+ end
886+ object TCustpostCode: TStringField
887+ DisplayWidth = 8192
888+ FieldKind = fkData
889+ FieldName = 'postCode'
890+ Index = 4
891+ LookupCache = False
892+ ProviderFlags = [pfInUpdate, pfInWhere]
893+ ReadOnly = False
894+ Required = False
895+ Size = 8192
896+ end
897+ object TCustcustState: TStringField
898+ DisplayWidth = 8192
899+ FieldKind = fkData
900+ FieldName = 'custState'
901+ Index = 5
902+ LookupCache = False
903+ ProviderFlags = [pfInUpdate, pfInWhere]
904+ ReadOnly = False
905+ Required = False
906+ Size = 8192
907+ end
908+ end
909+ object TSales: TSqlite3Dataset
910+ AutoIncrementKey = True
911+ IndexFieldNames = 'CustID'
912+ Options = []
913+ PrimaryKey = 'ID'
914+ SaveOnClose = True
915+ SaveOnRefetch = True
916+ SQL = 'Select * from sales;'
917+ TableName = 'sales'
918+ MasterSource = dsCust
919+ MasterFields = 'ID'
920+ FieldDefs = <
921+ item
922+ Name = 'itemNum'
923+ DataType = ftString
924+ Precision = -1
925+ Size = 8192
926+ end
927+ item
928+ Name = 'ID'
929+ DataType = ftAutoInc
930+ Precision = -1
931+ Size = 0
932+ end
933+ item
934+ Name = 'custID'
935+ DataType = ftInteger
936+ Precision = -1
937+ Size = 0
938+ end
939+ item
940+ Name = 'saleDate'
941+ DataType = ftDate
942+ Precision = -1
943+ Size = 0
944+ end
945+ item
946+ Name = 'shipDate'
947+ DataType = ftDate
948+ Precision = -1
949+ Size = 0
950+ end
951+ item
952+ Name = 'item'
953+ DataType = ftString
954+ Precision = -1
955+ Size = 8192
956+ end
957+ item
958+ Name = 'price'
959+ DataType = ftFloat
960+ Precision = -1
961+ Size = 0
962+ end>
963+ left = 66
964+ top = 141
965+ object TSalesitemNum: TStringField
966+ DisplayWidth = 8192
967+ FieldKind = fkData
968+ FieldName = 'itemNum'
969+ Index = 0
970+ LookupCache = False
971+ ProviderFlags = [pfInUpdate, pfInWhere]
972+ ReadOnly = False
973+ Required = False
974+ Size = 8192
975+ end
976+ object TSalesID: TAutoIncField
977+ DisplayWidth = 10
978+ FieldKind = fkData
979+ FieldName = 'ID'
980+ Index = 1
981+ LookupCache = False
982+ ProviderFlags = [pfInUpdate, pfInWhere]
983+ ReadOnly = False
984+ Required = False
985+ end
986+ object TSalescustID: TLongintField
987+ DisplayWidth = 10
988+ FieldKind = fkData
989+ FieldName = 'custID'
990+ Index = 2
991+ LookupCache = False
992+ ProviderFlags = [pfInUpdate, pfInWhere]
993+ ReadOnly = False
994+ Required = False
995+ end
996+ object TSalessaleDate: TDateField
997+ DisplayWidth = 10
998+ FieldKind = fkData
999+ FieldName = 'saleDate'
1000+ Index = 3
1001+ LookupCache = False
1002+ ProviderFlags = [pfInUpdate, pfInWhere]
1003+ ReadOnly = False
1004+ Required = False
1005+ end
1006+ object TSalesshipDate: TDateField
1007+ DisplayWidth = 10
1008+ FieldKind = fkData
1009+ FieldName = 'shipDate'
1010+ Index = 4
1011+ LookupCache = False
1012+ ProviderFlags = [pfInUpdate, pfInWhere]
1013+ ReadOnly = False
1014+ Required = False
1015+ end
1016+ object TSalesitem: TStringField
1017+ DisplayWidth = 8192
1018+ FieldKind = fkData
1019+ FieldName = 'item'
1020+ Index = 5
1021+ LookupCache = False
1022+ ProviderFlags = [pfInUpdate, pfInWhere]
1023+ ReadOnly = False
1024+ Required = False
1025+ Size = 8192
1026+ end
1027+ object TSalesprice: TFloatField
1028+ DisplayWidth = 10
1029+ FieldKind = fkData
1030+ FieldName = 'price'
1031+ Index = 6
1032+ LookupCache = False
1033+ ProviderFlags = [pfInUpdate, pfInWhere]
1034+ ReadOnly = False
1035+ Required = False
1036+ Currency = True
1037+ MaxValue = 0
1038+ MinValue = 0
1039+ Precision = -1
1040+ end
1041+ end
1042+ object TStock: TSqlite3Dataset
1043+ AutoIncrementKey = True
1044+ Options = []
1045+ PrimaryKey = 'ID'
1046+ SaveOnClose = True
1047+ SaveOnRefetch = True
1048+ SQL = 'Select * from stock;'
1049+ TableName = 'stock'
1050+ FieldDefs = <
1051+ item
1052+ Name = 'ID'
1053+ DataType = ftAutoInc
1054+ Precision = -1
1055+ Size = 0
1056+ end
1057+ item
1058+ Name = 'item'
1059+ DataType = ftString
1060+ Precision = -1
1061+ Size = 8192
1062+ end
1063+ item
1064+ Name = 'price'
1065+ DataType = ftFloat
1066+ Precision = -1
1067+ Size = 0
1068+ end
1069+ item
1070+ Name = 'itemNum'
1071+ DataType = ftString
1072+ Precision = -1
1073+ Size = 8192
1074+ end>
1075+ left = 66
1076+ top = 214
1077+ object TStockID: TAutoIncField
1078+ DisplayWidth = 10
1079+ FieldKind = fkData
1080+ FieldName = 'ID'
1081+ Index = 0
1082+ LookupCache = False
1083+ ProviderFlags = [pfInUpdate, pfInWhere]
1084+ ReadOnly = False
1085+ Required = False
1086+ end
1087+ object TStockitem: TStringField
1088+ DisplayWidth = 8192
1089+ FieldKind = fkData
1090+ FieldName = 'item'
1091+ Index = 1
1092+ LookupCache = False
1093+ ProviderFlags = [pfInUpdate, pfInWhere]
1094+ ReadOnly = False
1095+ Required = False
1096+ Size = 8192
1097+ end
1098+ object TStockprice: TFloatField
1099+ DisplayWidth = 10
1100+ FieldKind = fkData
1101+ FieldName = 'price'
1102+ Index = 2
1103+ LookupCache = False
1104+ ProviderFlags = [pfInUpdate, pfInWhere]
1105+ ReadOnly = False
1106+ Required = False
1107+ Currency = True
1108+ MaxValue = 0
1109+ MinValue = 0
1110+ Precision = -1
1111+ end
1112+ object TStockitemNum: TStringField
1113+ DisplayWidth = 8192
1114+ FieldKind = fkData
1115+ FieldName = 'itemNum'
1116+ Index = 3
1117+ LookupCache = False
1118+ ProviderFlags = [pfInUpdate, pfInWhere]
1119+ ReadOnly = False
1120+ Required = False
1121+ Size = 8192
1122+ end
1123+ end
11231124end
1125+```
11241126
11251127``` pascal
11261128unit uCust;
11271129
11281130{$mode objfpc}{$H+}
11291131
11301132interface
11311133
11321134uses
11331135 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
11341136 StdCtrls, ExtCtrls, Buttons, DBGrids,DB;
11351137
11361138type
11371139
11381140 { TcustDlg }
11391141
11401142 TcustDlg = class(TForm)
11411143 cancelBtn: TButton;
11421144 dgCust: TDBGrid;
11431145 edSearch: TEdit;
11441146 Label1: TLabel;
11451147 okBtn: TButton;
11461148 pnlCust: TPanel;
11471149 sbSearch: TSpeedButton;
11481150 procedure dgCustDblClick(Sender: TObject);
11491151 procedure edSearchChange(Sender: TObject);
11501152 procedure sbSearchClick(Sender: TObject);
11511153 private
11521154 function GetCust: String;
11531155 procedure SetCust(const AValue: String);
11541156 { private declarations }
11551157 public
11561158 { public declarations }
11571159 property CustName: String Read GetCust Write SetCust;
11581160 function ShowModalCust:integer;
11591161 end;
11601162
11611163var
11621164 custDlg: TcustDlg;
11631165
11641166implementation
11651167uses uMain;
11661168{ TcustDlg }
11671169
11681170procedure TcustDlg.edSearchChange(Sender: TObject);
11691171begin
11701172 sbSearch.Enabled:=edSearch.Text<>'';
11711173end;
11721174
11731175procedure TcustDlg.dgCustDblClick(Sender: TObject);
11741176begin
11751177 ModalResult := mrOk;
11761178end;
11771179
11781180procedure TcustDlg.sbSearchClick(Sender: TObject);
11791181begin
11801182 if not fMain.TCust.Locate('CustName', edSearch.Text,[loCaseInsensitive, loPartialKey])
11811183 then
11821184 MessageDlg('No matching record found.', mtInformation, [mbOK], 0);
11831185 edSearch.Color:=clRed;
11841186end;
11851187
11861188function TcustDlg.GetCust: String;
11871189begin
11881190 Result := fMain.TCustCustName.Value;
11891191end;
11901192
11911193procedure TcustDlg.SetCust(const AValue: String);
11921194begin
11931195 fMain.TCust.Locate('CustName',AValue,[loPartialKey,loCaseInsensitive]);
11941196end;
11951197
11961198function TcustDlg.ShowModalCust: integer;
11971199begin
11981200 Caption:='Select Customer Name';
11991201 Result := ShowModal;
12001202end;
12011203
12021204initialization
12031205 {$I uCust.lrs}
12041206
12051207end.
12061208```
12071209
12081210``` pascal
12091211unit uSales;
12101212
12111213{$mode objfpc}{$H+}
12121214
12131215interface
12141216
12151217uses
12161218 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
12171219 StdCtrls, ExtCtrls, Buttons, DBGrids, DB;
12181220
12191221type
12201222
12211223 { TsearchDlg }
12221224
12231225 TsearchDlg = class(TForm)
12241226 cancelBtn: TButton;
12251227 dgParts: TDBGrid;
12261228 edSearch: TEdit;
12271229 Label1: TLabel;
12281230 okBtn: TButton;
12291231 pnlParts: TPanel;
12301232 sbSearch: TSpeedButton;
12311233 procedure dgPartsDblClick(Sender: TObject);
12321234 procedure edSearchChange(Sender: TObject);
12331235 procedure sbSearchClick(Sender: TObject);
12341236 private
12351237 function GetPartNum: String;
12361238 procedure SetPartNum(const AValue: String);
12371239 { private declarations }
12381240 public
12391241 { public declarations }
12401242 property PartNum:String Read GetPartNum Write SetPartNum;
12411243 function ShowModalParts: Integer;
12421244 end;
12431245
12441246var
12451247 searchDlg: TsearchDlg;
12461248
12471249implementation
12481250uses uMain;
12491251{ TsearchDlg }
12501252
12511253procedure TsearchDlg.edSearchChange(Sender: TObject);
12521254begin
12531255 sbSearch.Enabled:=edSearch.Text<>'';
12541256end;
12551257
12561258procedure TsearchDlg.dgPartsDblClick(Sender: TObject);
12571259begin
12581260 ModalResult := mrOk;
12591261end;
12601262
12611263procedure TsearchDlg.sbSearchClick(Sender: TObject);
12621264begin
12631265 if not fMain.TStock.Locate('itemNum', edSearch.Text,[loCaseInsensitive, loPartialKey])
12641266 then
12651267 MessageDlg('No matching record found.', mtInformation, [mbOK], 0);
12661268 edSearch.Color:=clRed;
12671269end;
12681270
12691271function TsearchDlg.GetPartNum: String;
12701272begin
12711273 Result := fMain.TStockitemNum.Value;
12721274end;
12731275
12741276procedure TsearchDlg.SetPartNum(const AValue: String);
12751277begin
12761278 fMain.TStock.Locate('itemNum',AValue,[loPartialKey,loCaseInsensitive]);
12771279end;
12781280
12791281function TsearchDlg.ShowModalParts: Integer;
12801282begin
12811283 Caption:='Select Item Number';
12821284 Result := ShowModal;
12831285end;
12841286
12851287initialization
12861288 {$I uSales.lrs}
12871289
12881290end.
12891291```
12901292
12911293---
12921294*From the Free Pascal wiki, page "TSqlite3 Master Detail Example", as it stood on 2020-02-10 after a change by Andry, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history