Autor Beitrag
patrick dee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: So 14.01.07 12:34 
mahlzeit leute

wie kann ich in einem text file abfragen ? gebe in der edit ein wort ein und es soll in dem text file (musik.txt) gesucht werden und jede zeile in der das wort vorkommt in einer listbox ausgegeben werden.

so sehen die einträge aus :

5088-02#MUNGO JERRY#IN THE SUMMERTIME#03:25#17#00:00#03:23##
5088-03#CAT STEVENS#WHERE DO THE CHILDREN PLACE#03:50#30#00:00#03:46##
5089-11#MUD#LONELY THIS CHRISTMAS#03:31#15#00:00#03:31##
5089-12#EVERLY BROTHERS#ALL I HAVE TO DO IS DREAM#02:20#00#00:00#02:18##
5089-13#EVERLY BROTHERS#TILL I KISSED YOU#02:20#07#00:00#02:19##
5089-15#BEATLES#LET IT BE#03:47#13#00:00#03:47##
5089-16#MANHATTAN TRANSFER#GLORIA#02:54#00#00:00#02:53##

möchte so meine musiktitel abfragen.


danke für eure hilfe

patrick

_________________
Glauben heißt nichts wissen ...
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 14.01.07 12:44 
1. TStringList erzeugen
2. Mit YourStringList.LoadFromFile die Datei dahineinladen
(wenn im selben Verzeichnis wie die Exe mit ExtractFilePath(ParamStr(0)) + '\x.txt', weil du IMMER absolute Verzeichnisnamen mit angeben musst.
3. mit for i := 0 to YourStringList.Count - 1 do durch alle Zeilen gehen
4. mit YourStringList[i] die jeweilige Zeile ansprechen und mit Pos nachsehen, ob der gesuchte Text in der Zeile enthalten ist (Pos gibt dann einen Wert größer als Null zurück)
5. ggf. die Zeile mit YourListBox.Items.Add in die ListBox eintragen

// EDIT: Aus Versehen editiert... Alten Zustand wiederhergestellt. Operas Cache sei dank...


Zuletzt bearbeitet von jaenicke am So 14.01.07 13:14, insgesamt 3-mal bearbeitet
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: So 14.01.07 12:54 
puuu jaenicke

das klingt ja sehr kompliziert. da blicke ich grad gar nicht durch.

habe mir das nicht so komplziert vorgestellt.

danke

patrick

_________________
Glauben heißt nichts wissen ...
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 14.01.07 12:57 
Das ist nicht kompliziert... Es sind wirklich nur diese 5 Zeilen! Ich hab doch schon fast genau geschrieben, was du machen musst!
Dachtest du, das geht in einer Zeile oder wie? [IRONIE]So nach der Art: LoadTextFileLinesFromFileWithFilter? :lol: [/IRONIE]
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: So 14.01.07 13:03 
hi jaenicke;

danke aber mal sehen ob ich da mehr zu finde wie sich das aufbaut.
evtl. finde ich a weng an code.


danke trotzdem schönen sonntag :lol:

_________________
Glauben heißt nichts wissen ...
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 14.01.07 13:11 
Seufz. :roll: :roll: Warum probierst du es denn nicht einfach aus??? Irgendwie scheint es da an Eigeninitiative zu fehlen!!!
user profile iconjaenicke hat folgendes geschrieben:
1. TStringList erzeugen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  xy: TStringList;
begin
  xy := TStringList.Create;
  2.
  3.
    4. (if Pos(...) > 0)
      5.
  xy.Free;

So, jetzt musst du es ja fast nur noch abschreiben... Aber noch fertigeren Code gibts nicht, ich hab ja eh schon fast alles geschrieben. :lol:
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: Mo 15.01.07 12:08 
also ich habe es mal so probiert, aber bisher zeigt er mir in der listbox alles an udn nicht das gesuchte. irgendwo ist noch ein fehler drinnen :


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:
26:
27:
28:
29:
procedure TForm1.Button1Click(Sender: TObject);
var
 abfrage : string;
  Pfad   : string;
   j,i,p : integer;
 begin
  Pfad := edit1.Text;
  Memo1.lines.LoadFromFile(Pfad);// wo liegt die liste
  abfrage := Edit2.Text;
  i := 0;
while i < ListBox1.Items.Count do
  p :=POS(Abfrage,Memo1.Lines[i]);
  begin
  if p <> 0 then // kommt wort vor?
    begin
    //Die gefundene Zeile einfuegen
    ListBox1.items.Add(Memo1.Lines[i]);
     With Memo1 do
      begin
      for j := i+1 to Lines.Count - 1 do
        begin
           if Memo1.Lines[j] <> '' then
          ListBox1.items.Add(Memo1.Lines[j]);
        end;
    end;
  inc(i);
  end;
 end;
end;



stehe auf dem schlauch :cry:

_________________
Glauben heißt nichts wissen ...
Danny W.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Mo 15.01.07 12:50 
Benutz doch Ini's :P

//EDIT

Ich habe mal eine Präsentationssteuerung gemacht, vielleicht kannst du davon was gebrauchen ^^

Textdatei
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
03.11.2006,03.11.2006,13:55:00,13:55:30,Bildergalerie.pps
03.11.2006,03.11.2006,13:59:00,13:59:30,Hoffmann.pps
03.11.2006,03.11.2006,13:57:00,13:57:30,Moellering.pps
03.11.2006,03.11.2006,13:58:00,13:58:30,Busemann.pps
03.11.2006,03.11.2006,13:56:00,13:56:30,Citipost.pps
03.11.2006,03.11.2006,13:52:00,13:52:30,Seiters.pps
03.11.2006,03.11.2006,13:53:00,13:53:30,BegrüßungWulff.pps
03.11.2006,03.11.2006,13:54:00,13:54:30,BegrüßmonKult.pps
03.11.2006,03.11.2006,13:51:00,13:51:30,Rotary.pps
00.00.0000,00.00.0000,00:00:00,00:00:00,Standart.pps


Quellcode zum Auslesen und verwerten
ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
unit server;

interface

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

type
  TForm1 = class(TForm)
    ausgabe: TTimer;
    Panel1: TPanel;
    zeit: TLabel;
    eingabe: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    datum: TLabel;
    fullstring: TLabel;
    Memo2: TMemo;
    zeitaktual: TTimer;
    Memo3: TMemo;
    Label3: TLabel;
    Memo1: TMemo;
    Image1: TImage;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
   procedure zeitaktualTimer(Sender: TObject);
    procedure eingabeTimer(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ausgabeTimer(Sender: TObject);
  private
    { Private-Deklarationen }

  public
    { Public-Deklarationen }
   Procedure ausgeben;
   Procedure einlesen;
   procedure zeilendeleter;

  end;

var
  Form1: TForm1;
  Standart :String;
  besetzt : boolean;
  sl: TStringList;
  datum_von,zeit_von : array[1..10of string;
  datum_bis,zeit_bis : array[1..10of string;
  Programm           : array[1..10of string;
  liste:TStringList;
  x2 : integer;

implementation

{$R *.dfm}

function GetScreenShot: TBitmap;
var
  Desktop: HDC;
begin
  Result  := TBitmap.Create;
  Desktop := GetDC(0);
  try
    try
      Result.PixelFormat := pf32bit;
      Result.Width := Screen.Width;
      Result.Height := Screen.Height;
      BitBlt(Result.Canvas.Handle, 00, Result.Width, Result.Height, Desktop, 00, SRCCOPY);
      Result.Modified := True;
    finally
      ReleaseDC(0, Desktop);
    end;
  except
    Result.Free;
    Result := nil;
  end;
end;

procedure TForm1.zeilendeleter;
var i:integer;
begin

  liste := TStringList.Create;
  liste.LoadFromFile('daten\daten.txt');
  Memo3.Text := liste.Text;
  liste.Clear;
  Memo3.Text:=StringReplace(memo3.text, fullstring.caption, '00.00.0000,00.00.0000,00:00:00,00:00:00,Standart.pps', [rfReplaceAll]);
  liste.Text := memo3.text;
  liste.SaveToFile('daten\daten.txt');

end;

Procedure TForm1.einlesen;
var  i,x,y:integer;
begin
///////////////Memo Reset///////////////
  memo1.clear;
///////////////Memo Reset///////////////
  sl := TStringList.Create;
  sl.LoadFromFile('daten\daten.txt');

  Memo1.Text := sl.Text;

  label1.caption:=inttostr(sl.count);

    sl.Delimiter := ','//Splitter
    sl.DelimitedText := memo1.text; //der zu splittende text




    y:=0;
    for x:= 1 to 10 do begin
     datum_von[x]:=sl.strings[y];
     y:=y+5;
    end;

    y:=1;
    for x:= 1 to 10 do begin
     datum_bis[x]:=sl.strings[y];
     y:=y+5;
    end;

    y:=2;
    for x:= 1 to 10 do begin
     zeit_von[x]:=sl.strings[y];
     y:=y+5;
    end;

    y:=3;
    for x:= 1 to 10 do begin
     zeit_bis[x]:=sl.strings[y];
     y:=y+5;
    end;

    y:=4;
    for x:= 1 to 10 do begin
     programm[x]:=sl.strings[y];
     y:=y+5;
    end;

end;

Procedure TForm1.ausgeben;
var i,x : integer;
begin
///////////////Programmname///////////////
//BEISPIEL Programm:='daten/adac.pps';
Standart:='daten\Standard.pps';
///////////////Programmname///////////////

///////////////Aufruf der Standart Präsi///////////////
if besetzt=false then
 begin
  ShellExecute(Application.Handle,'open',PCHAR(Standart),nil,nil,SW_shownormal);
 end;
///////////////Aufruf der Standart Präsi///////////////

///////////////Programm Break///////////////
 for x := 1 to 10 do begin
 if ((datum_von[x]='break'and (besetzt=true)) then
 begin
  x2:=x;
  besetzt:=false;
  ShellExecute(Application.Handle,'open',PCHAR('close.bat'),nil,nil,SW_Hide);
    sleep(1000);
  ShellExecute(Application.Handle,'open',PCHAR(Standart),nil,nil,SW_shownormal);
  fullstring.caption:=('BREAK!');
///////////////Programm Laden///////////////
end;
end;
///////////////Programm Break///////////////

///////////////Programm Laden///////////////
 for x := 1 to 10 do begin
 if ((datum_von[x]='sofort'and (besetzt=false)) or ((datum.caption = datum_von[x]) and (zeit.caption = zeit_von[x]) and (besetzt=false)) then
 begin
  x2:=x;
  besetzt:=true;
  ShellExecute(Application.Handle,'open',PCHAR('close.bat'),nil,nil,SW_Hide);
    sleep(1000);
  ShellExecute(Application.Handle,'open',PCHAR('daten\'+Programm[x]),nil,nil,SW_shownormal);
  fullstring.caption:=(datum_von[x]+','+datum_bis[x]+','+zeit_von[x]+','+zeit_bis[x]+','+programm[x]);
///////////////Programm Laden///////////////
end;
end;



///////////////Programm Schließen///////////////
 if (datum.caption = datum_bis[x2]) and (zeit.caption = zeit_bis[x2]) and (besetzt=true) then
   begin
    ShellExecute(Application.Handle,'open',PCHAR('close.bat'),nil,nil,SW_Hide);
    besetzt:=false;
    zeilendeleter;
   end;
///////////////Programm Schließen///////////////

///////////////AUSGABE DER VARIABLEN ///////////////
 for i := 1 to 10 do begin
  memo2.lines.add('---Datensatz '+inttostr(i)+'---');
  memo2.Lines.add('datum_von: '+datum_von[i]);
  memo2.Lines.add('datum_bis: '+datum_bis[i]);
  memo2.Lines.add('zeit_von: '+zeit_von[i]);
  memo2.Lines.add('zeit_bis: '+zeit_bis[i]);
  memo2.Lines.add('programm: '+programm[i]);
  memo2.lines.add('');
 end;
 memo2.clear;
///////////////AUSGABE DER VARIABLEN ///////////////
end;

procedure TForm1.ausgabeTimer(Sender: TObject);
begin
ausgeben;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
application.minimize;
memo1.Clear;
zeit.caption:=timetostr(now);
datum.caption:=datetostr(now);
x2:=0;

///////////////Leitung Freimachen///////////////
besetzt:=false;
///////////////Leitung Freimachen///////////////
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
besetzt:=false;
sl.free;
liste.free;
end;

procedure TForm1.eingabeTimer(Sender: TObject);
begin
einlesen;
end;

procedure TForm1.zeitaktualTimer(Sender: TObject);
begin
///////////////Zeit Aktualisieren///////////////
zeit.caption:=timetostr(now);
datum.caption:=datetostr(now);
///////////////Zeit Aktualisieren///////////////
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Image1.Picture.Bitmap := GetScreenShot;
Image1.Picture.Bitmap.SaveToFile('stream.bmp');
end;

end.


mfG,
Danny

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
Danny W.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Mo 15.01.07 12:58 
user profile iconjaenicke hat folgendes geschrieben:

4. mit YourStringList[i] die jeweilige Zeile ansprechen und mit Pos nachsehen, ob der gesuchte Text in der Zeile enthalten ist (Pos gibt dann einen Wert größer als Null zurück)


Wenn du deine RauteZeichen hast, dann nehm dieses doch als Delimiter. Die funktionsweise solltest du in meinem vorherigen quelltext sehen.

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 15.01.07 13:25 
ein paar kleine sachen...
wenn du was zählen willst nimm ne ZÄHLSCHLEIFE!
Außerdem: wennde mit ner Schleife alle Zeilen des Memo in die Listbox kopierst, brauchste dich nicht wundern wenn da alle zeilen drin sind
Die POS abfrage muss auch mit in die Schleife rein! sonst macht er die Pos abfrage x mal und dann den rest
rest musste mal sehn... Teste mal
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm1.Button1Click(Sender: TObject);
var
 abfrage : string;
  Pfad   : string;
   j,i,p : integer;
 begin
  Pfad := edit1.Text;
  Memo1.lines.LoadFromFile(Pfad);// wo liegt die liste
  abfrage := Edit2.Text;
  i := 0;
for i:=0 to ListBox1.Items.Count do
  begin
  p :=POS(Abfrage,Memo1.Lines[i]);
  if p >0 then // kommt wort vor?
    begin
    //Die gefundene Zeile einfuegen
    ListBox1.items.Add(Memo1.Lines[i]);
  end;//endif
 end;//endfor
end;//end proc
patrick dee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: Di 16.01.07 08:48 
hi leute


meine abfrage läuft nun soweit ABER wie bekomme ich diese zeichen aus den gefundenen zeile raus # ## es soll nur eine leerstelle geszeigt werden. und auch nur die laufzeit des tracks.also so :

5089-15 BEATLES LET IT BE 03:47

bisher steht es so in meinem ergebnis der suche :

5089-15#BEATLES#LET IT BE#03:47#13#00:00#03:47##
5089-16#MANHATTAN TRANSFER#GLORIA#02:54#00#00:00#02:53##


danke patrick :roll:

_________________
Glauben heißt nichts wissen ...
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 16.01.07 08:57 
Vorab : wer zu faul ist die Großschreibung zu beachten, der macht seine Fragen unleserlicher, muss länger auf Antwort warten. Unhöflich ist er sowieso. :evil:

ABER :

stringreplace, pos, copy, F1

_________________
Gruß
Hansa