var
  tmpForm: TForm;  procedure tmpFormClose(Sender: TObject;
    var Action: TCloseAction);
  begin
    showmessage('');
  end;  function getshareForm: TForm;
  var
    tmpForm: TForm;
  Begin
    Result := Nil;
    tmpForm := TForm.Create(application);
    tmpForm.OnClose := tmpFormClose;//此处报错5~5555~
    Result := tmpForm;
  End;
错误信息:
[Error] DM.pas(220): Incompatible types: 'method pointer and regular procedure'
请问该怎么改呀?谢谢!~

解决方案 »

  1.   

    procedure TForm.tmpFormClose(Sender: TObject;
        var Action: TCloseAction);
      begin
        showmessage('');
      end;函数要放到你的Form类里面。
      

  2.   

    TO: gzmhero(hihihi) 
    但是我的Form是动态生成的呀:(
      

  3.   

    一定要是类成员函数,否则函数的参数是不匹配的。当用类来引用类方法时,除了一般的参数外,实际上还隐含传递了Self 参数,这个参数总是表示该类方法声明所在的类。事件函数放到你的主窗体里面。
      

  4.   

    从TFrom类继承一个新类,重载OnClose事件,然后创建自己的Form类
      

  5.   

    同意gzmhero(hihihi) 也可以自定义一个TMyForm:= class(TForm),
    并定义onclose事件为你的tmpFormClose之后你的代码就可以这样写了var
      tmpForm: TmyForm;  function getshareForm: TmyForm;
      var
        tmpForm: TmyForm;
      Begin
        Result := Nil;
        tmpForm := TmyForm.Create(application);
        Result := tmpForm;
      End;
      

  6.   

    tmpForm.OnClose := tmpFormClose(tmpForm,caFree);
      

  7.   

    谢谢各位
    TO: sunmingdong() 根据你的提示,写了一个类,但是会出现下面的错误:
    Project Ogl.exe raised exception class EResNotFound with message 'Resource TShareForm not found'. Process stopped. Use Step or Run to continue.
    是不是还得先注册一个这个类呢?该怎样注册?
      

  8.   

    补充,我的代码如下:
    unit uCreateShareForm;interfaceuses
      Forms, ExtCtrls, ParentForm, Dialogs, ActnList, Controls;Type
      TShareForm = Class(TForm)
      private
        FNeedQuery: Boolean;
        procedure tmpFormClose(Sender: TObject; var Action: TCloseAction);
        procedure tmpExitExecute(Sender: TObject);
        procedure ShareFormCloseQuery(Sender: TObject;
          var CanClose: Boolean);
      public
        procedure InitializeValue;
      published  End;  procedure CustomFShowPanel(FPanel: TPanel;FNeedQ: Boolean;FForm: TForm);
    implementationprocedure CustomFShowPanel(FPanel: TPanel;FNeedQ: Boolean;FForm: TForm);
    var
      H,W: integer;
      tmpShareForm: TShareForm;
      function getshareForm: TShareForm;
      Var
        tmpShareForm: TShareForm;
      Begin
        tmpShareForm := TShareForm.Create(application);
        tmpShareForm.initializeValue;
        tmpShareForm.OnClose := tmpShareForm.tmpFormClose;
        tmpShareForm.OnCloseQuery := tmpShareForm.ShareFormCloseQuery;
      End;
    begin
        H := FPanel.Height;
        W := FPanel.Width;
      try
        tmpShareForm := getShareForm;
        tmpShareForm.FNeedQuery := FNeedQ;
        tmpShareForm.Height := FPanel.Height + 10;
        tmpShareForm.Width := FPanel.Width + 10;    FPanel.Parent := tmpShareForm;
        FPanel.Align := alClient;
        FPanel.Visible := true;
        tmpShareForm.ShowModal;
      finally
        FPanel.Align := alNone;
        FPanel.Height := H;
        FPanel.Width := W;
        FPanel.Parent := FForm;
        FPanel.Visible := false;
        tmpShareForm.Destroy;
      end;
    end;procedure TShareForm.tmpExitExecute(Sender: TObject);
    begin
      IF FNeedQuery Then
         Tf_ParentForm(CurrentForm).Button3Click(nil);
    end;procedure TShareForm.InitializeValue;
    begin
      FNeedQuery := False;
    end;procedure TShareForm.tmpFormClose(Sender: TObject;
      var Action: TCloseAction);
    beginend;procedure TShareForm.ShareFormCloseQuery(Sender: TObject;
      var CanClose: Boolean);
    begin
      IF FNeedQuery Then
         Tf_ParentForm(CurrentForm).Button3Click(nil);
    end;end.
      

  9.   

    TShareForm这个类要有相应的dfm吧
      

  10.   

    生成的这个类需要有dfm的,作为你的动态生成form的模板