Delphi - Executable with different behavior on different machines

Asked

Viewed 173 times

2

I wanted to create a transition effect to a form, so in the event OnShow, I set up the estate AlphaBlend := 0 and, in the OnActivate:

  for i := 55 to 255 do
  begin
    AlphaBlendValue := i;
    Update;
    sleep(1);
  end;

It works perfectly on my equipment, making the form become visible gradually, around two tenths of a second, which gives a more pleasant effect. However, when copying the executable to two other equipment (by the way, identical to mine - same brand and model), the effect takes about two seconds (!), giving a terrible impression!

Does anyone have any idea what might be going on?

  • It can be a delay in processing the Update command. Exchange it for Application.Processmessages and see if it produces any results.

  • Originally the command was Application.ProcessMessages. I switched to Update just imagining that there could be a queue of messages causing slowness. But the effect is the same.

  • Apart from hardware, are the software on the machines the same (or similar)? Windows? Antivirus? In task manager, the processing is similar?

  • Just one question, we’re talking about VCL or Firemonkey?

  • They are machines with similar software, even Windows, even Antivirus. I will look at the task manager. The published used is the VCL.

  • I examined the task manager and the processing of this code doesn’t seem to be weighing anything down. CPU went from 0 to 1 during a blink of an eye and the memory increases 200k while the form remains open (the program consumes just over 6Mb).

Show 1 more comment

1 answer

3

Usually in such cases there is some process being executed in the Main Thread, and delaying the execution of your Looping For. A possible solution would be to run Looping in a Secondary Thread. Would look like this:

Event OnShow:

procedure TForm1.FormShow(Sender: TObject);
begin
    AlphaBlend := true;
    AlphaBlendValue := 0;
end;

Event OnActivate:

procedure TForm1.FormActivate(Sender: TObject);
var
    MyThread: TThread;
begin
    MyThread := TThread.CreateAnonymousThread(
    procedure
    var i: Integer;
    begin
        for i := 55 to 255 do
        begin
            TThread.Synchronize(MyThread, procedure begin
                AlphaBlendValue := i;
                Update;
                sleep(1);
            end);
        end;
    end);
    MyThread.Start;
end;

At the event OnActivate we created a Thread Anonymous, which will automatically be finished after its execution. Its processing takes place in the background, until the command is called Synchronize, and only that processing takes place in the Main Thread.

  • I used the thread but the effect was the same. Only on a computer; in mine it works perfectly. I also did another experiment: I commented on the Sleep(1) command. In this case, of course, the transition effect is lost, but the goal was to test whether the problem would be in this command. The result was that the form was visible immediately, even on the problematic computer. It is clear that there is some problem in Sleep.

  • Another test, replacing Sleep(1) with: <code>for k := 0 to 500000 of ;</code>, the effect works on all computers. The problem is that in this case it would vary depending on the processor’s speed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.