通用Delphi数据库输入控件DBPanel的实现Word文件下载.docx
- 文档编号:22296598
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:11
- 大小:18.17KB
通用Delphi数据库输入控件DBPanel的实现Word文件下载.docx
《通用Delphi数据库输入控件DBPanel的实现Word文件下载.docx》由会员分享,可在线阅读,更多相关《通用Delphi数据库输入控件DBPanel的实现Word文件下载.docx(11页珍藏版)》请在冰豆网上搜索。
ForI:
=0tom-1doEditors[ItemIndex].
Theend;
-specificapplicationisdifferent,sothecontrolalsoneedtohaveenougheventhandlingtotheprogrammerinterface,inordertorealizethefunctionofspecificapplications.Thisrequiresdefiningcertaineventprocessingmethodsinthecontroltobeimplementedbytheuser.ThisprovidesanOnOkClickevent,whichiswhathappenswhenallfieldeditorscomplete.Thecodeisasfollows:
OkButton:
TButton;
Theconfirmationbuttonforthefinalincrementof>
isusedtoimplementthesubmissionaction.
PropertyOnOkClick:
TNotifyEventreadFClick
ByimplementingtheOnOKClickmethod,userscancompletethevariousprocessingtaskssuchassubmissionanddatarationalitytesting.Anotherthingthatneedstobehandledspecificallyistheconversionbetweenfields.Thedefaultistoclickonthemouse.However,theuser'
shabitstendtobethe"
up,down,left,right"
fourarrowkeysonthekeyboard.Toimplementthisfunction,definethefollowingtwomethods:
ProcedureAKeyPress(Sender:
varKey:
Char);
ProcedureAKeyDown(Sender:
TObject;
VarKeyWord;
Shift:
TShiftState);
TheabovetwomethodsareassignedtothedynamicallygeneratedEditorstoimplementtheresponsetothearrowkeys.
Thenumberofdifferenttablefieldsisdifferent,andthereisapossibilitythattherewillbenodisplay,whichwillrequirescrollingfunctionality.So,aTscrollBoxcontrolisinsertedinthecontrol.Thelastthingtonoticeistheundoofthedynamiccontrolsandthereleaseofmemory.
Theundoandmemoryreleaseofthecontrolarrayissequential--intheexactoppositeorder.Otherwiseitwillgowrong.
Theuseofcontrols
First,placetheDBPanelcontrolontheform,thensetthedatasourceproperties,thenumberofcolumnsinthedatainputtable,andsoon.Intheprogram,whenyouopenthedatasource,themethodthatcreatesthedataeditcontrolisinvoked.Thatis:
Query1.Open;
->
opensthedatasource
DBPanel1.CreateEditors;
createstheeditcontrolforeachfield
DBPanel1.AddHits(0,'
1111'
'
11222'
eeee'
);
setsthepromptforafield
Dbpanel1.addhits(1,'
ThecontrolandthesampleprogramweredebuggedintheWin98+Delphi5.0environment.
Attachment:
thesourcecodefortheTDBPanel
TheunitDBPanel;
interface
USES
Windows,Messages,SysUtils,Classes,
Graphics,Controls,Forms,Dialogs,
ExtCtrls,DBCTRLS.
Thetype
TDBPanel=class(TPanel)
private
{Privatedeclarations}
FLeft:
FTop:
MaxTextLen:
MaxLabelLen:
FScrollBox:
TScrollBox;
{scrollcontrol}
FLineHeight:
FClick:
TNotifyEvent;
{datasource}
FDataSource:
TDataSource;
FColumns:
isthenumberofcolumnsinthetable
protected
{Protecteddeclarations}
ProcedureFreeEditors;
releasesthememoryforthedataentrycontrol
public
ProcedureCreateEditors;
//
(DS:
ColCount:
Integer);
createsdataentrycontrolsforeachfield
TheconstructorCreate(AOwner:
TComponent);
Override.
ThedestructorDestroy;
TObject;
VarKey:
VarKeyWord;
TShiftState);
ProcedureClearHits(ItemIndex:
ProcedureAddHits(ItemIndex:
AnInteger.Hits:
arrayofstring)
ThefunctionEditor(Index:
Integer):
TDBComboBox;
{Publicdeclarations}
published
ThepropertyLeftLimit:
Integerread
FLeftwriteFLeftdefault10;
ThepropertyTopLimit:
FTopwriteFTopdefault10;
ThepropertyEditorLen:
MaxTextLenwritemaxTextLen;
ThepropertyLabelLen:
MaxLabelLenwritemaxLabelLendefault100;
ThepropertyLineHeight:
FLineHeightwriteFLineHeightdefault15;
ThepropertyOnOkClick:
TNotifyEvent
ReadFClickwriteFClick;
属性数据源:
TDataSource
读FDataSource写FDataSource;
数据源
属性列:
整数阅读
FColumns写FColumns;
表列数
}{发表声明
结束;
程序注册;
实现
开始
RegisterComponents(“额外的”,[TDBPanel]);
{为第我字段增加提示信息的方法}
过程TDBPanel.AddHits(ItemIndex:
整数;
命中:
字符串数组;
m,n,我:
n:
=长度(编辑);
m:
=长度(打击);
如果ItemIndex<
n然后开始
对i:
=0到m-1做编辑器[ItemIndex].items.add(点击[i]);
过程TDBPanel.AKeyDown
(发送者:
varKey:
Word;
转变:
如果(发送方是TDBComboBox),那么开始
案件的关键
VK_Next:
TDBComboBox(发送方)
.DataSource.DataSet.Next;
VK_PRIOR:
.DataSource.DataSet.Prior;
过程TDBPanel。
AKeyPress(发送者:
Char);
如果键=#13(所有者为TForm)。
执行(WM_NEXTDLGCTL,0,0);
ClearHits(ItemIndex:
整数);
n然后编辑[ItemIndex].item。
clear;
构造函数TDBPanel。
创建(AOwner:
继承创建(AOWner);
=10;
maxTextLen:
=100;
maxLabelLen:
=15;
{创建各字段的数据输入控件的方法}
过程TDBPanel.CreateEditors;
//
TDataSource;
ColCount:
我,n,RowCount:
TextHeight:
如果DataSource.DataSet。
然后开始活跃
护士:
=DataSource.DataSet.FieldCount;
{计算最大的标题长度及显示长度}
DataSource.DataSet.First;
{计算高度}
=Canvas.TextHeight(数据源
.DataSet.Fields[0].DisplayLabel)+FLineHeight;
//10;
{计算行列数}
RowCount:
=ndiv列;
如果nmod列<
>
0,那么inc(RowCount);
{分配内存}
FreeEditors;
SetLength(编辑、n);
SetLength(标签,n);
{创建滚动盒}
=TScrollBox.Create(所有者);
FScrollBox。
父:
=自我;
对齐:
=alClient;
{创建编辑}
=0到n-1开始
{创建标题}
标签[我]:
=TLabel.Create(所有者);
[我]标签。
=FScrollBox;
//自我;
标题:
=DataSource.DataSet.Fields[我].DisplayLabel;
左:
=FLeft+(maxLabelLen+
maxTextLen+10)*(idivRowCount);
宽度:
=maxLabelLen;
顶端:
=FTop+(imodRowCount)*TextHeight+5;
{创建编辑对象}
编辑[我]:
=TDBComboBox.Create(所有者);
编辑[我]。
=[我]标签。
左+标签[我].Width;
=maxTextLen;
顶部:
=FTop+(imodRowCount)*TextHeight;
数据源:
=数据源;
DataField:
=DataSource.DataSet.Fields[我].FieldName;
OnKeyPress:
=AKeyPress;
OnKeyDown:
=AKeyDown;
{创建好按钮}
=TButton.Create(所有者);
OkButton。
=(n-1).Left编辑;
上图:
=编辑(n-1)。
前+TextHeight;
='
确定的;
OKButton。
OnClick:
=FClick;
析构函数TDBPanel.Destroy;
继承的破坏;
TDBPanel函数。
编辑器(指数:
整数):
如果索引<
长度(编辑器)结果:
=编辑器[索引]
其他结果:
=零;
过程TDBPanel.FreeEditors;
我,n:
{内存的释放是要有顺序的!
必须以创建的相反的顺序进行!
尤其是当组件之间有父子关系时}
如果OkButton<
nil,然后OkButton.free;
如果编辑器<
nil,则开始
=0到n-1编辑器[i]。
编辑:
=长度(标签);
=0到n-1做标签[我]。
标签:
如果FScrollBox<
nil开始
FScrollBox.Free;
结束。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 通用 Delphi 数据库 输入 控件 DBPanel 实现
![提示](https://static.bdocx.com/images/bang_tan.gif)