Einzelnen Beitrag anzeigen

Berlinermauer

Registriert seit: 3. Okt 2007
Ort: 0x0000
213 Beiträge
 
Delphi 7 Personal
 
#10

Re: String (str[i]) funktioniert nicht

  Alt 7. Mai 2009, 20:15
stimmt geb ich was anderes ein funtzt?

ok sehe gerade bei der Zahl gehts auch.

Aber irgendwas ist dann hier falsch :

Delphi-Quellcode:
var
  Form1: TForm1;
  intcounter,intsolution,intpos: Integer;
  intstr: String;
  Wert: Array [1..8] of Integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
intstr := Edit1.Text;

Wert[8] := 1;
Wert[7] := 2;
Wert[6] := 4;
Wert[5] := 8;
Wert[4] := 16;
Wert[3] := 32;
Wert[2] := 64;
Wert[1] := 128;

intsolution := 0;

for intcounter := 0 to Length(intstr) + 1 do begin
intpos := 8 - intcounter; // Aktuelle Position
ShowMessage(intstr);
ShowMessage(intstr[4]);
ShowMessage('Int Pos : ' + IntToStr(intpos) + 'IntContent' + intstr[intpos] + 'Solution ' + IntToStr(intsolution));

  if intstr[intpos] = '0then begin
  intsolution := intsolution + 0;
  // 0
  end

  else if intstr[intpos] = '1then begin
    intsolution := intsolution + Wert[intpos];
  end
  {
  else begin
    ShowMessage('Error: Binary has other values than 0 or 1');
  end;}

end;

ShowMessage(IntToStr(intsolution));
end;
Marc S.
  Mit Zitat antworten Zitat