Autor Beitrag
G-McKree
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178



BeitragVerfasst: Do 03.04.03 19:59 
wie kann ich eine string-variable in ne TStringList laden?
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Do 03.04.03 20:02 
Enthält der String Zeilenumbrüche? Wenn ja:
ausblenden Quelltext
1:
MeineStringListe.Text := MeinString;					

wenn nein:
ausblenden Quelltext
1:
MeineStringListe.Add(MeinString);					

_________________
Ist Zeit wirklich Geld?
G-McKree Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178



BeitragVerfasst: Do 03.04.03 20:06 
das mit dem add befehl hab ich schon mal versucht, aber mein delphi hat was dagegen
Alibi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458

Win2K SP3
Delphi 6 Ent
BeitragVerfasst: Do 03.04.03 20:12 
Kristallkugeln raus, er will einfach nicht sagen, was er machen will bzw. was er mit der Add Funktion versucht hat, die funktioniert garantiert. ;)
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Do 03.04.03 20:12 
Die StringList-Variable hast du aber schon deklariert?

_________________
Ist Zeit wirklich Geld?
G-McKree Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178



BeitragVerfasst: Do 03.04.03 20:23 
ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
   list: tstringlist;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 list:= tstringlist.create;
 list.loadfromfile('c:\test.txt');
 richedit1.text:= list[1];
 list.free;
end;

end.


delphi findet den source ok, aber bei run kommt ne fehlermeldung

Moderiert von user profile iconUGrohne: Quote- durch Code-Tags ersetzt
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Do 03.04.03 20:57 
Hi
an dem Code ist nix auszusetzen ausser dass du versuchst die zweite Zeile aus der Liste in das RichEdit zu laden, ohne zu wissen ob die überhaupt vorhanden ist.
[KristallkugelMode]
Hast du vielleicht nur eine Zeile in deiner Textdatei?
[/KristallkugelMode]

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
G-McKree Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178



BeitragVerfasst: Do 03.04.03 21:01 
index 1 ist die zweite zeile? das is ja mal wieder eine delphihaftigkeit
demnach ist index 0 die erste?
super, jez hab ich das problem behoben, danke
kann man irgentwie heraus finden wie viel zeilen ne datei hat?
Alibi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458

Win2K SP3
Delphi 6 Ent
BeitragVerfasst: Do 03.04.03 21:06 
Wieso delphihaftigkeit?
Also bis jetzt ist das bei jeder Programmiersprache, die mir über den Weg gelaufen ist so gewesen, dass die bei 0 anfängt zu zählen, nicht bei eins. Irgendwie auch logisch.
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Do 03.04.03 21:06 
Hi
Zitat:

index 1 ist die zweite zeile? das is ja mal wieder eine delphihaftigkeit

Arrays werden nun mal standardmässig ab 0 gezählt.
Zitat:

kann man irgentwie heraus finden wie viel zeilen ne datei hat?

Nachdem du sie in die Stringliste geladen hast? Klar
Anzahl: List.Count
Letzte zeile ist demnach:List.Count - 1
Einfaches Nachschlagen in der Online-Hilfe hätte das zutage gebracht :wink:

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Do 03.04.03 21:07 
ausblenden Quelltext
1:
list.count;					


Bittscheee.....

Schönen Abend noch
G-McKree Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178



BeitragVerfasst: Do 03.04.03 21:14 
warum ist die letzte zeil nicht nur list.count?
isst list [list.count] dann die zeile nach der letzten?
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Do 03.04.03 21:16 
Hi
G-McKree hat folgendes geschrieben:
warum ist die letzte zeil nicht nur list.count?

Wenn die Anzahl 2 ist und du bei 0 zu zählen anfängst, dann kommst du eben nicht weiter als bis 1
G-McKree hat folgendes geschrieben:

isst list [list.count] dann die zeile nach der letzten?

Ne, das ist Zugriffverletztung :twisted:

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Alibi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458

Win2K SP3
Delphi 6 Ent
BeitragVerfasst: Do 03.04.03 21:17 
Warum sollte?
List.Count liefert die Anzahl der Einträge zurück.
Eintrag 0 ist der erste Eintrag.
Und list[list.count] wird deswegen auch eine Exception auslösen.
Richtig: list[list.count-1]