
function BarcodeAdd13_1(const Barcode :string ):string;
var i :integer;
begin
  (*
Шаг 1	Отбросить контрольный разряд (крайний справа)
Шаг 2	Сложить разряды, стоящие на четных местах
Шаг 3	Результат ШАГа 2 умножить на 3
Шаг 4	Сложить разряды, стоящие на нечетных местах
Шаг 5	Суммировать результаты ШАГов 3 и 4
Шаг 6	В полученном числе крайнюю справа цифру вычесть из 10. Полученный результат и есть значение контрольной цифры
Пример расчета контрольного разряда в коде EAN-13: 46 76221 35746 С
Шаг 1	46 76221 35746
Шаг 2	6+6+2+3+7+6=30
Шаг 3	30х3=90
Шаг 4	4+7+2+1+5+4=23
Шаг 5	90+23=113
Шаг 6	10-3=7 - bvrus - здесь нужно взять последнюю цифру от вычитания. ибо 10 - 0 = 10, а надо 0.
Полный номер EAN-13 будет следующим: 46 76221 35746 7
  *)

  Result := Barcode;
  if length(Result)=12
  then begin
    for i := 1 to length(Result) do
    if not (Result[i] in ['0'..'9']) then exit;


    Result := Result +
                       inttostr(
                        (
                          10-(
                            ((strtoint(Result[2])
                              +strtoint(Result[4])
                              +strtoint(Result[6])
                              +strtoint(Result[8])
                              +strtoint(Result[10])
                              +strtoint(Result[12])
                             ) * 3
                             +
                             (strtoint(Result[1])
                              +strtoint(Result[3])
                              +strtoint(Result[5])
                              +strtoint(Result[7])
                              +strtoint(Result[9])
                              +strtoint(Result[11])
                             )
                            )
                            mod 10
                          )
                        ) mod 10
                      );


     (*
     createhinti(
                  inttostr(
                        (
                         10-
                         (
                          (
                           (strtoint(Result[2])
                            +strtoint(Result[4])
                            +strtoint(Result[6])
                            +strtoint(Result[8])
                            +strtoint(Result[10])
                            +strtoint(Result[12])
                           ) * 3

                           +
                           (strtoint(Result[1])
                            +strtoint(Result[3])
                            +strtoint(Result[5])
                            +strtoint(Result[7])
                            +strtoint(Result[9])
                            +strtoint(Result[11])
                           )

                          )
                          mod 10
                         )

                        ) mod 10
                      )
                );

     *)
  end;

end;


begin
   // comment
   CreateHint(BArcodeAdd13('460716593254')+' : '+BArcodeAdd13_1('460716593254')); //0
   CreateHint(BArcodeAdd13('880899361342')+' : '+BArcodeAdd13_1('880899361342')); //7
end.
