Einzelnen Beitrag anzeigen

Gehstock

Registriert seit: 28. Jan 2006
Ort: Görlitz / Sachsen
489 Beiträge
 
Delphi 2007 Professional
 
#1

Personalausweisnummer generieren

  Alt 23. Jul 2007, 10:21
Delphi-Quellcode:
procedure TForm7.Button1Click(Sender: TObject);
var
x,y:integer;
i:Integer;
begin
i:=0;
for x := 1 to Length(Edit1.Text) do begin
y:=chartoint(Edit1.Text[x]);
  case x of
  1:i:=y*7;
  2:i:=y*3;
  3:i:=y*1;
  4:i:=y*7;
  5:i:=y*3;
  6:i:=y*1;
  7:i:=y*7;
  8:i:=y*3;
  9:i:=y*1;
 10:i:=y*7;
 //-
 // Ausgabeland
 //-
 14:i:=y*3;
 15:i:=y*1;
 16:i:=y*7;
 17:i:=y*3;
 18:i:=y*1;
 19:i:=y*7;
 20:i:=y*3;
 //-
 22:i:=y*1;
 23:i:=y*7;
 24:i:=y*3;
 25:i:=y*1;
 26:i:=y*7;
 27:i:=y*3;
 28:i:=y*1;
  end;
 i:=i+i;// Hier ist der Fehler weiß aber nicht warum er rechnet falsch zusammen
end;
Label1.caption:=InttoStr(i);
Edit2.Text:=Cut(InttoStr(i));
end;

Function TForm7.cut(a:string):string;
begin
  if length(a)>1 then begin
  Result:=a[2];
  end else
  Result:=a;
end;

function TForm7.CharToInt(C: Char):integer;
begin
  Result := 0;
  if C = '0then Result := 0;
  if C = '1then Result := 1;
  if C = '2then Result := 2;
  if C = '3then Result := 3;
  if C = '4then Result := 4;
  if C = '5then Result := 5;
  if C = '6then Result := 6;
  if C = '7then Result := 7;
  if C = '8then Result := 8;
  if C = '9then Result := 9;
end;
wobei x die Stelle im Maskedit darstellt und y den wert der stelle

aber schon bei der 1. Stelle rechnet er falsch
die 1. Stelle im Maskedit ist z.B. 7
für stelle 1. Steht im Case der Multiplikator 7-> 7*7=49

Raus hat er aber 98

Algo ist hier zu finden
Marcel
  Mit Zitat antworten Zitat