熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

DELPHI基礎教程:簡單數據庫應用的創建及MASTAPP介紹(三)[2]

2022-06-13   來源: Delphi編程 

  程序清單修改數據庫中的記錄

  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可以插入刪除表中的記錄但是任何重要的數據庫應用程序都是根據最終用戶的命令完成此類操作的同樣如果我們掌握了字段對象及其用法修改數據庫中的記錄插入和刪除記錄將變得非常容易

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/Delphi/201311/25168.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.