procedure TSensorMergeFm.ButtonWriteChangesClick(Sender: TObject);
var
s: string;
sens: TCSensor;
Sql: TStringList;
i1: Integer;
begin
Sql := TStringList.Create;
if (ListViewKnown.Items.Count > 0) then
for i1 := 0 to ListViewKnown.Items.Count - 1 do
begin
s := emptyStr;
sens := TCSensor(ListViewKnown.Items[i1].Data);
if (sens.SensorIndex > mServer.Sensors.Count) then
s := GetSensorSetup(sens.SensorType, sens.SensorIndex, sens.SerialNumber);
if (s <> emptyStr) then
Sql.Add(s);
end;
if (Sql.Count > 0) then
begin
Timer1.Enabled := False;
Conn.RemoveXBytesFromBuffer(Conn.CurrentReadBufferSize);
if Assigned(mServer.CommForm) then
TCommunicationFm(mServer.CommForm^).WriteComLn('--> UN');
Conn.WriteLn(Chr(2) + 'UN');
Conn.RemoveXBytesFromBuffer(Conn.CurrentReadBufferSize);
sleep(100);
while (Sql.Count > 0) do
begin
if Assigned(mServer.CommForm) then
TCommunicationFm(mServer.CommForm^).WriteComLn('--> ' + Sql.Strings[0]);
Conn.WriteLn(Chr(2) + Sql.Strings[0]);
Sql.Delete(0);
Delay(100);
end;
mResult := True;
//If we dont delay the connection before the PM processes the commands, it wont
//add the sensors.
Delay(700);
end else
begin
MessageDlg('No new sensors have been added.', mtInformation, [mbOk], 0);
end;
FreeAndNil(Sql);
if (mResult = True) then
ModalResult := idOk;
end;