当前位置:首页
开发技术指南» 文章正文
    引言:

    摘要: 我用c++builder5编数据库程序,用access建了个表,但是无法插入数据 我是这样写的 form1->table1->open(); form1->table1->insert(): form1->table1->fieldbyname("日期")=edit1->text; 日期是我在表中的字段,在我得程序中可以打开表,......
    摘要: 我编了一个rs232串口通讯程序,接受采集器的数据,然后打包放到数据库里。可是程序执行几分钟后,发生异常错误“insufficient memoary for this operation".请问这是什么原因造成的错误?怎么解决? ......


新手上路:第一课:操作DBGrid;(您是高手吗嘻嘻嘻,那就不用进来啦)

新手上路:第一课:操作DBGrid;  
  DBGrid是我们数据库编辑中不可缺少的一个控件,如果能对它进行熟练的操作,会让程序更人性化;  
  以下就以一个对DBGrid的操作为例来说明如何改变DBGrid的背景、和对其进行编辑  
  ---------------------------------------------------------  
  unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls,   DBCtrls,   DB,   DBTables,   Grids,   DBGrids;  
   
  type  
      TForm1   =   class(TForm)  
          DataSource1:   TDataSource;  
          DBGrid1:   TDBGrid;  
          Table1:   TTable;  
          DBComboBox1:   TDBComboBox;  
          procedure   DBGrid1DrawDataCell(Sender:   TObject;   const   Rect:   TRect;  
              Field:   TField;   State:   TGridDrawState);  
          procedure   DBGrid1ColExit(Sender:   TObject);  
          procedure   DBGrid1KeyPress(Sender:   TObject;   var   Key:   Char);  
          procedure   DBGrid1DrawColumnCell(Sender:   TObject;   const   Rect:   TRect;  
              DataCol:   Integer;   Column:   TColumn;   State:   TGridDrawState);  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
  var  
      Form1:   TForm1;  
   
  implementation  
   
  {$R   *.dfm}  
   
  procedure   TForm1.DBGrid1DrawDataCell(Sender:   TObject;   const   Rect:   TRect;  
      Field:   TField;   State:   TGridDrawState);  
  begin  
  if   (gdFocused   in   State)   then  
        begin  
          if   (   Field.FieldName   =   DBComboBox1.DataField   )   then  
          begin  
              DBComboBox1.Left   :=   Rect.Left   +   DBGrid1.Left;  
              DBComboBox1.   :=   Rect.   +   DBGrid1.top;  
              DBComboBox1.Width   :=   Rect.Right   -   Rect.Left;  
              DBComboBox1.Height   :=   Rect.Bottom   -   Rect.;  
              DBComboBox1.Visible   :=   True;  
          end;  
      end;  
  end;  
   
  procedure   TForm1.DBGrid1ColExit(Sender:   TObject);  
  begin  
      If   DBGrid1.SelectedField.FieldName   =   DBComboBox1.DataField   then  
      begin  
          DBComboBox1.Visible   :=   false;  
      end;                        
  end;  
   
  procedure   TForm1.DBGrid1KeyPress(Sender:   TObject;   var   Key:   Char);  
  begin  
      if   (key   <>   chr(9))   then  
      begin  
          if   (DBGrid1.SelectedField.FieldName=DBComboBox1.DataField)   then  
          begin  
              DBComboBox1.SetFocus;  
              SendMessage(DBComboBox1.Handle,   WM_Char,   word(Key),   0);  
          end;  
      end;  
  end;  
   
  procedure   TForm1.DBGrid1DrawColumnCell(Sender:   TObject;   const   Rect:   TRect;  
      DataCol:   Integer;   Column:   TColumn;   State:   TGridDrawState);  
  begin  
      if   Table1.FieldByName(SIZE).AsInteger   =   2   then//仅仅是一个例子罢了  
      begin  
          DBGrid1.Canvas.Font.Color:=clred;  
          DBGrid1.Canvas.Brush.color:=clyellow;  
      end   else  
      begin  
          DBGrid1.Canvas.Font.Color:=clblue;  
          DBGrid1.Canvas.Brush.color:=clBtnFace;  
      end;  
      DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);//这一步不可少的,嘻嘻嘻嘻,俺不喜欢偷懒的;  
  end;  
   
  end.  
  ------------------------------------------------------------------  
  当然,您可以用TComboBox或者是TListBox都可以,在这我,我用的是TDBComboBox,用它有一个好处就是它可以自动的检索数据集里的数据(和放在DBGrid外边不一样的);  
   
 

NO.1   作者: shinomori0692

good

NO.2   作者: chll

very   good

NO.3   作者: xjl

好人

NO.4   作者: wgjsoft

这些都是操作dbgrid的经典用法啊

NO.5   作者: Esengnet

不錯,這項技術,我也是前幾天學到的。

NO.6   作者: wang81lei

难得你这么有心,只不过注释少了点,呵呵!

NO.7   作者: sky_yy

不錯  
  想你學習

NO.8   作者: hansonboy

如果再加一些注释就更好了

NO.9   作者: delphi_han

好心人!!

NO.10   作者: forfoo

订张座位  
  洗眼以对  
 

NO.11   作者: jianlinlong

up

NO.12   作者: linbee

ihihonline   (小小-&gt;不要再流浪!!)    
  你为什么有200啊?

NO.13   作者: sunny518

接分!  
  谢谢

NO.14   作者: eulb

CSDN多点这些帖子就是我辈之福了  
   
  小小,辛苦你了  
   
  不过最好能把所有的这些基本内容都放在一起,放在TOP  
  象ASM论坛一样  
   
  支持

NO.15   作者: lwk_hlj

我来要分的,好久没发言了

NO.16   作者: cgh1970

up

NO.17   作者: DJ_KK

人家贴出来你爱看就看不爱看拉倒,批夸什么啊~

NO.18   作者: xxyzjf

学习dbgrid,还有楼主的精神!  
  希望早日也多几颗星!本不想劳各位兄长的,但希望多几颗星,所以还是原谅我吧!  
   
  http://www.csdn.net/expert/topic/965/965509.xml?temp=.7913019

NO.19   作者: xylyge

我试过了,不过有问题,也不是从你这学的,前三个过程中,当你改变了DBGRID的字段时和QUERY中的字段改变时,问题就出现了,也请大家测试一下

NO.20   作者: dongxsoft

支持,收藏,呵呵


    摘要: 请问怎样可以让邮件连接默认的为outlook而不是outlookexpress ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE