From ec596bb0c8618db889f89d5df6bbebe1d02e2383 Mon Sep 17 00:00:00 2001 From: Uladzimir Karpenka Date: Mon, 11 May 2026 18:57:26 +0300 Subject: [PATCH] fix connect --- DeviceForm.pas | 10 +++++++++- MainForm.pas | 47 +++++++++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/DeviceForm.pas b/DeviceForm.pas index 1fbaa33..317eaee 100644 --- a/DeviceForm.pas +++ b/DeviceForm.pas @@ -105,7 +105,8 @@ type function GetAutoStartBoardType: Integer; function GetSavedBoardType(Idx: Integer): Integer; - // Получить результат + // Получить/сбросить результат + procedure ClearResult; property DialogResult: TDeviceDialogResult read FResult; property OnDiscover: TNotifyEvent read FOnDiscover write FOnDiscover; property SavedCount: Integer read FSavedCount; @@ -596,6 +597,13 @@ begin ModalResult := mrCancel; end; +procedure TDeviceDialog.ClearResult; +begin + FResult.Accepted := False; + FResult.IPAddress := ''; + FResult.SavedIdx := -1; +end; + function TDeviceDialog.GetAutoStartIP: string; var I: Integer; diff --git a/MainForm.pas b/MainForm.pas index 6eb0151..23be83a 100644 --- a/MainForm.pas +++ b/MainForm.pas @@ -3285,8 +3285,10 @@ begin FDeviceDialog.OnDiscover := BtnDiscoverFromDialog; if FLightTheme then FDeviceDialog.SetTheme(LightTheme) else FDeviceDialog.SetTheme(DarkTheme); + FDeviceDialog.ClearResult; // сбрасываем старый выбор перед открытием FDeviceDialog.ShowModal; - // Результат диалога не обрабатываем здесь — START сам спросит если нужно + // Если пользователь нажал CONNECT — результат хранится в DialogResult, + // START его заберёт и использует с приоритетом над autostart end; procedure TMainForm.BtnDiscoverFromDialog(Sender: TObject); @@ -3350,26 +3352,39 @@ begin // --- START --- AutoIP := ''; FPendingBoardType := 0; - if Assigned(FDeviceDialog) then - AutoIP := FDeviceDialog.GetAutoStartIP; - if AutoIP <> '' then + // Явный выбор через CONNECT в диалоге имеет приоритет над autostart + if Assigned(FDeviceDialog) and FDeviceDialog.DialogResult.Accepted then begin - FPendingIP := AutoIP; - FPendingBoardType := FDeviceDialog.GetAutoStartBoardType; + FPendingIP := FDeviceDialog.DialogResult.IPAddress; + FPendingBoardType := FDeviceDialog.GetSavedBoardType( + FDeviceDialog.DialogResult.SavedIdx); + FDeviceDialog.ClearResult; // consumed — следующий START снова спросит end else begin - if not Assigned(FDeviceDialog) then - FDeviceDialog := TDeviceDialog.Create(Self); - FDeviceDialog.OnDiscover := BtnDiscoverFromDialog; - if FLightTheme then FDeviceDialog.SetTheme(LightTheme) - else FDeviceDialog.SetTheme(DarkTheme); - if FDeviceDialog.ShowModal <> mrOk then Exit; - if not FDeviceDialog.DialogResult.Accepted then Exit; - FPendingIP := FDeviceDialog.DialogResult.IPAddress; - FPendingBoardType := FDeviceDialog.GetSavedBoardType( - FDeviceDialog.DialogResult.SavedIdx); + if Assigned(FDeviceDialog) then + AutoIP := FDeviceDialog.GetAutoStartIP; + + if AutoIP <> '' then + begin + FPendingIP := AutoIP; + FPendingBoardType := FDeviceDialog.GetAutoStartBoardType; + end + else + begin + if not Assigned(FDeviceDialog) then + FDeviceDialog := TDeviceDialog.Create(Self); + FDeviceDialog.OnDiscover := BtnDiscoverFromDialog; + if FLightTheme then FDeviceDialog.SetTheme(LightTheme) + else FDeviceDialog.SetTheme(DarkTheme); + if FDeviceDialog.ShowModal <> mrOk then Exit; + if not FDeviceDialog.DialogResult.Accepted then Exit; + FPendingIP := FDeviceDialog.DialogResult.IPAddress; + FPendingBoardType := FDeviceDialog.GetSavedBoardType( + FDeviceDialog.DialogResult.SavedIdx); + FDeviceDialog.ClearResult; + end; end; // Создаём запись устройства из IP + BoardType из диалога если есть