webForumDet fria alternativet

Konvertera Char till int

4 svar · 206 visningar · startad av Alpha II

Alpha IIMedlem sedan maj 20002 993 inlägg
#1

Varför fungerar inte det här?

var
  F : TextFile;
  X : Integer;
  Y : Integer;
  S : String;
begin
  AssignFile(F, FileName);
  Reset(F);
  for X := 0 to 9 do begin
    ReadLn(F, S);
    for Y := 0 to 9 do begin
      Table[X,Y].Image := StrToInt(S[Y]); <-- Blir ett exception här när programmet körs...
      Table[X,Y].Visible := Bool(Table[X,Y].Image);
      Table[X,Y].Rect.Left := X*BlockWidth;
      Table[X,Y].Rect.Right := (X+1)*BlockWidth;
      Table[X,Y].Rect.Top := Y*BlockHeight;
      Table[X,Y].Rect.Bottom := (Y+1)*BlockHeight;
    end;
  end;
  CloseFile(F);
BeatboxMedlem sedan okt. 20013 217 inlägg
#2
Table[X,Y].Image := StrToInt(S[Y]);

Borde inte Table[X,Y].Image vara av typen TImage ?

jtMedlem sedan juni 2000350 inlägg
#3

Första tecknet i en sträng är position 1.
S := ABC
S[1] = A
Du startar din Loop på noll.

Alpha IIMedlem sedan maj 20002 993 inlägg
#4

Image är en Integer.
Det är bara vilken pattern som ska ritas (DelphiX)

BeatboxMedlem sedan okt. 20013 217 inlägg
#5

Så här stod det i hjälpen i alla fall.

StrToInt converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number. If S does not represent a valid number, StrToInt raises an EConvertError exception.

129 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
126 ms — hämta tråd, inlägg och bilagor (db)