我写了一个通用的过滤窗体(为简单起见,叫它B窗体,要求不用模式窗体打开它),用来对别的窗体(A1,A2,A3,A4等)的DataSet 的filter属性进行修改和编辑,已获得满足要求的数据。
我现在碰到了两个问题:(假设程序运行时,Ai中有且只有一个存在,即Ai以模式窗体打开)
一是:我发现当我把Ai关掉时,B还在,我的解决方法是B.parent:=Ai;为什么不管用。
    用什么方法可以让B依附在Ai上面,随着B的关闭而不关闭?(但B不一定存在)
二是:Ai中有的用DBGrid,有的用StringGrid显示数据,用DBgrid 的好说,当filter 
改变时,里面的数据也跟着改变了,而stringgrid则要求重新运行一个将数据从dataset
读出的过程(不同的窗体又不同的过程),我不知道在什么地方(或者是哪个事件)运行这个过程。(希望您给出宝贵的意见,有描述不清的地方请提出。)我在这以前还提了两个相关的问题,结果也不是我想要得,如果你解答了,那里的分也属于你。
http://expert.csdn.net/Expert/topic/1578/1578108.xml?temp=.9226038
http://expert.csdn.net/Expert/topic/1578/1578229.xml?temp=.2755701
在线等候!!

解决方案 »

  1.   

    1. 创建B时指定Owner为Ai就行了:
      B := TFormB.Create(Ai);2. 当你设置完新的filter后就可以接着重新从dataset读出来啊。
      

  2.   

    1.你的B可以设置为unit,无窗体的那种。
    2。同意sysu(死树) ,filter后将stringgrid的数据清除,然后重新写上去。
      

  3.   

    同意一楼,
    2。可在B中filter条件改变后向B.parent(Ai)发送自定义消息,Ai收到消息后如果用的是stringgrid,则重新填充数据。
      

  4.   

    to sysu(死树) ( ) 我是这样做的,
    unitA;
    B:=TB.create(A);
    B.dataset:=A.dataset;
    B.show;unitB;
    procedure B.button1click(sender:object);
    begin
      self.dataset.filter:='Afilterstring';
      self.dataset.filtered:=true;
    end;我是在这里改变A.dataset.filter的。我觉得怎么不好加。
      

  5.   

    to  d983074(d983074) ( ) 
    给个自定义消息的例子好吗? 我重来没用过这玩意儿。
      

  6.   

    const
      wm_mymesage=wm_user+1;...
    sendmessage(tform(B.parent).handle,wm_mymessage,0,0);...
      TAiForm=class(TForm)
      ...
      private
        procdure wmmymessage(var msg:tmessage);message:wm_mymessage;
      ...procedure TAiForm.wmmymessage(var msg:tmessage);
    begin
      //do something to refresh the stringgrid
    end;
      

  7.   

    to 楼主:unitB;implementationuses unitA1, unitA2, unitA3, UnitA4;procedure B.button1click(sender:object);
    begin
      self.dataset.filter:='Afilterstring';
      self.dataset.filtered:=true;
      if self.owner = FormA1 then
        FormA1.StringGrid1. ...
      else
      if self.owner = FormA2 then
        FormA2.StringGrid1. ...
      else
      if self.owner = FormA3 then
        FormA3.StringGrid1. ...
      else
      if self.owner = FormA4 then
        FormA4.StringGrid1. ...
    end;不过这种方法不是太好,用楼上的发消息的方法会比较好,分别在各自的表单里处理。
      

  8.   

    我已经按 d983074(d983074) 的方法做好了,谢谢两位。
    sysu(死树) ( ) 、 d983074(d983074)  如果想要分的话去这两个地方签个名。http://expert.csdn.net/Expert/topic/1578/1578108.xml?temp=.9226038
    http://expert.csdn.net/Expert/topic/1578/1578229.xml?temp=.2755701