元号選択式日付時刻入力コンポーネント
テストプログラム DBTest
動作確認等
Windows 7 U64(SP1) + Delphi XE Pro
plDBDateEdit のテストです。Delphi に付属の DBDEMOS を使用しています。他のデータベースコンポーネントの動作と比較確認するためのものです。
入力途中の値をデータベースに反映するために、POST 用のボタンを配置しています。TDBGrid での編集は不可にしています。
このテストプログラムは、BDE 経由で Paradox のデータベースを扱っています。
Windows Vista あるいは Windows 7 で BDE を初めて使用する場合、設定が必要です。また、このテストプログラムは、管理者権限で実行しないと、編集もデータベースの値の更新もできません。
以前のバージョンでは、アプリケーションマニフェストを添付していました。現バージョンには添付していません。
図1
設計時画面
図2
実行画面
copy code
unit DBTestUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, plDateEdit, ExtCtrls, Db, Mask, DBCtrls, DBTables,
DBGrids, Buttons;
type
TForm1 = class (TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Table1: TTable;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
plDBDateEdit1: TplDBDateEdit;
Table1CustNo: TFloatField;
Table1Company: TStringField;
Table1LastInvoiceDate: TDateTimeField;
Table1Zip: TStringField;
DBEdit3: TDBEdit;
SpeedButton1: TSpeedButton;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private 宣言 }
public
{ Public 宣言 }
end ;
var
Form1: TForm1;
implementation
{$R *.DFM}
// =============================================================================
// Formを表示したらTableをOpen
// =============================================================================
procedure TForm1.FormShow(Sender: TObject);
begin
Table1.Open;
end ;
// =============================================================================
// FormのCloseでTableもClose
// =============================================================================
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Table1.Close;
end ;
// =============================================================================
// DBBridの選択行は色を変更
// =============================================================================
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with DBGrid1 do begin
if gdSelected In State Then begin
Canvas.Brush.Color := $00EFEED3 ;
Canvas.Font.Color := clBlack;
DefaultDrawColumnCell(Rect,DataCol,Column,State);
end else begin
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end ;
end ;
end ;
// =============================================================================
// 現在の編集内容をデータベースに記録
// =============================================================================
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Table1.Edit;
Table1.Post;
end ;
end .