程序清单修改数据库中的记录
unit Unit;
interface
uses
Windows Messages SysUtils Classes Graphics Controls Forms
Dialogs StdCtrls Grids DBGrids ExtCtrls DB DBTables Buttons;
type
TForm = class(TForm)
DataSource: TDataSource;
customerTable: TTable;
Panel: TPanel;
DBGrid: TDBGrid;
Panel: TPanel;
UpperCaseFirstAddBtn: TButton;
UpperCaseSecondAddBtn: TButton;
MixedCaseFirstAddBtn: TButton;
MixedCaseSecondAddBtn: TButton;
BitBtn: TBitBtn;
procedure ForceCase(TargetField:String;ToUpper:Boolean)
procedure UpperCaseFirstAddBtnClick(Sender: TObject)
procedure MixedCaseFirstAddBtnClick(Sender: TObject)
procedure UpperCaseSecondAddBtnClick(Sender: TObject)
procedure MixedCaseSecondAddBtnClick(Sender: TObject)
procedure FormCreate(Sender: TObject)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form: TForm;
implementation
const
upper=true;
Mixed=False;
{$R *DFM}
Function IsUpper(ch:char)Boolean;
begin
If (ch>=A)and(ch<=Z)then
IsUpper:=true
else
IsUpper:=False;
end;
procedure TFormForceCase(TargetField:String;ToUpper:Boolean)
var
WorkBuffer:string;
i:Integer;
begin
with customerTable do
begin
DisableControls;
TRY
First; {将记录指针移到第一条记录处 }
While not EOF do
begin
WorkBuffer:=FieldByName(TargetField)AsString;
If ToUpper then
for i:= to Length(WorkBuffer)do
WorkBuffer[i]:=UpCase(WorkBuffer[i])
else
begin
for i:= to Length(WorkBuffer) do
If IsUpper(WorkBuffer[i]) then
WorkBuffer[i]:=chr(ord(WorkBuffer[i])+)
WorkBuffer[]:=UpCase(WorkBuffer[])
end;
Edit;
FieldByName(TargetField)AsString:=WorkBuffer;
post;
Next;
end;
Finally
enableControls;
end;
end;
end;
procedure TFormUpperCaseFirstAddBtnClick(Sender: TObject)
begin
ForceCase(AddrUpper)
end;
procedure TFormMixedCaseFirstAddBtnClick(Sender: TObject)
begin
ForceCase(AddrMixed)
end;
procedure TFormUpperCaseSecondAddBtnClick(Sender: TObject)
begin
ForceCase(AddrUpper)
end;
procedure TFormMixedCaseSecondAddBtnClick(Sender: TObject)
begin
ForceCase(AddrMixed)
end;
procedure TFormFormCreate(Sender: TObject)
begin
customerTableopen;
end;
end
插入和删除记录
虽然我们使用DBD或者在应用程序窗体中用TDBNavigator可以插入删除表中的记录但是任何重要的数据库应用程序都是根据最终用户的命令完成此类操作的同样如果我们掌握了字段对象及其用法修改数据库中的记录插入和删除记录将变得非常容易
[] [] [] []