1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

IBAN Control Unit

Discussion in 'Delphi Programming' started by AdminDF, Feb 11, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Hi
    You can download iban control unit for iban.

    Download Here

    Code:
    unit IBAN;
    
    interface
    
    type
      TIBANMetrics = packed record
        nLenIBAN: Word;
        nStartBLZ: Word;
        nLenBLZ: Word;
        nStartKTO: Word;
        nLenKTO: Word;
      end;
    	TIBAN = class
    	private
      	FKTO: string;
    	  FBLZ: string;
      	FLand: string;
        FIBAN: string;
    
        procedure SetLand(const aValue: string);
        function CodiereLandIBAN(const aLand: string): string;
        function Modulo97PruefZiffer(const aIBAN:string):Integer;
        function GetIBANMetrics: TIBANMetrics;
        function PruefeIBAN: Boolean;
        function BerechneIBAN: string;
        function GetLand: string;
        function GetCountryFromIBAN: string;
        procedure SetIBAN(const aValue: string);
      public
        property Konto: string read FKTO write FKTO;
        property BLZ: string read FBLZ write FBLZ;
        property Land: string read GetLand write SetLand;
        property IBAN: string read BerechneIBAN write SetIBAN;
        property Valid: Boolean read PruefeIBAN;
    	end;
    
    implementation
    
    uses SysUtils;
    
    procedure TIBAN.SetLand(const aValue: string);
    begin
      FLand := Trim(UpperCase(Copy(aValue, 1, 2)));
    
      if (Length(FLand) < 2) then
    	  raise Exception.CreateFmt('Invalid country code: %s', [aValue]);
    end;
    
    function TIBAN.GetCountryFromIBAN: string;
    begin
      Result := Copy(FIBAN, 1, 2);
    end;
    
    procedure TIBAN.SetIBAN(const aValue: string);
    begin
    	FIBAN := aValue;
      SetLand(GetCountryFromIBAN);
    end;
    
    function TIBAN.GetLand: string;
    begin
    	if not (FLand = EmptyStr) then
      	Result := FLand
      else if not (FIBAN = EmptyStr) then
      	Result := GetCountryFromIBAN
      else
      	raise Exception.Create('No country or IBAN set');
    end;
    
    function TIBAN.Modulo97PruefZiffer(const aIBAN:string):Integer;
    const
       m36:string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var
       nCounter, nPruef : Integer;
    begin
       Result := 0;
    
       for nCounter := 1 to Length(aIBAN) do
       begin
          nPruef := Pos(aIBAN[nCounter], m36) ;
    
          if (nPruef = 0) then
             raise Exception.CreateFmt('Modulo97PruefZiffer(%s): invalid data', [aIBAN]);
    
          Dec(nPruef);
    
          if (nPruef > 9) then
          begin
             Result := Result * 10 + (nPruef div 10);
             nPruef := nPruef mod 10;
          end;
    
          Result := Result * 10 + nPruef;
          Result := Result mod 97;
       end;
    end;
    
    function TIBAN.CodiereLandIBAN(const aLand: string): string;
    var
      sLetter: Char;
    begin
      for sLetter in aLand do
        case sLetter of
          'A': Result := Result + '10';
          'B': Result := Result + '11';
          'C': Result := Result + '12';
          'D': Result := Result + '13';
          'E': Result := Result + '14';
          'F': Result := Result + '15';
          'G': Result := Result + '16';
          'H': Result := Result + '17';
          'I': Result := Result + '18';
          'J': Result := Result + '19';
          'K': Result := Result + '20';
          'L': Result := Result + '21';
          'M': Result := Result + '22';
          'N': Result := Result + '23';
          'O': Result := Result + '24';
          'P': Result := Result + '25';
          'Q': Result := Result + '26';
          'R': Result := Result + '27';
          'S': Result := Result + '28';
          'T': Result := Result + '29';
          'U': Result := Result + '30';
          'V': Result := Result + '31';
          'W': Result := Result + '32';
          'X': Result := Result + '33';
          'Y': Result := Result + '34';
          'Z': Result := Result + '35';
        else
          raise Exception.CreateFmt('Invalid country code: %s', [aLand]);
        end;
    end;
    
    function TIBAN.PruefeIBAN(): Boolean;
    var
    	sBLZ: string;
      sKTO: string;
      sIBAN: string;
      sLand: string;
      sControl: string;
    begin
    	Result := (Length(FIBAN) = GetIBANMetrics.nLenIBAN);
    
      if Result then
      begin
        sControl := Copy(FIBAN, 3, 2);
        sBLZ := Copy(FIBAN, GetIBANMetrics.nStartBLZ, GetIBANMetrics.nLenBLZ);
        sKTO := Copy(FIBAN, GetIBANMetrics.nStartKTO, GetIBANMetrics.nLenKTO);
        sLand := CodiereLandIBAN(GetCountryFromIBAN);
        sIBAN := sBLZ + sKTO + sLand + sControl;
        Result := (Modulo97PruefZiffer(sIBAN) = 1);
      end;
    end;
    
    function TIBAN.BerechneIBAN(): string;
    var
      sKTO: string;
      sIBAN: string;
      nControl: Integer;
    const
    	sSuffix = '00';
      nControlBase = 98;
    begin
      sKTO := StringOfChar('0', GetIBANMetrics.nLenKTO - Length(FKTO)) + FKTO;
      sIBAN := FBLZ + sKTO + CodiereLandIBAN(FLand) + sSuffix;
      nControl := Modulo97PruefZiffer(sIBAN);
      nControl := nControlBase - nControl;
      FIBAN := FLand + IntToStr(nControl) + FBLZ + sKTO;
      Result := FIBAN;
    end;
    
    function TIBAN.GetIBANMetrics: TIBANMetrics;
    begin
      {
      	Übersicht über die Struktur der IBAN in verschiedenen Ländern:
      	https://secure.wikimedia.org/wikipedia/de/wiki/International_Bank_Account_Number#IBAN-Struktur_in_verschiedenen_L.C3.A4ndern
      }
    
    	if (FLand = 'AT') then
      begin
      	with Result do
        begin
          nLenIBAN := 20;
          nLenBLZ := 5;
          nLenKTO := 11;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else 	if (FLand = 'BE') then
      begin
      	with Result do
        begin
          nLenIBAN := 16;
          nLenBLZ := 3;
          nLenKTO := 5;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else if (FLand = 'CH') then
      begin
      	with Result do
        begin
          nLenIBAN := 21;
          nLenBLZ := 5;
          nLenKTO := 12;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else if (FLand = 'DE') then
      begin
      	with Result do
        begin
          nLenIBAN := 22;
          nLenBLZ := 8;
          nLenKTO := 10;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else 	if (FLand = 'DK') then
      begin
      	with Result do
        begin
          nLenIBAN := 18;
          nLenBLZ := 4;
          nLenKTO := 10;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else 	if (FLand = 'FR') then
      begin
      	with Result do
        begin
          nLenIBAN := 27;
          nLenBLZ := 5;
          nLenKTO := 11;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else if (FLand = 'LI') then
      begin
      	with Result do
        begin
          nLenIBAN := 21;
          nLenBLZ := 5;
          nLenKTO := 12;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else if (FLand = 'LU') then
      begin
      	with Result do
        begin
          nLenIBAN := 20;
          nLenBLZ := 3;
          nLenKTO := 17;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else if (FLand = 'NL') then
      begin
      	with Result do
        begin
          nLenIBAN := 18;
          nLenBLZ := 4;
          nLenKTO := 10;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else if (FLand = 'CZ') then
      begin
      	with Result do
        begin
          nLenIBAN := 24;
          nLenBLZ := 4;
          nLenKTO := 16;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else if (FLand = 'PL') then
      begin
      	with Result do
        begin
          nLenIBAN := 28;
          nLenBLZ := 7;
          nLenKTO := 16;
          nStartBLZ := 5;
          nStartKTO := nStartBLZ + nLenBLZ;
        end;
      end
      else
      	raise Exception.CreateFmt('Country (%s) not supported yet', [FLand]);
    end;
    
    end.
    
     
    roma89 likes this.

Share This Page