Autor Beitrag
DarkHunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Mi 10.03.04 17:16 
Hallo
ich arbeite noch nicht alzu lange mit delphi (~1 Jahr) und stehe vor einem Problem

ich möchte aus einer textdatei jeden einzelnen buchstaben als array auslesen und zwar für jeden zeile.
Wie geht das?

MFG DarkHunter

Moderiert von user profile iconPeter Lustig: Thema verschoben
Pascal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155

Win 98, Win XP
Delphi 2005, Delphi 5
BeitragVerfasst: Mi 10.03.04 17:42 
Es geht zwar eleganter schätze ich, aber man kann es z.B. so machen:
Listbox auf das Formular setzen und dann
ausblenden Delphi-Quelltext
1:
2:
listbox1.items.loadfromfile('C:\Windows\Desktop\Test.txt');
Buchstabexy:=listbox1.items[y-1][x];
DarkHunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Mi 10.03.04 17:46 
hm

das ganze hat den hintergrund das ich eine karte machen will damit, je nachdem was für ein buchstabe dort steht nimmt er ein anderes bild.
zb
zeile 1: wwwbbbwww
zeile 2: wwwwbbbww

nun sollen also die ersten 3 das image "w" erhalten die nächsten 3 "b" und die letezen wieder "w"
in der nächsten zeile entsprechend
Pascal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155

Win 98, Win XP
Delphi 2005, Delphi 5
BeitragVerfasst: Mi 10.03.04 17:48 
heißt das es gibt noch Probleme, oder war es das was du brauchst?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 10.03.04 17:50 
Eine ListBox brauchst Du dafür nicht. Da reicht es doch, eine StringList zu erzeugen.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Pascal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155

Win 98, Win XP
Delphi 2005, Delphi 5
BeitragVerfasst: Mi 10.03.04 17:52 
Ich weiß, aber die hat bei mir so oft Fehler gegeben, das ich das aufgegeben habe. Auch wenn ich es noch irgendwie zum laufen bringe, brauche ich dafür immer mehr zeit, als wenn ich gleich ne Listbox einsetze.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 10.03.04 17:56 
Wie? Viele Fehler?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var myList : TStringList;
begin
  myList := TStringList.Create;
  try
    myList.LoadFromFile('irgendwas.txt');
    BuchstabeXY := myList[y][x];
  finally
    myList.Free;
  end;
end;


Das ist doch ganz einfach und sehr viel sauberer, als eine Listbox. Wie machst Du das denn dann? Versteckst Du die?

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Pascal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155

Win 98, Win XP
Delphi 2005, Delphi 5
BeitragVerfasst: Mi 10.03.04 18:00 
Wahrscheinlich habe ich mich mit der Stringlist auch nicht genug auseinandergesetzt.
Und ja die listbox verstecke ich meist. Ich mag die auch gerne weil ich die nur einmal aufs Formular setze und dann in 10 Proceduren benutzen kann. Wie gesagt, die Fehler ließen sich wahrscheinlich vermeiden, aber ich find's trotzdem leichter so.
DarkHunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Mi 10.03.04 18:04 
das problem ist ein anderes das programm soll erkene um welchen buchstaben es sich handelt
das soll dem programm vorher nicht bekannt sein.
das mit dem in eine Tstringlist lagen mach ich auch schon nur bisher kann ich nur ganze zeile auslesen
ausblenden Delphi-Quelltext
1:
Map.strings[0]....					
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 10.03.04 18:06 
Hast Du Dir die Quelltexte, die hier gepostet wurden, mal richtig angesehen? Da steht drin, wie man auf einzelne Buchstaben zugreift!

(Außerdem: wenn Du das schon laden kannst, hat das hier nichts in Dateizugriff zu suchen!)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
DarkHunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Mi 10.03.04 19:13 
stimmt
wenn ich also zeile eins buchstbe 2 wissen will wäre das in etwa so
ausblenden Delphi-Quelltext
1:
if map[1][2] = w then begin.......					
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 10.03.04 19:15 
Jein. ;-)

falsch: Die erste Zeile hat den Index 0.
richtig: Der erste Index der Buchstaben in der Zeile ist 1.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
DarkHunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Mi 10.03.04 19:26 
stimmt hatte ich vergessen
wäre dann also ........map[0][2].......
Pascal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155

Win 98, Win XP
Delphi 2005, Delphi 5
BeitragVerfasst: Mi 10.03.04 19:51 
genau.
nur nicht ...=w sondern ...='w' (Es sei denn w ist ne Variable)