delphi - Focus control in a frame -
i hope can explain wich prblem i'm trying solve. i've form 3 papnels: 1 buttons, 1 data, , 1 messages. data panel populated frames (one each database table need use). table detail frame , used display record in grid manipulated interface.
here grid frame:
unit fraedtlist; interface uses winapi.windows, winapi.messages, system.sysutils, system.variants, system.classes, vcl.graphics, vcl.controls, vcl.forms, vcl.dialogs, vcl.grids, vcl.dbgrids; type tfraedtlst = class(tframe) grdeditori: tdbgrid; private { private declarations } public { public declarations } end; implementation {$r *.dfm} uses database; end.
and here detail frame:
unit fraedtdetail; interface uses winapi.windows, winapi.messages, system.sysutils, system.variants, system.classes, vcl.graphics, vcl.controls, vcl.forms, vcl.dialogs, vcl.stdctrls, vcl.mask, vcl.dbctrls; type tfraedtdtl = class(tframe) lblideditore: tlabel; edtideditore: tdbedit; lbldsceditore: tlabel; edtdsceditore: tdbedit; private { private declarations } public { public declarations } end; implementation {$r *.dfm} uses database; { tfraedtdtl } { tfraedtdtl } end.
here interface unit:
unit editori; interface uses fraedtlist, fraedtdetail; type ieditori = interface procedure createfraedtlst(); procedure createfraedtdtl(); end; teditori = class(tinterfacedobject, ieditori) private fedtlst: tfraedtlst; fedtdtl: tfraedtdtl; procedure createfraedtlst(); procedure createfraedtdtl(); end; implementation { tautori } uses tabelle; procedure teditori.createfraedtlst; begin fedtlst := fedtlst.create(frmtabelle); fedtlst.parent := frmtabelle.pnldta; end; procedure teditori.createfraedtdtl; begin fedtdtl := tfraedtdtl.create(frmtabelle); fedtdtl.parent := frmtabelle.pnldta; end; end.
i've added "editori" unit form use frames. example i've not used grid, detail frame , when user select table records shows following sample:
for example first button (that blank paper) used insert new record in database table, second 1 used edit current shown record , on.
the proble tha focus dbedit component when user click "new" button or "edit" button, can't reach way kind of operation.
here source of tha use 2 frames (and others)
unit tabelle; interface uses winapi.windows, winapi.messages, system.sysutils, system.variants, system.classes, vcl.graphics, vcl.controls, vcl.forms, vcl.dialogs, vcl.extctrls, rzpanel, dxbevel, vcl.buttons, pngspeedbutton, autori, editori, dbinterface, dbimplementation, msaccess; type tfrmtabelle = class(tform) pnlcmd: trzpanel; pnldta: trzpanel; pnlmsg: trzpanel; bvlcmd: tdxbevel; bvlnav: tdxbevel; btnnew: tpngspeedbutton; btnedit: tpngspeedbutton; btnsave: tpngspeedbutton; btndelete: tpngspeedbutton; btnundo: tpngspeedbutton; btnprior: tpngspeedbutton; btnnext: tpngspeedbutton; procedure formcreate(sender: tobject); procedure btnnewclick(sender: tobject); procedure btnsaveclick(sender: tobject); procedure btnpriorclick(sender: tobject); procedure btnnextclick(sender: tobject); procedure btneditclick(sender: tobject); procedure btndeleteclick(sender: tobject); procedure btnundoclick(sender: tobject); private fdbtable: idbtable; fautori: iautori; feditori: ieditori; public procedure setbuttonsstatus(stsnew, stsedit, stssave, stsdelete, stsundo, stspnldta: boolean); procedure settablename(table: tmstable); end; var frmtabelle: tfrmtabelle; implementation {$r *.dfm} { tfrmtabelle } { inizializzazione } procedure tfrmtabelle.formcreate(sender: tobject); begin fdbtable := tdbtable.create; end; { impostazione tabella di lavoro } procedure tfrmtabelle.settablename(table: tmstable); begin fdbtable.dbtable := table; setbuttonsstatus(true, true, false, true, false, false); // tabella autori if table.tablename = 'autori' begin if not assigned(fautori) begin fautori := tautori.create; fautori.createfraautdtl; end; end; // tabella editori if table.tablename = 'editori' begin if not assigned(feditori) begin feditori := teditori.create; feditori.createfraedtdtl; end; end; end; { impostazione pulsanti } procedure tfrmtabelle.setbuttonsstatus(stsnew, stsedit, stssave, stsdelete, stsundo, stspnldta: boolean); var flgtblempty: boolean; begin flgtblempty := fdbtable.tableisempty; btnnew.enabled := stsnew; btnedit.enabled := stsedit , not flgtblempty; btnsave.enabled := stssave; btndelete.enabled := stsdelete , not flgtblempty; btnundo.enabled := stsundo; pnldta.enabled := stspnldta; end; { inserimento nuovo record } procedure tfrmtabelle.btnnewclick(sender: tobject); begin if fdbtable.newrecord setbuttonsstatus(false, false, true, false, true, true); end; { editazione record } procedure tfrmtabelle.btneditclick(sender: tobject); begin if fdbtable.editrecord setbuttonsstatus(false, false, true, false, true, true); end; { salvataggio record } procedure tfrmtabelle.btnsaveclick(sender: tobject); begin if fdbtable.saverecord setbuttonsstatus(true, true, false, true, false, false); end; { cancellazione record } procedure tfrmtabelle.btndeleteclick(sender: tobject); begin if fdbtable.deleterecord setbuttonsstatus(true, true, false, true, false, false); end; { annulla l'operazione in corso } procedure tfrmtabelle.btnundoclick(sender: tobject); begin if fdbtable.undorecord setbuttonsstatus(true, true, false, true, false, false); end; { record precedente } procedure tfrmtabelle.btnpriorclick(sender: tobject); begin if fdbtable.priorrecord setbuttonsstatus(true, true, false, true, false, false); end; { record successivo } procedure tfrmtabelle.btnnextclick(sender: tobject); begin fdbtable.nextrecord; end; end.
as can see in above code database used via interface! hope clear in explication, know question bit complicate tell. can, please, me?
the interface ieditori need expanded give outer controlling form way inform interface needed. example interface have methods addingrecord, savingrecord, validaterecord, etc. parent form not need know individual controls on frame, frame can told happening , react correctly setting focused control. there may other things want new record defaulting values or setting additional state.
you can figure things out handling events directly table such onnewrecord, when passing table around need make sure don't step on events set elsewhere.
Comments
Post a Comment