Autor Beitrag
Green
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Di 09.05.06 22:47 
also: habe folgenden code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
type Stringarray: array of string;

function TForm1.explode(s_divider,s_string:string) : Stringarray;
  var
    i,j: integer;
    resultarray: Stringarray;
begin
        while (i<Length(s_string)+1do
        begin
                i:=i+1;
                if s_string[i]<>s_divider then
                        resultarray[j] := resultarray[j]+s_string
                else
                        j:=j+1;
        end;
Result := resultarray;
end;

procedure TForm1.Button1Click(Sender: TObject);
  var
    laenge: integer;
begin
array1 := explode(':',Edit1.Text);
//laenge := Length(array1);
end;


die funktion explode soll mir in einem dynamischen array den string s_string an den stellen geteilt zurückgeben wo der divider s_divider vorhanden ist.

d.h.:

dynarray := explode(':','abc:def');

-->
dynarray[0] = abc
dynarray[1] = def
etc...

so wie der code aber jetzt ist kriege ich immer einen fehler (aber nicht beim kompilieren, sondern zur laufzit (!) o_O und zwar:

eine EAccess Violation ... :shock: was auch immer das ist :D

kann mir jemand helfen?

mfG Green
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 09.05.06 23:09 
Moin!

Guckst du hier. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Mi 10.05.06 13:00 
Also zuerstma vielen dank für die funktion, läuft einwandfrei, aber kannst du mir noch erklären was an meiner falsch war??

ich versteh den fehler einfach nit... der compiler übrigens auch nit :D
wär nett wenn mir jemand helfen könnt

mfG Green
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mi 10.05.06 13:13 
Die hast dein Resultarray nicht dimensioniert. Bei einem dynamsichen Array musst du vor der ersten Verwendung die mit SetLength für die benötigte Anzahl Elemente Speicherplatz reservieren.

Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Mi 10.05.06 13:15 
aha, also w#re es sinvoll zuerst die benötigten elemente zu zählen (also die trennzeichen) und dann mit setlength zu setezn oder hab ich da was falsch verstanden ?