有没有人知道如何让Form不编译dfm资源文件?能够直接继承出一个窗体出来呢?
或者, 能够像TForm一样的, 这样子来新建呢?我想做的不是只是单单从一个Project里面选择现有的窗体来继承, 而是想做一个新建自己的窗体的类型可能, 极少人会需要使用到窗体的继承方法.但是, 如果按平时一样, 在工程建立个基窗体, 然后所有工程的其他窗体均由这个窗体派生出来.但是, 如果基窗体对于有继承某些组件内部的函数: 比如Loaded, SetParent, SetName等等这些函数的话, 这个就会有问题出现了.一个继承自工程基窗体, 而非 TForm的话, 那么Loaded会运行两次的, SetName也会运行两次的, 这个是很大的问题
特别是Loaded这个最麻烦大,怎样才能正确让继承Loaded的只运行一次, 并且必须是最下层的子类运行?CreateWnd也是一样, 继承多少次就会被运行多少次, 这种机制跟普通理解的继承不太一样.创建一个非继承自TForm的窗体, 都会把超类窗体资源一个一个的读入的, 而不是直接读入一次最下层的子类的DFM就算.

解决方案 »

  1.   

    由于窗体继承中,DFM文件是分开多个保存的,这决定了VCL只能把它们一个个加载进来。我倒是想了解楼主说LAODED麻烦最大是什么原因,也许你覆盖了LOADED执行了代码而导致出问题。不过就算这样,说不定有变通的方法。
      

  2.   

    嗯, 跟踪过, 我把断点设置在基窗体的Loaded, 然后打开一个继承出来的模块, Loaded居然运行两次=.= 我晕
    DFM中, 查看就会知道, 其实最下层的子类的DFM中, 里面记录的信息其实已经包含所有超类的IDE设计信息的, 根本就不用这样读入那么多次
      

  3.   

    在工程文件中创建窗体,绕过vcl
    program HardCore; uses 
        Windows, Messages; {$R *.RES} {The window procedure for our hardcore API window} 
    function WindowProc(TheWindow: HWnd; TheMessage, WParam, 
                        LParam: Longint): Longint; stdcall; export; 
    begin 
      case TheMessage of 
        {upon getting the WM_DESTROY message, we exit the application} 
        WM_DESTROY: begin 
                      PostQuitMessage(0); 
                      Exit; 
                    end; 
      end;   {call the default window procedure for all unhandled messages} 
      Result := DefWindowProc(TheWindow, TheMessage, WParam, LParam); 
    end; { Register the Window Class } 
    function RegisterClass: Boolean; 
    var 
      WindowClass: TWndClass; 
    begin 
      {setup our new window class} 
      WindowClass.Style := CS_HREDRAW or CS_VREDRAW;          {set the class styles} 
      WindowClass.lpfnWndProc := @WindowProc;                  {point to our window procedure} 
      WindowClass.cbClsExtra := 0;                            {no extra class memory} 
      WindowClass.cbWndExtra := 0;                            {no extra window memory} 
      WindowClass.hInstance := hInstance;                      {the application instance} 
      WindowClass.hIcon := LoadIcon(0, IDI_APPLICATION);      {load a predefined logo} 
      WindowClass.hCursor := LoadCursor(0, IDC_UPARROW);      {load a predefined cursor} 
      WindowClass.hbrBackground := COLOR_WINDOW;              {use a predefined color} 
      WindowClass.lpszMenuName := nil;                        {no menu} 
      WindowClass.lpszClassName := 'TestClass';                {the registered class name}   {now that we have our class set up, register it with the system} 
      Result := Windows.RegisterClass(WindowClass) <> 0; 
    end; 
    var 
      TheMessage: TMsg; 
      OurWindow: HWND; 
    begin 
      {register our new class first} 
      if not RegisterClass then 
      begin 
        MessageBox(0,'RegisterClass failed',nil,MB_OK); 
        Exit; 
      end;   {now, create a window based on our new class} 
      OurWindow := CreateWindowEx(0,                    {no extended styles} 
                                  'TestClass',          {the registered class name} 
                                  'HardCore Window',    {the title bar text} 
                                  WS_OVERLAPPEDWINDOW or {a normal window style} 
                                  WS_VISIBLE,            {initially visible} 
                                  CW_USEDEFAULT,        {default horizontal position} 
                                  CW_USEDEFAULT,        {default vertical position} 
                                  CW_USEDEFAULT,        {default width} 
                                  CW_USEDEFAULT,        {default height} 
                                  0,                    {handle of the parent window} 
                                  0,                    {no menu} 
                                  hInstance,            {the application instance} 
                                  nil                    {no additional information} 
                                  );   {if our window was not created successfully, exit the program} 
      if OurWindow=0 then 
      begin 
        MessageBox(0,'CreateWindow failed',nil,MB_OK); 
        Exit; 
      end;   {the standard message loop} 
      while GetMessage(TheMessage,0,0,0) do 
      begin 
        TranslateMessage(TheMessage); 
        DispatchMessage(TheMessage); 
      end; end. 
      

  4.   


    一个假设,那这个FORM你可能要自已建立了。你可以把DFM文件当作你的窗体的一个配置文件来处理,载入控件。 
      

  5.   

    最大的问题在于, 直接编写Window那么就不能直接进行IDE设计了, 
    那么还倒不如直接用VC, VC是不会采用这种形式的
    用DELPHI就是为了可以方便使用组件zhangxiaommmm
    说的方法可不可以具体一点? 而且, 最后一个函数, 名字也看不到