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



BeitragVerfasst: Mo 02.12.02 19:02 
servus

wie kann ich test aus einer text datei in mehrere Listboxen einfügen?
der code unten macht es mit 2 sachen, die duch das = gtrennt sind.
ich möchte aber das es in 4 boxenaufgeteilt wird.
also der text steht so in der datei

ich=100=77=877
du=100=55=877

kann mir jemand wieter helfen?

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
const 
  FileName = 'test.txt'; 
  Seperator = '='; 
  
procedure Button1Click( sender: TObejct); 
var 
  f : TextFile; { ? } 
  a : string; 
  i      : integer; 
begin 
  AssignFile( f, FileName); 
  Reset( f); 
  while not( EoF( f)) do 
  begin 
      ReadLn( f, a); 
      i := Pos( Seperator, a); 
      Listbox1.Items.Add( Copy( a, 1, i-1)); 
      Listbox2.Items.Add( Copy( a, i+1, Length( a)); 
  end; 
    CloseFile( f); 
end;
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Mo 02.12.02 19:41 
Hi,

bitte verwende die Code-Tags. Ich habe sie jetzt mal hinzugefügt.

Gruß
Klabautermann
Savage
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110



BeitragVerfasst: Mo 02.12.02 20:11 
Hi,

ich hab mal auf der schnelle was zusammengebastelt ;-)

ich verwende in diesem Beispiel jedoch TStringlist, um an die Text-Datei herran zukommen.

Aber schau dir mal die Prozedur Delete in der Delphi-Hilfe an, dann kannst du leicht deinen Code ummodifizieren.

ausblenden 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:
const filename = 'test.txt' ;
      sep = '=';

var sl : TStringlist;
     i : Integer;
     s : String;
begin

 sl := TStringlist.Create;
 sl.LoadFromFile(filename);

for i := 0 to sl.count - 1 do
 begin
    s := sl.Strings[i];
    listbox1.Items.Add(copy(s,1,pos(sep,s)-1));
    delete(s,1,pos(sep,s));
    listbox2.Items.Add(copy(s,1,pos(sep,s)-1));
    delete(s,1,pos(sep,s));
    listbox3.Items.Add(copy(s,1,pos(sep,s)-1));
    delete(s,1,pos(sep,s));
    listbox4.Items.Add(s);
 end;

end;


MfG
Savage