procedure SyncChannel and FMX best way?

Started by Ed1966,

Ed1966

Hello,

I build a complete FMX Delphi (first time) test application for Windows, Android and MacOS.
The question is how to use the Sync the best way.
Here are three examples but is this the right way or is there a better way.
PostMessage is not a option. Please look at the code.

procedure SyncChannel(Handle: HSYNC; channel, data, user: Pointer); {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
var
  TimeSeconds: DWORD;
  NextSync: DWORD;
begin
  // Calculate time + 1 second
  NextSync := BASS_ChannelGetPosition(LocalStream, BASS_POS_BYTE) + BASS_ChannelSeconds2Bytes(LocalStream, 1);
  TimeSeconds := Trunc(BASS_ChannelBytes2Seconds(LocalStream, NextSync));

  // Set a new Sync 1 second in future time
  BASS_ChannelSetSync(LocalStream, BASS_SYNC_POS or BASS_SYNC_ONETIME, NextSync, @SyncChannel, Pointer(TimeSeconds));

  // Call Sync outside this Proc.
  // Witch one is de best or is the a different way?

//  UpdateScreen1(Integer(User)); // Option
  UpdateScreen2(Integer(User)); // Now use this one
//  UpdateScreen3(Integer(User)); // Option
end;

And the subprocs al three.
What is the best way? Please help me because after long tests sometimes AV error.

// Use Breakpoint on 'raise' for debug
procedure UpdateScreen1(Count: Integer);
begin
  try
    TThread.Synchronize(nil, procedure
    begin
      try
        Form2.Label1.Text := 'Eduard is here... ' + Count.ToString;
      except
        raise;
      end;
    end);
  except
    raise;
  end;
end;

// Use Breakpoint on 'raise' for debug
procedure UpdateScreen2(Count: Integer);
begin
  try
    TThread.CreateAnonymousThread(
      procedure
      begin
        { Standaard }
        TThread.Synchronize(TThread.Current, procedure
        begin
          { GUI }
          try
            Form2.Label1.Text := 'Eduard is here... ' + Count.ToString;
          except
            raise;
          end;
        end);
      end
    ).Start;
  except
    raise;
  end;
end;

// Use Breakpoint on 'raise' for debug
procedure UpdateScreen3(Count: Integer);
begin
  try
    Form2.Label1.Text := 'Eduard is here... ' + Count.ToString;
    Form2.Invalidate;
  except
    raise;
  end;
end;

Regards,
Eduard.

Ian @ un4seen

I'm not a Delphi user (so could be wrong) but UpdateScreen1 looks good to me. It shouldn't be necessary to create a new thread (like in UpdateScreen2) because the sync is already called in a dedicated sync thread so long as it isn't "mixtime". If it is mixtime (eg. on a decoding channel) then you can add the BASS_SYNC_THREAD flag to the BASS_ChannelSetSync call to still have it called in the dedicated sync thread.