Autor Beitrag
Georg08
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: Sa 02.05.09 19:23 
Hallo,
ich hab schon einiges in Delphi hinbekommen, aber jetzt könnt ich gut hilfe gebrauchen :D ;)

Mein Problem ist folgendes:
Ich möchte eien Musikdatei z.B. verschlüsseln, dazu muss ich sie aber auslesen. Ich habe versucht die Datei ganz nomal mit "assignfile..." eingelesen. Aber mein Problem ist, dass die Dateien eigentlich nur eine Zeile haben. Wenn ich den Text in eine Variable lese bekommt ich nur die ersten x Zeichen, der Rest ist weg :(

Danke im voraus für eure Hilfe...
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 02.05.09 19:42 
Das liegt an den darin enthaltenen Steuerzeichen. Schau dir einmal TFileStream an. ;-)
Timosch
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1314

Debian Squeeze, Win 7 Prof.
D7 Pers
BeitragVerfasst: Sa 02.05.09 19:42 
Du darfst nicht mit TextFile arbeiten. Nimm z.B. File of Byte und lies die Zeichen einzeln ein (also mit Read statt ReadLn). Oder nimm TFileStream, wie jaenicke grad schreibt (verdammt! 10 Sekunden zu spät! :mrgreen:).

_________________
If liberty means anything at all, it means the right to tell people what they do not want to hear. - George Orwell
Georg08 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: Sa 02.05.09 19:49 
TFileStream? Hab ich schon mal versucht aber hinbekommen... Noch nie xD
kanns mir einer erklären?

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

wie soll ich denn eine Datei auslesen
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
datei : file of byte;
datei_inhalt: string;

[...]

if OpenDialog1.Execute then
begin
assignfile(datei, OpenDialog1.FileName);
datei_inhalt := read(datei);
end;


so?
Timosch
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1314

Debian Squeeze, Win 7 Prof.
D7 Pers
BeitragVerfasst: Sa 02.05.09 20:06 
user profile iconGeorg08 hat folgendes geschrieben Zum zitierten Posting springen:
wie soll ich denn eine Datei auslesen
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
datei : file of byte;
datei_inhalt: string;

[...]

if OpenDialog1.Execute then
begin
assignfile(datei, OpenDialog1.FileName);
datei_inhalt := read(datei);
end;


so?

datei_inhalt darf natürlich kein String sein. Nimm einen Array of Byte und schreibe Stück für Stück mit einer Schleife die einzelnen Bytes rein. (While-Schleife mit while not eof(datei) ). Aber ich gebe jaenicke recht: TFileStream ist viel besser. Schau dir mal die Delphi-Hilfe dazu an.

_________________
If liberty means anything at all, it means the right to tell people what they do not want to hear. - George Orwell
Georg08 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: Sa 02.05.09 20:14 
hmm... den filestream kapier ich auch mit der dlephihilfe nich :(
kann mal jemand n beispiel posten egal für was?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 02.05.09 20:21 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
  MyFile: TFileStream;
  Example: Integer;
begin
  MyFile := TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
  try
    MyFile.ReadBuffer(Example, SizeOf(Example)); // Um einen Integerwert (4 Byte) zu lesen
  finally
    MyFile.Free;
  end;
Georg08 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: Sa 02.05.09 20:25 
wow xD und wie kann ich den text rausholen?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 02.05.09 20:30 
Welchen Text? Eine Musikdatei ist keine Textdatei, da gibt es keinen Text, das sind einfach nur binär Bytes hintereinander. :gruebel:
Georg08 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: Sa 02.05.09 20:40 
also irgenwas mach ich falsch xD
hier mal mein quellcode:
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:
var
  Form1: TForm1;
  datei : TFileStream;
  i : integer;
  inhalt : char;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin

datei := TFileStream.Create(Opendialog1.FileName, fmOpenRead);
try
datei.ReadBuffer(i, sizeof(i));
finally
datei.Free;
end;
richedit1.text := IntToStr(i);

end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin

datei := TFileStream.Create(Savedialog1.FileName, fmCreate);
datei.Write(i, sizeof(i));
datei.Free;

end;

end;
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 02.05.09 20:43 
Sieht auf den ersten Blick doch richtig aus. ;-)

Mehr kann ich zu der äußerst aufschlussreichen und detaillierten Fehlermeldung "also irgenwas mach ich falsch" gerade nicht sagen... :roll:
Georg08 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: Sa 02.05.09 20:47 
also wenn aus ner 5MB mp3 ne 40 byte mp3 wird is was schief gelaufen oder???
was allerdings auch komisch ist:
die mp3 hat nur 8 Zeichen wenn ich sie auslese (habs mir mal anzeigen lassen)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 02.05.09 20:49 
Du liest einen Integerwert mit 4 Byte und schreibst den... Mehr machst du doch auch gar nicht... :lol:

Du kannst auch byteweise in eine Variable vom Typ Byte lesen, aber in jedem Fall brauchst du eine Schleife...