nit pub;interfaceuses
  Windows,  Messages, SysUtils, Variants, Classes, Graphics, Controls, 
  Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls;
  procedure findword(typeform:tform;myedit:tedit;dbset:tadodataset;zdname:string;zdvalue:string;sqlstr:string);implementation
var   myedit:tedit;
      mydbgrid:Tdbgrid;
      myDataSource:Tdatasource;
      key:char;
      mymess:Tmessage;
{ mydbgrid }procedure findword(typeform:tform; myedit:tedit;dbset:tadodataset;zdname:string;zdvalue:string;sqlstr:string);
var sender:Tobject;
begin
  dbset.Close;
if myDataSource=nil then
   begin
    mydatasource:=Tdatasource.Create(nil);
    mydatasource.DataSet:=dbset;
   end;
if mydbgrid=nil then
   begin
    mydbgrid:=Tdbgrid.Create(typeform);
    mydbgrid.DataSource:=mydatasource;
    mydbgrid.Height:=200;
    mydbgrid.Width:=300;
    mydbgrid.Top:=myedit.Top+myedit.Height;
    mydbgrid.Left:=myedit.Left;
   end;
  dbset.CommandText:=sqlstr+' where '+zdname+' like "'+myedit.Text+'%"';
  dbset.Open;
end;
end.
我想在这个方法中调用myedit的onkeypress事件销毁mydbgrid及mydatasource并在myedit中返回结果。如何实现,请教高手。

解决方案 »

  1.   

    加一句myedit1.onkeypress(self)
    试试~~
      

  2.   

    多谢,试过多次,而且是这样写的myedit.onkeypress(typeform,key)都实现不了。
      

  3.   

    不只你到底是意思,你是想在myedit的onkeypress事件销毁mydbgrid及mydatasource呢,还是要调用myedit的onkeypress事件?还是只要毁mydbgrid及mydatasource?
      

  4.   

    再说myedit.onkeypress(typeform,key)中的sender是tedit不是tfrom
      

  5.   

    to wmm1977(吴明明)
    我想在这个方法中调用myedit的onkeypress事件销毁mydbgrid及mydatasource并在myedit中返回结果。如何实现?
      

  6.   

    你是想在edit中输入时自动检索是吧,最方便的方法是单独放个tfrom,提供个外部函数访问
      

  7.   

    为生么要调onkeypress释放,那没onkeypress不是不释放了,所以最好不要动态创建,用静态的,动态的没意义,onkeypress是个事件,在相应程序单元由这个事件对应的过程,调用是调用存在的过程,不是调用onkeypress事件
      

  8.   

    onkeypress只是个指针地址,执行是procname(myedit.onkeypress)(sender,key)
      

  9.   

    我这没delphi,可以说思路
    如:1做一个静态窗体,把该用的放好
    2procedure findword(myedit:tedit;zdname:string;zdvalue:string;sqlstr:string);
    var sender:Tobject;
    begin
      dbset.Close;
      //1显示窗体
      //2设置显示位置
        dbset.CommandText:=sqlstr+' where '+zdname+' like "'+myedit.Text+'%"';
      dbset.Open;
      myedit.onkeypress:=//你的函数,参数一样 ,这样当onkeypress发生时你的函数就执行了
    end;
      

  10.   

    这样存在问题,就是显示查询窗口不关闭,关闭查询窗口调用窗口,再打开一个窗口调用这个查询窗体报错,必需要在调用窗体的onclose中判断查询窗口是否释放。所以考虑动态建立。
      

  11.   

    你传入的myedit的onkeypress事件写了没有啊,要先判断他是否存在哦
      

  12.   

    to p96114(POO)
      不太明白,能不能说清楚些?