Autor Beitrag
theTJ
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 43

WIN XP: SP1
D7 enterprise
BeitragVerfasst: Mo 09.05.05 20:16 
Hi,

ich möchte aus einer Datei in ein TMemo reinschreiben...


Habe den Code aus meinem "Lern"-Buch Teilweise übernommen und angepasst, aber irgentwas Funtzt nicht, da ich Text in der Datei habe Funktioniert das mit FileSize nicht...

Hier der Code der Funktion
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button11Click(Sender: TObject); {Laden}
var f: TextFile;
    s: String;
    anz, i: Integer;
    werte: Array[1..200] of Integer;
begin
 Protokoll.Lines.Clear;
 OpenDialog.Execute;
 AssignFile(f, OpenDialog.FileName);
 Reset(f);
 anz := FileSize(f);
  For i := 1 to anz do
   ReadLN(f, werte[i])
   Protokoll.Lines.Add(s);

 CloseFile(f);
end;


irgentwas passt da nicht...

Kann mir jemand helfen???

_________________
theTJ
"Die Antwort auf die Frage nach dem Leben, dem Universum und dem ganzen Rest ist 42, aber was ist die Frage genau?" aus "Per Anhalter durch die Galaxis" von Douglas Adams
feivel3333
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190

W7
Delphi XE prof
BeitragVerfasst: Mo 09.05.05 20:23 
Hi, nimm mal diese hier:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function File_Read( csFile : string ) : string;  // Liest aus einer Datei alles in die Variable cInhalt

var oAsciiFile : TextFile;
    csString   : string;


begin
   AssignFile( oAsciiFile, csFile );
   Reset( oAsciiFile );
   while not eof( oAsciiFile ) do begin
      ReadLn( oAsciiFile, csString );
      result := result + csString + CRLF;
      Application.ProcessMessages;
   end;
   CloseFile( oAsciiFile );
end;

Die Punkte habe ich nur wegen der Einrückung gemacht, die hier leider flöten ging.

Der Rückgabewert der Funktion ist der Text, der sich in der Datei befindet.

Mit einem Aufruf von

ausblenden Delphi-Quelltext
1:
Memo1.Text := File_Read( 'C:\Autoexec.bat' ); // (deine Datei angeben)					


bekommst du den Text in das Memo.


Gruß, AS

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.


Zuletzt bearbeitet von feivel3333 am Mo 09.05.05 20:33, insgesamt 1-mal bearbeitet
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 09.05.05 20:27 
Kurzversion:

ausblenden Delphi-Quelltext
1:
Mome1.Lines.LoadFromFile('test.txt');					


That's it ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
feivel3333
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190

W7
Delphi XE prof
BeitragVerfasst: Mo 09.05.05 20:36 
Tausend Wege führ´n nach Rom. Diesen kannte ich noch nicht.
theTJ Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 43

WIN XP: SP1
D7 enterprise
BeitragVerfasst: Mo 09.05.05 20:37 
:?
user profile iconBenBE hat folgendes geschrieben:
Kurzversion:

ausblenden Delphi-Quelltext
1:
Mome1.Lines.LoadFromFile('test.txt');					


That's it ...
:? :? Das FUntzt...??? mal testen


[EDIT]Krass das Funtzt ja wirklich THX
@feivel3333: du könntest auch einfach das [ delphi ] -Tag benutzen...
[/EDIT]

_________________
theTJ
"Die Antwort auf die Frage nach dem Leben, dem Universum und dem ganzen Rest ist 42, aber was ist die Frage genau?" aus "Per Anhalter durch die Galaxis" von Douglas Adams
MenzeChristian
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mo 30.05.05 07:30 
Ich Versuche grade in das Memo feld eine RTF Datei einzulesen. Ich würde gerne die Formatierung aus der Datei für das Memo übernehmen. Leider klappt das nicht. Hat jemand ne andere Idee ?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
if TreeView1.Selected.Text = 'AGB' then begin
   Memo1.Lines.Clear ;
   Memo1.Lines.LoadFromFile('Daten/AGB/Agb.rtf');
   end;
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: Mo 30.05.05 07:41 
Dafür musst Du die RichEdit Komponente benutzen, Memo unterstützt das nicht !


ausblenden Delphi-Quelltext
1:
2:
3:
4:
if TreeView1.Selected.Text = 'AGB' then begin  
   RichEdit1.Lines.Clear ;  
   RichEdit1.Lines.LoadFromFile('Daten/AGB/Agb.rtf');  
   end;
MenzeChristian
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mo 30.05.05 08:03 
Habs Grade ausprobiert , funktioniert super. Thx