Jump to content
Devis

Odd scripting lag??

Recommended Posts

Im making an app using a Tform but I have included a MMouse(); function in the script at some point and it creates massive lag? or lagging of the function for some reason when a Tform is in use..Wondered if anyone knows how to fix this or why this happens?

 

Run this script to see what I mean:

 

[scar]program New;

{.include OSI/OSI.scar}

 

var

frmDesign: TForm;

Button1: TButton;

 

procedure Button1Click(Sender: TObject);

begin

MMouse(1518, 155,0,0);

end;

 

procedure InitForm;

begin

frmDesign := CreateForm;

frmDesign.Left := 100;

frmDesign.Top := 100;

frmDesign.Width := 500;

frmDesign.Height := 500;

frmDesign.Caption := 'Test!';

frmDesign.Color := ClWhite;

frmDesign.Font.Color := ClBlack;

frmDesign.Font.Name := 'Comic Sans MS';

 

Button1 := TButton.Create(frmDesign);

Button1.Parent := frmDesign;

Button1.Left := 50;

Button1.Top := 50;

Button1.Height := 30;

Button1.Width := 120;

Button1.Caption := 'Move Mouse!';

Button1.Font.Size := 12;

Button1.OnClick := @Button1Click;

end;

 

procedure SafeInitForm;

var

v: TVariantArray;

begin

setarraylength(V, 0);

ThreadSafeCall('InitForm', v);

end;

 

procedure ShowFormModal;

begin

frmDesign.ShowModal;

end;

 

procedure SafeShowFormModal;

var

v: TVariantArray;

begin

setarraylength(V, 0);

ThreadSafeCall('ShowFormModal', v);

end;

 

begin

SetUpOSI;

SafeInitForm;

SafeShowFormModal;

end.[/scar]

 

When you click the button the mouse should just move to the co-ordinates near the top right of the screen, using the MMouse(); function but it lags like crazy when its run.

 

Devis.

Edited by Devis
Link to comment
Share on other sites

I tried changing the v's to V's and it didnt help.. just runs exactly the same. Also im not using any waitis in that script as you can see unless you mean the @ButtonClick? which is a kind of wait I supose, as its waiting for the button to be clicked before moving to the next procedure, but i dont see how that is lagging the whole thing?

 

Also can I ask if you ran the script and it lagged like crazy on your comp or is it just me?

Link to comment
Share on other sites

The Button Click is an EVENT. Forms have them built in. It has to do with Windows API whenever the form is clicked on Windows will send the message to the program. Then the event is triggered and ran. SCAR handles this fine. That is not the problem. MMouse that function look at the source code for it, it might have a wait in it. Try using MoveMouse instead see if it lags.

 

Delphi is based on Windows API, or has it built in anyway. Windows API sends and receives messages I think usually starting with WM_

 

On my phone at the moment sorry.

Edited by LordJashin
Link to comment
Share on other sites

If it is an OSI function. Try holding down Control then click the MMouse function in the script. Or look for the function in OSI I bet it uses Waits which will lag the form because everything in SCAR with forms is on one thread. So if you had a TTimer running too it would lag the form even more. Now, you can make a DLL using Delphi for SCAR (APPA for example) and have a form load from that DLL. Then the form might be able to have more threads but I doubt it. SCAR's compiler doesn't support it.

Edited by LordJashin
Link to comment
Share on other sites

I've also noticed that wait(); and sleep(); functions are ignored too... For example in the last script I posted if you change the procedure to this:

 

[scar]procedure Button1Click(Sender: TObject);

begin

MMouse(1518, 155,0,0);

Wait(5000);

MMouse(100, 100,0,0);

end;[/scar]

 

The 5 second wait is completely skipped.

 

Events for visual controls are executed in SCAR's mainthread, you should use mouse functions in there. (Because Wait calls Sleep on the thread which basically stops it for x ms.)

 

So does that mean I can't effectivly use procedures that contain visuals such as MMouse when im building a form?

Edited by Devis
Link to comment
Share on other sites

I don't understand this too much because I haven't experimented with using Waits with SCAR forms. But here is my theory. The Waits and other functions take time to execute. No 2 things can execute at the same time. So since Freddy said everything runs on the main thread even the events for the controls do. So basically your form will not update/refresh/whatever until you tell it to after that button click or whenever. Note there is TForm refresh and repaint functions. Using TTimers those use the main thread too.

 

[sCAR]

TForm.Repaint;

TForm.Refresh;

[/sCAR]

 

So I recommend using TTimers and faster functions to simulate multitasking with the form. You can hide the form and show the form too.

Edited by LordJashin
Link to comment
Share on other sites

Right ill give TTimers a look into then, because at the moment im using a variable and just counting up to simulate a wait function in my script like:

 

[scar]WaitTime:= 0;

repeat

WaitTime:=WaitTime + 1;

until WaitTime = 100000[/scar]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...