Autor Beitrag
lanzelot
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 20.03.05 22:25 
Hallo zusammen

ich möchte eine zahl in einem edit eigeben
-den button clicken
-das programm sollte die länge der zahl erkennen und danach
-die ganze zahl in ein array schreiben.

ich habe das so versucht:
nehmen wir an, im edit stehe die zahl 1234

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
var myArray: Array of integer;
 l:integer;

begin
l:=Length(edit1.Text); // länge bestimmen von zahl
setlength(myArray,l);  // länge bestimmen von array


das funktioniert aber nicht.

jetzt fehlt mir auch immer noch das reinschreiben der zahl in mein array.
das programm sollte nun automatisch folgendes machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
myarray[1]:=1;
myarray[2]:=2;
myarray[3]:=3;
myarray[4]:=4;



ich habe dazu schon 2 Tutorials für Arrays durchgelesen. Die haben mir jedoch nicht weitergeholfen. Bin sehr froh, wenn mir jemand weiterhelfen kann.

verfüge über:
Delphi 6
winxp

vielen Dank

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: So 20.03.05 22:29 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var iar: array of integer;
    s: string;
    i: integer;
begin
  s := '1234';
  setlength(iar,length(s));
  for i := 1 to length(s) do
    iar[i] := strtointdef(s[i-1],0);
end;

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit


Zuletzt bearbeitet von uall@ogc am So 20.03.05 22:36, insgesamt 1-mal bearbeitet
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 20.03.05 22:32 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
 myArray: array of integer;
 i: integer;
 s: string;
begin
 s := Edit1.Text;
 SetLength(myArray,Length(s));
 for i := 0 to Length(s)-1 do
  myArray[i] := StrToInt(s[i+1]);
end;

Ist dann aber von 0 an nummeriert.

//Edit: uall war schneller, aber: s[i-1] :?: Stringposition 0 lesen kommt nicht gut ;)
lanzelot Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 20.03.05 23:50 
Vielen Dank für euere Hilfe, es hat geklappt :lol: . Mein Hauptproblem war offenbar, dass ich den text nicht als variable (s) gespeichert habe :idea: