Delphi - Executable with different behavior on different machines

2

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

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

It works perfectly on my device, making the form visible gradually, around two tenths of a second, which gives a more pleasant effect. However, by copying the executable to two other devices (by the way, identical to my - same make and model), the effect takes about two seconds (!), Giving a very bad impression!

Does anyone have any idea what might be happening?

    
asked by anonymous 28.09.2017 / 15:46

1 answer

3

Usually in these cases there is some process running on the Main Thread , and delaying the execution of your Looping For. One possible solution would be to run Looping on a Secondary Thread . It 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;

In event OnActivate we create an Anonymous Thread , which will automatically be finalized after it is executed. Its processing occurs in the background until the Synchronize command is called, and only that processing occurs on the Main Thread.

    
28.09.2017 / 16:21