Mainfrm.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:2k
- unit Mainfrm;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, DB, DBTables, Grids, DBGrids, ExtCtrls, DBCtrls, ExtDlgs;
- type
- TfrmMain = class(TForm)
- Table1: TTable;
- DataSource1: TDataSource;
- Panel1: TPanel;
- DBGrid1: TDBGrid;
- DBImage1: TDBImage;
- DBNavigator1: TDBNavigator;
- OpenPictureDialog1: TOpenPictureDialog;
- procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
- DataCol: Integer; Column: TColumn; State: TGridDrawState);
- procedure DBImage1DblClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- frmMain: TfrmMain;
- implementation
- {$R *.dfm}
- //实现根据动物的重量分三个级别,用不同的颜色表示
- procedure TfrmMain.DBGrid1DrawColumnCell(Sender: TObject;
- const Rect: TRect; DataCol: Integer; Column: TColumn;
- State: TGridDrawState);
- begin
- if DBGrid1.DataSource.DataSet.FieldByName('Weight').AsInteger <= 10 then
- DBGrid1.Canvas.Font.Color := clRed
- else if DBGrid1.DataSource.DataSet.FieldByName('weight').AsInteger <= 20 then
- DBGrid1.Canvas.Font.Color := clBlue
- else
- DBGrid1.Canvas.Font.Color := clGreen;
- DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, state);
- end;
- //双击DBImage1组件,存取图片
- procedure TfrmMain.DBImage1DblClick(Sender: TObject);
- begin
- //判断数据集是否处于编辑或添加状态
- if (DBImage1.DataSource.DataSet.State <> dsEdit) and
- (DBImage1.DataSource.DataSet.State <> dsInsert) then
- raise Exception.Create('数据集不处于编辑或添加状态');
- if OpenPictureDialog1.Execute then
- DBImage1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
- end;
- end.