Autor Beitrag
PeeTheBee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win 98
D4 Pers
BeitragVerfasst: Sa 31.07.04 16:25 
Hallo!

Ich möchte eine txt-Datei (804KB) in ein Memo laden (LoadFromFile), um dann per Zufall eine Zeile auszuwählen und zu kopieren.

Wie kann ich die Memokapazität soweit erhöhen oderkann ich das direkt an der Date machen (mit assign und so)?

Danke für eure Antwort, PeeTheBee
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 31.07.04 17:03 
Wenn sie nicht angezeigt werden müssen, nimm doch eine Stringliste. Ansonsten kann ein Memo unter NZ ff. auch mehr als 64 KB an Daten aufnehmen.
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Sa 31.07.04 17:41 
ist doch aber humbug, eine riesen Datei in ein Memo zu laden, und dann nur eine Zeile zu nehmen. Auch eine StringList lädt den ganzen Kram in den Speicher. Hier würd ich echt die nativen Routinen Assignfile() Reset() ReadLn() u.s.w. empfehlen.

grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
PeeTheBee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win 98
D4 Pers
BeitragVerfasst: So 01.08.04 08:50 
Hallo!

Also nicht in ein Memo laden.
Gut, aber ich habe eigentlich noch nie mit reienen Textdateien gearbeitet. Wie würde ich dann eine zufällige Zeile in eine Variable laden können?

Danke, PeeTheBee
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: So 01.08.04 09:47 
Um das einmalige Lesen der Datei kommt er wohl nicht herum. Egal wie, es sei denn, die Zeilen haben eine genau definierte Länge.

Dann könnte man die vorhandene Zeilenanzahl anhand der Dateigröße ermitteln. Nun gut, ein Perfektionist würde folgendes tun : Datei zeilenweisse lesen und in einem Ring speichern. Das ist eine verkettete Liste, bei der das Ende wieder an den Anfang zeigt. Das wäre so etwas wie ein "Glücksrad". Das steht irgendwo auf einer Zahl. Dann wird es gedreht, bis es wieder irgendwo stehen bleibt usw.

In diesem Fall müßte es mit "random (X)" gedreht werden. Ist X größer, als die maximale Zeilenanzahl, dann geht es vorne wieder los. Wahrscheinlich ist das aber zu kompliziert.

_________________
Gruß
Hansa
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 01.08.04 10:32 
ich würds erstmal nit ner stringliste machen !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
PeeTheBee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win 98
D4 Pers
BeitragVerfasst: Di 03.08.04 08:12 
Hi!

Könnte mir vielleicht jemand von euch eine kleine Funktion schrieben, die die Textdatei öffnet und eine beliebige Zeile daraus zurückgibt?

Wäre nett, Danke, PeeTheBee
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 03.08.04 09:20 
so müsste das klappen: (ungetestet)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var SL:TStringlist;
begin
     randomize;
     SL := TStringlist.create;
     try
        SL.LoadFromFile ('c:\datei.txt');
        showmessage (SL[random (SL.count)]);
     finally
            SL.free
     end;
end;

_________________
In the beginning was the word.
And the word was content-type: text/plain.
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Di 03.08.04 14:36 
oder so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var
  F:Textfile;
  S:String;
  R,I:Integer;
begin
  AssignFile(F,'test.txt');
  R:=0;
  reset(F);
  while not EOF(F) do begin
    readln(F,S);
    Inc(R);
  end;
  R:= Random(R); // :-)
  I:=0;
  Reset(F); // ReOpen, seek(0,0);
  while i<R do ReadLn(F,S);
  CloseFile(F);
  S:='hier steht der zufällige Text';
end;


** UNGETESTET ***

grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
PeeTheBee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win 98
D4 Pers
BeitragVerfasst: Do 05.08.04 06:54 
Danke, Leute!

Werd's mal probieren und hier berichten...
PeeTheBee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win 98
D4 Pers
BeitragVerfasst: Do 05.08.04 12:37 
Funktioniert mit StringList, das andere habe ich dann nicht mehr probiert. Trotzdem vielen Dank an euch, die Mitglieder des besten Forums, das ich je gesehen habe, ehrlich.

Ciao, PeeTheBee