10-20-2011، 12:14 PM
با سورس زیر میتونید در فایل txt رو بارگذاری کرده یا در ان بنویسید
Example code : Reading single characters at a time from a text file
Example code : Reading single characters at a time from a text file
کد:
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
unit Unit1;
interface
uses
// The System unit does not need to be defined
SysUtils,
Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);
var
myFile : TextFile;
letter : char;
text : string;
begin
// Try to open the Test.txt file for writing to
AssignFile(myFile, 'Test.txt');
ReWrite(myFile);
// Write lines of text to the file
WriteLn(myFile, 'Hello');
WriteLn(myFile, 'To you');
// Close the file
CloseFile(myFile);
// Reopen the file for reading only
FileMode := fmOpenRead;
Reset(myFile);
// Display the file contents
while not Eof(myFile) do
begin
// Proces one line at a time
ShowMessage('Start of a new line :');
while not Eoln(myFile) do
begin
Read(myFile, letter); // Read and display one letter at a time
ShowMessage(letter);
end;
ReadLn(myFile, text);
end;
// Close the file for the last time
CloseFile(myFile);
end;
end.