October 29th, 2012, 10:52 PM
So finally, using show is impossible basically (the way I am doing things)? I have to use showmodal?
October 30th, 2012, 12:31 AM
That is too simplistic; but before finding some complicated way to still use Show
Originally Posted by DLPB
we need to know why ShowModal (the simplest solution) is not acceptable.
If show is required then you have to add something in the thread that keeps the thread busy
doing something until you are ready to close the form.
October 30th, 2012, 12:47 AM
The reason why I don't like showmodal is really... small. But I like to do things properly. The small issue here is that when using Showmodal, I do not know how to make the form Hide from the beginning. A modal form cannot start up invisible. It will give an error. So, I have to show it first, then onpaint tell it to hide. The result is that it flashes on and off (but obviously still works in the background).
Originally Posted by clivew
It looks unprofessional basically.
October 30th, 2012, 08:54 AM
Well, why didn't you say so from the start
The normal way to use a form this way is to create it on demand e.g.
You do not necessarily need the two local variables form2 and _mr; but that is for another day.
form2 := TForm2.Create(nil);
_mr := form2.ShowModal;
//put code here that depends upon the value of _mr
NOTE: I have not syntax checked the above code.
October 30th, 2012, 09:31 AM
Doesn't appear to work even when I corrected it (I think i did). Also, the form I make must be able to be brought back with shortcut and then hidden again by the user. At moment I can do that but as I say modal window has to be shown first.
I am not sure if your code was designed for that also?
October 30th, 2012, 10:15 AM
Of course, your context might be quite different, in fact, from what you are describing it is.
What prevents you from creating the form each time you want it?
Why do you have to hide it?
If you need it to be permanent (hide/show and not create/free) why are you creating it in a thread?
October 30th, 2012, 10:27 AM
I explained why before, if I don't create a new thread, bass.dll will crash. It must be initialised and used on a separate thread to the game. I am also analysing changes in memory (of Final fantasy 8) from the created form in the created thread (via a TTimer).
The menu is for user to change volume and display info, its also on the form.
I need it hiding until user presses a shortcut key, then it displays, then if they press again it hides.
At the moment It does this, but the form flashes on first and causes the game to lose focus and they have to reclick the game window, not to mention flashing on and off when the game starts looks bad.
The code I have so far is:
In the main DLL begin end. and the procedure is
Form 1 is the form already designed and made with the bass code and ttimer and other code present on it. Form1 does everything. It analyses memory, allows user to change volume and also plays the game music (vorbis ogg) via bass.dll using delphi bass.pas
Form1 := tForm1.create(nil);
The form MUST be present at all times, since it is working to provide the game music and checking memory addresses. See here for finished product:
Can't see menu there though he doesnt bring it up and he is using fraps for that. As you can see, music works perfectly and at this moment in time the form is hidden. It is only the initial show that is the problem. The form has to be in operation and for that I have to show it. If I could have the form use showmodal but not actually display it on FIRST show only, that would be cool. So far everything I have tried it shows for a fraction of a second beforehand. It cannot create in the background without actually displaying to the user.
edit. Another work around (for the lost focus) would be for me to somehow make ff8 focused again, but how do I do that from the dll thats been attached to the main game thread?
October 30th, 2012, 10:57 AM
Well the sloppy way around this is to set the alphablend to 0 and then make it 255 afterwards but that still doesnt address the loss of focus.
I suppose I could do that the cheapo way as well with SetForegroundWindow( HWND )
I have done this the sloppy way. Onpaint I set the foreground window by SetForegroundWindow(FindWindow(NIL,'FINAL FANTASY VIII'));
And I set the window to be alphablend 0 on a first show, eliminating the flash.
October 30th, 2012, 12:00 PM
An option I would have considered also given the detailed explanation.
The other approach that I would take myself (and I do not know enough about your situation to know if it makes sense)
would be to move all the management and persistence into a custom class and create the form on demand,
as per my example, simply to manipulate the properties of my custom class.
Or perhaps use a TDataModule for all the code and create the form on demand.
Last edited by clivew; October 30th, 2012 at 12:02 PM.
Reason: Added the TDataModule idea
October 30th, 2012, 12:04 PM
Thank you for your input on this thread. It is appreciated. I will certainly look into TDataModule at a later time
Originally Posted by clivew