Delphi制作的TDBEdit應用實例,實現Tdate TimePicker組件的數據感知功能,代碼如下:
001
unit
Unit1;
002
interface
003
uses
004
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
005
Dialogs, DB, StdCtrls, ADODB, Grids, DBGrids, DBCtrls, Mask, ExtCtrls,
006
Menus, ComCtrls,JPEG;
007
type
008
TForm1 =
class
(TForm)
009
ADOConnection1: TADOConnection;
010
DataSource1: TDataSource;
011
ADOQuery1: TADOQuery;
012
DBEdit1: TDBEdit;
013
Label1: TLabel;
014
Label2: TLabel;
015
Label3: TLabel;
016
Label4: TLabel;
017
Label5: TLabel;
018
Label6: TLabel;
019
DBEdit2: TDBEdit;
020
DBEdit5: TDBEdit;
021
DBEdit6: TDBEdit;
022
DBNavigator1: TDBNavigator;
023
Label7: TLabel;
024
DBText1: TDBText;
025
DBImagePhoto: TDBImage;
026
PopupMenu1: TPopupMenu;
027
MenuLoad: TMenuItem;
028
MenuDelete: TMenuItem;
029
MenuCopy: TMenuItem;
030
MenuPaste: TMenuItem;
031
MenuSaveAs: TMenuItem;
032
MenuSeperator: TMenuItem;
033
OpenDialog1: TOpenDialog;
034
SaveDialog1: TSaveDialog;
035
MenuCut: TMenuItem;
036
DBComboBox1: TDBComboBox;
037
Image1: TImage;
038
DateTimePicker1: TDateTimePicker;
039
procedure
ButtonAddClick(Sender: TObject);
040
ADOQuery1CalcFIElds(DataSet: TDataSet);
041
DBEdit3KeyPress(Sender: TObject;
var
Key:
Char
);
042
MenuLoadClick(Sender: TObject);
043
MenuDeleteClick(Sender: TObject);
044
MenuCopyClick(Sender: TObject);
045
MenuPasteClick(Sender: TObject);
046
MenuCutClick(Sender: TObject);
047
MenuSaveAsClick(Sender: TObject);
048
DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
049
DataSource1DataChange(Sender: TObject; Field: TFIEld);
050
DataSource1UpdateData(Sender: TObject);
051
DateTimePicker1KeyPress(Sender: TObject;
052
private
053
{ Private declarations }
054
public
055
{ Public declarations }
056
end
;
057
058
Form1: TForm1;
059
implementation
060
{$R *.dfm}
061
TForm1
.
062
begin
063
if
(ADOQuery1
FIEldByName(
'郵政編碼'
).Value<>null)
then
064
ShowMessage(ADOQuery1
).AsString )
065
else
066
ShowMessage(
''
067
exit;
068
//插入新記錄
069
ADOQuery1
Insert;
070
//設定字段值
071
FIEldValues[
'公司名稱'
]:=
'新建的公司'
072
'地址'
'海澱區XX路XX號'
073
'城市'
'北京'
074
'省區市'
075
//ADOQuery1.FIEldValues['郵政編碼']:='100000';
076
'地區'
'東北區'
077
'國家'
'中國'
078
'網站'
'www.None.com'
079
//提交更改
080
Post;
081
082
083
084
with
Do
085
086
'總價'
).Value:= FIEldByName(
'數量'
).Value* FIEldByName(
'單價'
).Value;
087
088
089
090
091
ShowMessage(IntToStr(ORD(Key)));
092
093
//從文件中讀取圖片並放到DBImagePhoto對象中
094
095
096
Pic:TPicture;
097
098
//設定數據集為編輯狀態,這段代碼相當於
099
//ADOQuery1.Edit;
100
DBImagePhoto
DataSource
DataSet
Edit;
101
//打開文件選擇對話框選擇文件
102
(OpenDialog1
Execute)
103
104
//創建一個TPicture對象
105
Pic:=TPicture
Create();
106
try
107
//從文件中讀取圖片
108
Pic
LoadFromFile(OpenDialog1
FileName);
109
//將圖片賦值給DBImagePhoto對象
110
Picture:=pic;
111
finally
112
//用Try...Finally結構確保新建的TPicture對象被釋放
113
Free;
114
115
116
//更新數據集
117
118
119
//刪除DBImagePhoto對象中的圖片
120
121
122
123
Picture
Bitmap:=
nil
124
125
126
//將DBImagePhoto對象中的圖片拷貝到剪切板
127
128
129
CopyToClipboard;
130
131
//從剪切板中讀取圖片到DBImagePhoto對象中
132
133
134
PasteFromClipboard;
135
136
//將DBImagePhoto對象中的圖片剪切到剪切板
137
138
139
CutToClipboard;
140
141
//將DBImagePhoto對象中的圖片保存為文件
142
143
144
(SaveDialog1
145
Graphic
SaveToFile(SaveDialog1
146
147
148
149
Button=nbNext
150
Image1
Bitmap
Assign(ADOQuery1
'照片'
));
151
152
//在該事件中設置當數據指針移動時DateTimePicker1的值相應發生變動
153
154
155
//DataSource1.DataSet=ADOQuery1
156
DateTimePicker1
Date:=DataSource1
'生日'
).AsDateTime;
157
Assign(DataSource1
158
159
//在該事件中設置當提交數據變動時,“生日”字段值的來源
160
161
162
DataSource1
).AsDateTime:=DateTimePicker1
Date;
163
164
165
166
//按下ESC鍵將取消對尚未提交的數據集的修改
167
Key=#
27
168
Cancel
169
170
171
State<>dsEdit
172
//設置數據為編輯狀態
173
174
175
176
本例效果圖: 代碼文件:unit Unit1;inte
把前兩天的門業自動計算軟件想法進行了實例化,用的DEL
圖1 軟件原理圖2、VtxtAuto接口說明De
Delphi下OpenGL2d繪圖(05)-畫圖片Bmp,一
用 Lazarus 開發 OPC Client 2 (關於L
除了通過 OnGesture 事件識別手勢, 還可以直接個