Skip to main content
gamedev.net
🔒 Locked

Delphi problem

Started by Viper173 Oct 29, 2002 at 12:40 PM 3 replies 450+ views
Original Post
Viper173
Viper173
I have a problem with a DelphiX component that I wanted to use. It''s taking care of creating all the network interface stuff so I pretty much save a lot of work when I manage to use it. But comonents actually require a form to drop on (unless you create them yourself). Because I don''t have a form I have problems with the following procedure : DXPlay.Create( AOwner : TComponent ) I CANT FIND the suitable component for it. I expected a TObject as parameter but TComponent is something I have no idea about... So here''s my window function: (maybe you can find something to put in there) function glCreateWnd(Width, Height : Integer; Fullscreen : Boolean; PixelDepth : Integer) : Boolean; var wndClass : TWndClass; // Window class dwStyle : DWORD; // Window styles dwExStyle : DWORD; // Extended window styles dmScreenSettings : DEVMODE; // Screen settings (fullscreen,etc...) PixelFormat : GLuint; // Settings for the OpenGL rendering h_Instance : HINST; // Current instance pfd : TPIXELFORMATDESCRIPTOR; // Settings for the OpenGL window begin h_Instance := GetModuleHandle(nil); //Grab An Instance For Our Window ZeroMemory(@wndClass, SizeOf(wndClass)); // Clear the window class structure with wndClass do // Set up the window class begin style := CS_HREDRAW or // Redraws entire window if length changes CS_VREDRAW or // Redraws entire window if height changes CS_OWNDC; // Unique device context for the window lpfnWndProc := @WndProc; // Set the window procedure to our func WndProc hInstance := h_Instance; hCursor := LoadCursor(0, IDC_ARROW); lpszClassName := ''OpenGL''; end; if (RegisterClass(wndClass) = 0) then // Attemp to register the window class begin MessageBox(0, ''Failed to register the window class!'', ''Error'', MB_OK or MB_ICONERROR); Result := False; Exit end; // Change to fullscreen if so desired if Fullscreen then begin ZeroMemory(@dmScreenSettings, SizeOf(dmScreenSettings)); with dmScreenSettings do begin // Set parameters for the screen setting dmSize := SizeOf(dmScreenSettings); dmPelsWidth := Width; // Window width dmPelsHeight := Height; // Window height dmBitsPerPel := PixelDepth; // Window color depth dmFields := DM_PELSWIDTH or DM_PELSHEIGHT or DM_BITSPERPEL; end; // Try to change screen mode to fullscreen if (ChangeDisplaySettings(dmScreenSettings, CDS_FULLSCREEN) = DISP_CHANGE_FAILED) then begin MessageBox(0, ''Unable to switch to fullscreen!'', ''Error'', MB_OK or MB_ICONERROR); Fullscreen := False; end; end; // If we are still in fullscreen then if (Fullscreen) then begin dwStyle := WS_POPUP or // Creates a popup window WS_CLIPCHILDREN // Doesn''t draw within child windows or WS_CLIPSIBLINGS; // Doesn''t draw within sibling windows dwExStyle := WS_EX_APPWINDOW; // Top level window ShowCursor(False); // Turn of the cursor (gets in the way) end else begin dwStyle := WS_OVERLAPPEDWINDOW or // Creates an overlapping window WS_CLIPCHILDREN or // Doesn''t draw within child windows WS_CLIPSIBLINGS; // Doesn''t draw within sibling windows dwExStyle := WS_EX_APPWINDOW or // Top level window WS_EX_WINDOWEDGE; // Border with a raised edge end; // Attempt to create the actual window h_Wnd := CreateWindowEx(dwExStyle, // Extended window styles ''OpenGL'', // Class name WND_TITLE, // Window title (caption) dwStyle, // Window styles 0, 0, // Window position Width, Height, // Size of window 0, // No parent window 0, // No menu h_Instance, // Instance nil); // Pass nothing to WM_CREATE if h_Wnd = 0 then begin glKillWnd(Fullscreen); // Undo all the settings we''ve changed MessageBox(0, ''Unable to create window!'', ''Error'', MB_OK or MB_ICONERROR); Result := False; Exit; end; // Try to get a device context h_DC := GetDC(h_Wnd); if (h_DC = 0) then begin glKillWnd(Fullscreen); MessageBox(0, ''Unable to get a device context!'', ''Error'', MB_OK or MB_ICONERROR); Result := False; Exit; end; // Initializes the timer used to calculate the FPS SetTimer(h_Wnd, FPS_TIMER, FPS_INTERVAL, nil); // Settings to ensure that the window is the topmost window ShowWindow(h_Wnd, SW_SHOW); SetForegroundWindow(h_Wnd); SetFocus(h_Wnd); Result := True; end; ********************************************** Is there anything of the window creation that could be regarded as DXPlay`parent component? thanx
Alimonster
Alimonster
TComponent is a class has the ability to be used at design time. It does this using an owner, which is the component responsible for managing the lifetime of the object.

For example, you could dump down a component (say, a button) onto a form. The form would be the owner of that button. When any owner dies, it kills its owned objects. This is the reason why you can place things down at design-time onto your form and run your program without problems - the objects are freed automatically.

In this case, the constructor expects a TComponent-derived class (remember that it''s just a class, nothing more). This is usually one of three things:

1) Any visual object that''s derived from TComponent (such as a form or a panel)
2) The Application object (of type TApplication)
3) nil

Each of these has a different effect. Remember that owners control the lifetime of the object. In the first case, whenever you freed the visual object then your component would be freed as well. In the second case, the application object would free your object when your program finished.

You want the 3rd one, nil. Any class is implicitly a pointer (hence the reason you have to create and free them -- you need to allocate memory so that the class points somewhere). If you specify nil then your object will not be freed until you do so explicitly. Remember to match any "Create"s with "Free"s.

MyObject := TSomeClass.Create(nil);

// do stuff

MyObject.Free; // when you''ve finished...

(Incidentally, you can use [''source]your_code_here[''/source] tags without the ''s to get a nice white syntax box.)
Viper173
Viper173
I think I already tried your third Option. NIL is not really working. The second one however looks quite interesting.
But isn''t Application an object. Remember that Create demanded a component....

thanx though
Viper173
Viper173


hr := Isee;


Qatal
Qatal
of course you could just give in to delphi and hijack your window with a rendering context...thats what i do...but then u get the vcl bloat, eh...

TApplication is descended from TComponent i believe...
die or be died...i think

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.