Autor Beitrag
Force
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: Sa 04.11.06 23:55 
Hi,

Ich habe ein Programm, welches mir eine Datei senden soll, nämlich mitfolgendem String:
311 Dateiname||Dateiinhalt
diesen string speichere ich dann in einer Memo, und im weiteren Verlauf wird der Inhalt der Memo mittels SaveToFile als Datei gespeichert (ich habe es zuerst mit einem TFileStream versucht, allerdings hat der zwischen jedes empfangene Zeichen in der Datei ein zusätzliches Zeichen hinzugefügt, ist sah irgendwie sehr seltsam aus...).

Jetzt meine Frage: die ersten Zeichen sollen nun gelöscht werden, allerdings kenne ich als einzigen Weg mittels einer For- beziehungsweise While-Schleife alle Zeichen einzeln dem Text zuzufügen, was allerdings sehr arbeitsaufwändig für den PC ist.

Gibt es eine bessere Methode? Ich habe schon gegoogelt, allerdings habe ich nichts gefunden...

Vielen Dank, Force ;)
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 04.11.06 23:58 
Schau dir mal die Delete();-Function an ;)
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: So 05.11.06 00:01 
vielen dank für die schnelle Antwort, aber so weit ich weiß, kann man damit doch nur ganze Lines löschen, oder?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 05.11.06 00:02 
Moin!

user profile iconForce hat folgendes geschrieben:
Ich habe ein Programm, welches mir eine Datei senden soll, nämlich mitfolgendem String:
311 Dateiname||Dateiinhalt
diesen string speichere ich dann in einer Memo, und im weiteren Verlauf wird der Inhalt der Memo mittels SaveToFile als Datei gespeichert

Wenn es sich bei den Dateien nicht zufällig um Textdateien handelt, dann wird das sowieso nicht funktionieren, weil das Memo dir (vermeintlich) unvollständige Zeilenumbrüche "vervollständigt", am 1. #0 abtrennt und eh nicht mehr als 16kb Daten verarbeiten kann. :mahn: ;)

user profile iconForce hat folgendes geschrieben:
(ich habe es zuerst mit einem TFileStream versucht,

Und dieser Ansatz, zusammen mit einem Suche in: Delphi-Forum, Delphi-Library PROTOKOLL sollte es dann bringen. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: So 05.11.06 10:58 
Alelrdings komm ich mit dem TFilestream noch nicht so klar - ich hab das ungefähr so gemacht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure SaveFile(const FileName: TFileName;
                   const content: string);
begin
  with TFileStream.Create(FileName, fmCreate) do
    try
      Write(Pointer(content)^, Length(content));
    finally
      Free;
    end;
end;


Allerdings sieht das Ergebnus dann so aus, dass zwischen jedem Zecihen noch ein Leerzeichen ist...

Ist da irgendwo ein Fehler?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 05.11.06 11:16 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure SaveFile(const FileName: TFileName; const Content: String);
var
  FStream: TFileStream;
begin
  FStream := TFileStream.Create(FileName, fmCreate);

  try
    FStream.Write(Pointer(Content)^, Length(Content));
  finally
    FStream.Free;
  end;
end;

So funktioniert es.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: So 05.11.06 12:04 
leider das selbe Ergebnis :(

Ich hab mal einen Screenshot gemacht:

user defined image
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 05.11.06 12:55 
Der Content ist aber richtig? Hast du das mal mit ShowMessage(); überprüft?

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 05.11.06 14:36 
Moin!

Um das mal noch schnell klarzustellen: user profile iconForce, dein Ansatz zum Schreiben der Datei ist absolut gleichwertig zu dem von user profile iconGTA-Place. ;) Allerdings würde ich den Typecast anders machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure SaveFile(const FileName: TFileName;  
                   const Content: String);  
begin  
  with TFileStream.Create(FileName, fmCreate) do  
    try  
      Write(PChar(Content)^, Length(Content));  
    finally  
      Free;  
    end;  
end;

Ich halte den Code für korrekt, stimmt denn die Länge der Datei mit der String-Länge überein? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: So 05.11.06 15:01 
es funktioniert immer noch nicht - allerdings habe ich mal die Größe verglichen: Beide Dateien sind gleich groß oO
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 05.11.06 15:18 
Moin!

Hast du denn die Idee von GTA-Place schonmal umgesetzt und geschaut, ob der String überhaupt das enthält, was du erwartest? ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure SaveFile(const FileName: TFileName;    
                   const Content: String);    
begin    
  with TFileStream.Create(FileName, fmCreate) do    
    try
      ShowMessage(Content);
      Write(PChar(Content)^, Length(Content));    
    finally    
      Free;    
    end;    
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: So 05.11.06 15:21 
doch, das hab ich schon direkt am Anfang gemacht, der String wird auch direkt in einer Memo angezeigt, da sieht es jedenfalls ganz normal aus.

/edit: auch bei Showmessage sieht es normal aus :(
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 05.11.06 15:42 
Moin!

Pack mal so eine von dir erstellte Datei hier in den Anhang und schreib dazu, was du in der Datei erwarten würdest. :?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: So 05.11.06 15:47 
Das kann jede beliebige Datei sein - ich habs hier zum Test mal mit der Boot.ini von meiner VM gemacht - ein anderes Programm liest den Inhalt dieser Datei aus und schickt in mir wie ganz oben beschrieben.
Einloggen, um Attachments anzusehen!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 05.11.06 16:01 
Moin!

Kannst du das auch als ZIP anhängen? Ich kann RARs nicht so ohne weiteres auspacken (zumindest ist bei mir nur eine Datei drin?!)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: So 05.11.06 16:07 
klar, kein problem ;)
Einloggen, um Attachments anzusehen!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 05.11.06 16:12 
Moin!

Wie ich´s mir dachte, du machst aus dem String irgendwo einen MultiByte-String (MCBS). ;) Da kommen wir aber nur weiter, wenn du den Code zum Senden und Empfangen mal komplett zeigst. :?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 143

Ubuntu Jaunty
FreePascal
BeitragVerfasst: So 05.11.06 16:17 
dann wird das sehr wahrscheinlich am Server liegen - von dem hab ich aber leider den Quelltext nicht :(

Deshalb meine Fragen: a) Gibt es eine Möglichkeit, den in einen "normalen" String umzuwandeln? und b) wie kann ich die ersten Zeichen am besten löschen? (Hier würde ich dann auch den Temorystream nehmen.)

auch nochmal vielen Dank für die schnellen Antworten ;)

Force


/edit a) hat sich erledigt, hab grad eine Funktion gefunden, ich werde sie mal eben ausprobieren