有时delphi的问题比较怪,你在函数里面再定义一下变量试试,如下:
function TFormMainWindow.LoadChildWindow(InstanceClass : TcomponentClass; var Reference) : Boolean;
var                                        <-----
     InstanceClass : TcomponentClass;      <-----
begin
  Application.CreateForm(InstanceClass, Reference);
  Reference.Parent := FormMainWindow.PanelClient;
  //运行到上面出错了,Reference是个参数,若不在此函数内,这里用的是窗口对象名
  Reference.Show;
  Result := True;
end;

解决方案 »

  1.   

    把函数改一下下,还有条编译错误:-(
    procedure TFormMainWindow.LoadChildWindow(InstanceClass : TcomponentClass; var Reference; OpenWindowID : integer; LoadingString, LoadOverString : string);
    var
      Instance: TComponent;
      FMainForm: TForm;
    begin
      Instance := TComponent(InstanceClass.NewInstance);
      TComponent(Reference) := Instance;
      try
        Instance.Create(Self);
      except
        TComponent(Reference) := nil;
        raise;
      end;
      if (FMainForm = nil) and (Instance is TForm) then
      begin
        TForm(Instance).HandleNeeded;
        FMainForm := TForm(Instance);
      end;  //FormMainWindow.MainStatusBar.Panels.Items[0].Text := LoadingString;
      //FormMainWindow.MainStatusBar.Refresh;
      //FormMainWindow.FreeChildWindow();
      //Application.CreateForm(InstanceClass, Reference);
      FMainForm.Parent := FormMainWindow.PanelClient;
      FMainForm.Show;
      //FormMainWindow.OpenWindowID := OpenWindowID;
      //FormMainWindow.MainStatusBar.Panels.Items[0].Text := LoadOverString;
    end;错误:Variable 'FMainForm' might not have been initialized
    好,我试一下您说的办法:-)
      

  2.   

    可以定义变量,若和参数名相同就不可以(当然不行)就我上面说的办法其实就是Application.CreateForm的函数原型。里面的FMainForm是在模块里面定义的
    根据编译错误,我加了条  FMainForm := nil; 在FMainForm的这行
    if (FMainForm = nil) and (Instance is TForm) then前面,问题解决了不知算算不根本解决,还是说只是乱摆平了。因为我实在不能理解这段代码