有没有人知道如何让Form不编译dfm资源文件?能够直接继承出一个窗体出来呢?
或者, 能够像TForm一样的, 这样子来新建呢?我想做的不是只是单单从一个Project里面选择现有的窗体来继承, 而是想做一个新建自己的窗体的类型可能, 极少人会需要使用到窗体的继承方法.但是, 如果按平时一样, 在工程建立个基窗体, 然后所有工程的其他窗体均由这个窗体派生出来.但是, 如果基窗体对于有继承某些组件内部的函数: 比如Loaded, SetParent, SetName等等这些函数的话, 这个就会有问题出现了.一个继承自工程基窗体, 而非 TForm的话, 那么Loaded会运行两次的, SetName也会运行两次的, 这个是很大的问题
特别是Loaded这个最麻烦大,怎样才能正确让继承Loaded的只运行一次, 并且必须是最下层的子类运行?CreateWnd也是一样, 继承多少次就会被运行多少次, 这种机制跟普通理解的继承不太一样.创建一个非继承自TForm的窗体, 都会把超类窗体资源一个一个的读入的, 而不是直接读入一次最下层的子类的DFM就算.
或者, 能够像TForm一样的, 这样子来新建呢?我想做的不是只是单单从一个Project里面选择现有的窗体来继承, 而是想做一个新建自己的窗体的类型可能, 极少人会需要使用到窗体的继承方法.但是, 如果按平时一样, 在工程建立个基窗体, 然后所有工程的其他窗体均由这个窗体派生出来.但是, 如果基窗体对于有继承某些组件内部的函数: 比如Loaded, SetParent, SetName等等这些函数的话, 这个就会有问题出现了.一个继承自工程基窗体, 而非 TForm的话, 那么Loaded会运行两次的, SetName也会运行两次的, 这个是很大的问题
特别是Loaded这个最麻烦大,怎样才能正确让继承Loaded的只运行一次, 并且必须是最下层的子类运行?CreateWnd也是一样, 继承多少次就会被运行多少次, 这种机制跟普通理解的继承不太一样.创建一个非继承自TForm的窗体, 都会把超类窗体资源一个一个的读入的, 而不是直接读入一次最下层的子类的DFM就算.
解决方案 »
- .......................................................................................
- CheckUserForm delphi中是否有这个组件
- 急等:ppt文件如何生成exe文件,哪位朋友知道,多谢!!!
- *********刚找到个工作,在微软做开发测试工程师好吗,是外包的,有什么要注意的,各位大哥发表下意见
- 调用printers进行打印问题
- 天啊,难道BDE QUERY不能运行带括号的SQL语句吗?
- 高手快来灭火啊~~~票据打印的问题
- sockconnection连接,请赐教,谢谢
- 使用COM时,怎么传入一个字符串?
- 在SQL2000中可以执行的存储过程,在delphi中为什么不可以呢?
- 求助二维数组定义
- TComponent构造函数
DFM中, 查看就会知道, 其实最下层的子类的DFM中, 里面记录的信息其实已经包含所有超类的IDE设计信息的, 根本就不用这样读入那么多次
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.
一个假设,那这个FORM你可能要自已建立了。你可以把DFM文件当作你的窗体的一个配置文件来处理,载入控件。
那么还倒不如直接用VC, VC是不会采用这种形式的
用DELPHI就是为了可以方便使用组件zhangxiaommmm
说的方法可不可以具体一点? 而且, 最后一个函数, 名字也看不到