Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   Problem handling messages? (http://www.delphipages.com/forum/showthread.php?t=218667)

walker1 04-11-2019 11:15 AM

Problem handling messages?
 
I am using Delphi 6 on Win 7 32 bit.


My .exe files all work, but if I run from within the IDE, my apps will not handle incoming messages from other applications. :mad: I use a LOT of those messages!



Which flags do I have to adjust?


Windows directory attributes, Delphi IDE and/or debug flags or .. ?


I also seem to have problems with breakpoints. Every now and then they seem to be disabled at run time.



I do have administrator privileges, directories should all be fully accessible etc, but I may have missed something?

walker1 04-24-2019 08:14 AM

So far no answers?!
Maybe I should put in some more specifics?


I use messaging inside and between applications.
Almost all message numbers are in the WM_App and WM_User ranges (external and internal respectively)


At startup I search for wanted forms of other apps and then transmit the current apps handle to them.
All transmitting is done using SendMessage, and finding external forms is done with FindWindow.


The code below is (part of) the seeker for external apps.
(Sorry about the indents, I can not figure out how to get them to show properly)



procedure MesToDebug(MesID : integer; wParam : cardinal; lParam : integer);
begin
if DebugWindow<>0 then
sendmessage(DebugWindow, MesID, wParam, lParam);

end;

procedure FindOthers(OwnWindow : THandle; OwnID : integer);
begin
MySelfWindow:=OwnWindow;
MySelfID:=OwnID;

if MySelfID <>RemoteID then
begin
RemoteWindow:=findwindow(pchar('TRemoteform'),pcha r('MRS Remote Display'));
MesToRemote(MRS_WinIdentify, MySelfID, MySelfWindow);
end;

if MySelfID <>DisplayID then
begin
DisplayWindow:=findwindow(pchar('TMainform'),pchar ('MRS Live Display'));
MesToDisplay(MRS_WinIdentify, MySelfID, MySelfWindow);
end;

if MySelfID <>DebugID then
begin
DebugWindow:=findwindow(pchar('TDbgForm'),pchar('M RS Debug Status'));
MesToDebug(MRS_WinIdentify, MySelfID, MySelfWindow);
end;
end;



The code below receives the form handle from relevant just started external apps.


private
procedure WinIdentify(var mes : Tmessage); message MRS_WinIdentify;




procedure Tmainform.WinIdentify(var mes : Tmessage);
Begin
with mes do
case wparam of
ControlID : Controlwindow := lparam;
RemoteID : Remotewindow := lparam;
DebugID : DebugWindow:=lParam;
end;

end;


Under XP this all worked perfectly from within the IDE and as .exe.
Under Win 7 (32 bit), however, incoming messages, and at least to some extend breakpoints, are not handled when running from within the IDE.
Outgoing messages work fine, and the correct handle for a form is received in apps run as .exe.

Running one app from the IDE and then starting another does produce the correct handle to the IDE form, when the newly started .exe seeks it.
But the IDE run app never receives the handle to the .exe.



How to change that?

rojam 04-24-2019 01:16 PM

Since you want all the applications to have a unique message number for MRS_WinIdentify, you should be registering the message using the windows RegisterWindowMessage function from all your applications. The first app that runs RegisterWindowMessage gets the message number, all subsequent apps that run it, get the same message number as the 1st one, ensuring all of them get the same reference. Since you mention that all messages are in the WM_APP and WM_USER space, it leads me to believe you are just declaring it as a constant. Check reference here.

walker1 04-25-2019 06:51 AM

Quote:

Originally Posted by rojam (Post 235247)
Since you want all the applications to have a unique message number for MRS_WinIdentify, you should be registering the message using the windows RegisterWindowMessage function from all your applications. The first app that runs RegisterWindowMessage gets the message number, all subsequent apps that run it, get the same message number as the 1st one, ensuring all of them get the same reference. Since you mention that all messages are in the WM_APP and WM_USER space, it leads me to believe you are just declaring it as a constant. Check reference here.

As I read the Win32 help file, RegisterWindowMessage should only be needed if I use broadcasting.

And I fail to see, why that use would make a difference between .exe and IDE execution of my code. Of course, I graduated in 1980, so I may not be too sharp anymore :rolleyes:

I lean more towards some flag or setting (or blockade?) in Windows 7 (32 bit), the IDE or the shortcut wrapper I use to start the IDE with.
I have tried setting compatibility to XP SP3, but it does not seem to change much. My breakpoints may work better without it, but messages do not get handled by my code. XP or not.
The messages do get handled, however, because I see no blocking.

What does the handling so the transmitting code can continue?

On the other hand, the IDE does takes forever to start my code, and the same happens should the IDE react to a breakpoint. With Integrated Debugging disabled, the code starts immediately! Message handling is still off, however.

Norrit 04-25-2019 02:09 PM

Delphi 6 is from 2001, so you're relying on a 18 year old help file which has API references of windows 2000?

Not to be rude or anything, but back in the day Delphi 6 (as for any even delphi release up to that point) didn't have a good track record of being good and stable.
But I would be carefull to assume that all API of windows 2000 is still compatible with newer windows versions...

As for you problem, I have no clue, the code samples don't provide any real logic of the problem.
Perhaps it's as simple as that it cannot find a window, because run as administrator for example ads administrator to the caption. And since you find windows by caption this could already result in a non-responsive situation.
But again, with the code provided it's not possible to figure these things out (and to be honest, I don't have Delphi 6 so if it's version related, what I don't assume in this case but just to note it, it's imposible to answer).

But what does your debugger say, just add some logs at all points to see if al variables are correctly filled.

Glenn1234 04-28-2019 06:52 AM

I gather this is a transition between Windows XP and Windows 7? Note on Windows 7 there's a lot more security measures put in that are intended to keep certain things from happening.


As an initial step, I will point out that Delphi has to have the same permissions as the applications you need to debug. So if you use "Run as administrator" or the like to run your programs otherwise, you have to do the same with Delphi to debug these programs. Try that, and if your programs debug okay, you know what you'll need to do.


I had to do this with my Delphi 3 in going away from Windows XP. More or less, you can find the executable where you have it installed and set the file to permanently run as administrator if you find out that these programs will debug fine after simply right-clicking the icon and using that option.


All times are GMT. The time now is 12:57 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.