ttanyag
asked on
ShowModal and Menu problem
I have a problem with my ShowModal form and Menu. In the case where my application is doing a lot of processes (receiving data feed form a clientsocket, decoding the feed, loading data to memory) when i bring out a showmodal form, the application responds very very slow(about 5-10 seconds delay) that is why it looks as though it hangs. Clicking on the Menu is also really slow or sometimes does not respond anymore.
What can i do to fix this?
thanks so much ... :)
What can i do to fix this?
thanks so much ... :)
Hi TTanyaq
I sounds to me as if your application doesn't process the message queue during communication. You nedd to do this frequently.
To interrupts the execution of an application so that Windows can process the message queue write:
Application.ProcessMessage s;
I sounds to me as if your application doesn't process the message queue during communication. You nedd to do this frequently.
To interrupts the execution of an application so that Windows can process the message queue write:
Application.ProcessMessage
ASKER
I have already put application.processmessage s in certain parts of my code especially in long loops.
I got this from the internet ...
implementing ShowModal as Show ...
procedure Show_Prompt;
var
WindowList: Pointer;
begin
{Disables all forms except Form2}
WindowList := DisableTaskWindows(Form2.H andle);
try
Form2.Show;
Form2.ModalResult:=0;
Repeat
Application.ProcessMessage s;
Until Form2.ModalResult<>0;
//OnButtonClick - ModalResult is set
finally
{enable all forms again}
EnableTaskWindows(WindowLi st);
Form2.Close;
end;
end;
but it still doesn't seem to work ... and when you choose mrNo the focus goes to another application.
i think the repeat ... until still takes up a lot of processing??? even though i have placed an application.processmessage s ...
I got this from the internet ...
implementing ShowModal as Show ...
procedure Show_Prompt;
var
WindowList: Pointer;
begin
{Disables all forms except Form2}
WindowList := DisableTaskWindows(Form2.H
try
Form2.Show;
Form2.ModalResult:=0;
Repeat
Application.ProcessMessage
Until Form2.ModalResult<>0;
//OnButtonClick - ModalResult is set
finally
{enable all forms again}
EnableTaskWindows(WindowLi
Form2.Close;
end;
end;
but it still doesn't seem to work ... and when you choose mrNo the focus goes to another application.
i think the repeat ... until still takes up a lot of processing??? even though i have placed an application.processmessage
Hello ttanyag,
create a thead to
receiving data feed form a clientsocket
decoding the feed
loading data to memory ( With Synchronize )
Sample Code ( not Tested )
Type
TMyThread = Class ( tThread )
Private
mySocket : TClientSocket;
Procedure ClientRead (Sender: TObject;
Socket: TCustomWinSocket);
Protected
Procedure Execute;
Public
Constructor Create; Override;
Destructor Destory;
End;
Constructor TMyThread.Create;
Begin
Inherited Create(False);
MySocket := TClientSocket.Create....
MySocket.OnClientRead := clientRead;
End;
Destructor TMyThread.Destroy;
Begin
MySocket.Close;
MySocket.Free;
Inherited Destroy;
End;
....
....
Its just an idea ;-)
Cesario
create a thead to
receiving data feed form a clientsocket
decoding the feed
loading data to memory ( With Synchronize )
Sample Code ( not Tested )
Type
TMyThread = Class ( tThread )
Private
mySocket : TClientSocket;
Procedure ClientRead (Sender: TObject;
Socket: TCustomWinSocket);
Protected
Procedure Execute;
Public
Constructor Create; Override;
Destructor Destory;
End;
Constructor TMyThread.Create;
Begin
Inherited Create(False);
MySocket := TClientSocket.Create....
MySocket.OnClientRead := clientRead;
End;
Destructor TMyThread.Destroy;
Begin
MySocket.Close;
MySocket.Free;
Inherited Destroy;
End;
....
....
Its just an idea ;-)
Cesario
yep, a thread could be a solution,
when exactly do you display your modal form? after the "(receiving data feed form a clientsocket, decoding the feed, loading data to memory)" or during the "(receiving dat..."
if you will be showing it during processing (like displaying transfer status) don't make it modal. set FormStyle to fsStayOnTop instead and just "Show" it.
try adding processmessages() on Application.OnIdle
if you will be showing it during processing (like displaying transfer status) don't make it modal. set FormStyle to fsStayOnTop instead and just "Show" it.
try adding processmessages() on Application.OnIdle
HI,
First of all, it seems curiosly for me to see those rows
of code:
"Form2.Show;
Form2.ModalResult:=0;"
The second, I didn't understand what the problem?
The code you didn't show to us or that while your code is
processing everything seems to become frosen.
Sincerely,
Nestorua.
First of all, it seems curiosly for me to see those rows
of code:
"Form2.Show;
Form2.ModalResult:=0;"
The second, I didn't understand what the problem?
The code you didn't show to us or that while your code is
processing everything seems to become frosen.
Sincerely,
Nestorua.
i think he wants a button on the "proposed" modal form to trigger something (maybe OK, Cancel ...)
HI, piscean,
Maybe you are right but let him answer the question?
Sincerely,
Nestorua.
Maybe you are right but let him answer the question?
Sincerely,
Nestorua.
The Application.ProcessMessage s may take too much processor capacity.
I had the same problem in the past and do suggest that you add a Sleep into your loop. Please find the code below that I used to relieve the CPU in a delay loop by adding sleep(10):
procedure Delay( AMilliSeconds: integer );
var
iStartTick: longint;
begin
iStartTick := GetTickCount;
repeat
Application.ProcessMessage s;
Sleep(10);
until
((LongInt(GetTickCount) - iStartTick) >= Longint(AMilliSeconds));
end;
I had the same problem in the past and do suggest that you add a Sleep into your loop. Please find the code below that I used to relieve the CPU in a delay loop by adding sleep(10):
procedure Delay( AMilliSeconds: integer );
var
iStartTick: longint;
begin
iStartTick := GetTickCount;
repeat
Application.ProcessMessage
Sleep(10);
until
((LongInt(GetTickCount) - iStartTick) >= Longint(AMilliSeconds));
end;
ASKER
My application is a Real-Time program processing data feed form the exchange for the stock market. The showmodal form can be triggered by the user (event) may it be ordering, an error message, etc. In the case where there is a big influx of data (ex. start of trading), the application kinda hangs when a showmodal form is shown or the menu/popmenu is clicked.
I've actually worked around the showmodal problem, but my problem still is the menu. So the user is not able to use the menu (shortcut keys are not affected) when there is an influx of data coming in.
As for the code above, I just experimented with it ... got it from the internet ... It is actually kinda the same code of function ShowModal in Forms.pas.
thanks for all your suggestions
I've actually worked around the showmodal problem, but my problem still is the menu. So the user is not able to use the menu (shortcut keys are not affected) when there is an influx of data coming in.
As for the code above, I just experimented with it ... got it from the internet ... It is actually kinda the same code of function ShowModal in Forms.pas.
thanks for all your suggestions
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY. Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days. Experts, please post closing recommendations before that time.
Below are your open questions as of today. Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response. This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database. If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
--> Post comments for expert of your intention to delete and why
--> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.
For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process. https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.
Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added. When you grade the question less than an A, please comment as to why. This helps all involved, as well as others who may access this item in the future. PLEASE DO NOT AWARD POINTS TO ME.
To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20245974.html
https://www.experts-exchange.com/questions/Q.20247079.html
https://www.experts-exchange.com/questions/Q.20249274.html
https://www.experts-exchange.com/questions/Q.20300761.html
To view your locked questions, please click the following link(s) and evaluate the proposed answer.
https://www.experts-exchange.com/questions/Q.20295273.html
***** E X P E R T S P L E A S E ****** Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://www.experts-exchange.com/commspt/Q.20277028.html
Moderators will finalize this question if in @7 days Asker has not responded. This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
Below are your open questions as of today. Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response. This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database. If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
--> Post comments for expert of your intention to delete and why
--> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.
For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process. https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.
Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added. When you grade the question less than an A, please comment as to why. This helps all involved, as well as others who may access this item in the future. PLEASE DO NOT AWARD POINTS TO ME.
To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20245974.html
https://www.experts-exchange.com/questions/Q.20247079.html
https://www.experts-exchange.com/questions/Q.20249274.html
https://www.experts-exchange.com/questions/Q.20300761.html
To view your locked questions, please click the following link(s) and evaluate the proposed answer.
https://www.experts-exchange.com/questions/Q.20295273.html
***** E X P E R T S P L E A S E ****** Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://www.experts-exchange.com/commspt/Q.20277028.html
Moderators will finalize this question if in @7 days Asker has not responded. This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you could try to place some
application.processmessage
lines into your code
meikl ;-)