Unit dbpanel;
Interface
Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Extctrls, Dbctrls, Stdctrls, DB;
type TDBPanel = class (tpanel) private {private declarations} fleft: integer; ftop: integer; maxtextlen: integer; maxlabellen: integer; fscrollbox: tscrollbox; {scrolling control} flineheight: integer; fclick: tnotifyevent; editors: array of tdbcombobox; File: // -> The data control used in the specific editing, dynamically generate labels: array of tlabel; file: // -> Dynamically generate okbutton: tbutton; file: // -> Last increased determination Buttons for implementation of the submission action.
Source data {} fdatasource: tdatasource; fcolumns: integer; file: // -> input form columns protected {protected declarations} procedure freeeditors; file: // -> public procedure createeditors release memory control data input (ds: tdatasource ; colcount: integer); file: // -> create a data entry control constructor create the fields (aowner: tcomponent); override; destructor destroy; override; procedure akeypress (sender: tobject; var key: char); procedure akeydown ( sender: tobject; var key: word; shift: tshiftstate); procedure clearhits (itemindex: integer); procedure addhits (itemindex: integer; hits: array of string); function editor (index: integer): tdbcombobox; {public declarations} published property leftlimit: integer read fleft write fleft default 10; property toplimit: integer read ftop write ftop default 10; property editorlen: integer read maxtextlen write maxtextlen; property labellen: integer read maxlabellen write maxlabellen default 100; property linehei ght: integer read flineheight write flineheight default 15; property onokclick: tnotifyevent read fclick write fclick; property datasource: tdatasource read fdatasource write fdatasource; file: // data source property columns: integer read fcolumns write fcolumns; // -> the number of columns in Table {Published Declarations} End; Procedure Register; Implementation
{Add prompt information for the i-th field} Procedure TdbPanel.addhits (ItemIndex: Integer; Hits: Array of String); Var M, N, I: Integer; Begin N: = Length (Editors); M: = Length Hits); if ItemIndex procedure tdbpanel.akeydown (sender: tobject; var key: word; shift: tshiftstate); begin if (sender is tdbcombobox) then begin case key of vk_next: (sender as tdbcombobox) .datasource.dataset.next; vk_prior: (sender as TDBCOMBOBOX) .DATASOURCE.DataSet.Prior; End; end; end; procedure tdbpanel.akeypress (sender: TOBJECT; var key: char); recomcation = # = # 13 dam (Owner As TFORM). Perform (WM_NEXTDLGCTL, 0, 0); end; end; Procedure tdbpanel.clearhits (ItemIndex: Integer); var n: integer; begin n: = length (editors); if ItemIndex Constructor TDBPANEL.CREATE (AOWNER: TComponent); Begin inherited Create (Aowner); Fleft: = 10; fTOP: = 10; Maxtextlen: = 100; MaxLabellen: = 100; FLINEHEIGHT: = 15; end; {Method for creating data input controls of each field} Procedure TdbPanel.createEditors (DS: TDataSource; Colcount: Integer); Var i, n, rowcount: integer; textHeight: integer; begin if DataSource.DataSet.active dam N: = DataSource.Dataset.field; {Calculated maximum title length and display length} DataSource.DataSet.First; {Calculation height} textHeight: = canvas.textHeight (DataSource .dataset.fields [0] .displayLabel) FlineHeight; File: / / 10; {calculation rantric number} RowCount: = n Div Column; if n mod column <> 0 THEN INC (Rowcount); {assigning memory} freeeditors; setlength (editors, n); setlength (labels, n); {creation Roller box} fscrollbox: = tscrollbox.create (Owner); fscrollbox.parent: = self; fscrollbox.align: = alclient; {Creation Edit} for i: = 0 to n-1 do begin {creation title} labels [i] : = TLABEL.CREATE (OWNER); Labels [i] .parent: = fscrollbox; file: // self; labels [i] .caption: = Datasource.Dataset.fields [i] .displaylabel; labels [i] .left : = FLEFT (MaxLabellen Maxtextlen 10) * (I Div Rowcount); labels [i] .width: = m Axlabellen; labels [i] .top: = ftop (i mod rowcount) * textHeiGHT 5; {Create Edit Object} Editors [i]: = TDBCOMBOX.CREATE (OWNER); Editors [i] .parent: = fscrollbox; File: // self; editors [i] .left: = labels [i] .width; editors [i] .width; editors [i] .width: = maxtextlen; Editors [i] .top: = ftop (i MOD ROWCOUNT; editors [i] .datasource: = Datasource; Editors [i] .datafield: = Datasource.DataSet.fields [i] .fieldname; editors [i] .onkeypress: = akeypress; editors [i]. ONKEYDOWN: = akeydown; end; {Create OK button} okbutton: = tbutton.create (OKButton.Parent: = FScrollBox; Okbutton.Left: = Editors [N-1] .left; okbutton.top: = Editors [N-1] .top textHeight; okbutton.caption: = 'determination'; okbutton.onclick: = fclick; End; destructor tdbpanel.destroy; begin freeeditors; inherited destroy; Function TDBPANEL.EDITOR (INDEX: Integer): TDBCOMBOBOX; Begin IF INDEX Procedure TDBPanel.FreeEditors; var i, n: integer; begin {memory release is the order! Must be carried out in the opposite order of creation! Especially when there is a parent child relationship between the components} if okbutton.free; if editors <> nil dam n: = length (editors); for i: = 0 to n-1 do editors [i] .free; editors: = NIL; N: = Length (labels); for i: = 0 to n-1 do labels [i] .free; labels: = nil; end; if fscrollbox <> nil dam fscrollbox.free ; Fscrollbox: = nil; end; end; Procedure Register; Begin RegisterComponents ('OK', [TDBPANEL]); END; End.