Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
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 N0body, Feb 11, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator 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.
    
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block