Places the string parameter into the text stream, end of line characters (#13#10), and then returns the text stream.
The text stream is returned to allow you to chain together Put method calls (for example, Put('a').Put(123).PutEOL).
Namespace: GStreams
Delphi
|
public
function PutLine(const Str: String): TGTextStream; virtual;
|
Parameters
Str
Type: String
Return Value
Type: TGTextStream
The following example writes out some information and then reads it back. Note that without spaces or other delimiters between Puts the Get method calls would not work. The Get method calls need delimiters; methods like PutLine, which automatically writes end of line delimiters, or WriteLn, which writes spaces between the fields, ensure the correct reading behavior:
Delphi
|
var
FileStream: TGTextStream;
begin
if (SaveDialog.FileName <> '') or SaveDialog.Execute then
begin
FileStream := TGTextStream.Create( SaveDialog.Filename, fmCreate );
try
FileStream.PutLine( eFirstName.Text );
FileStream.PutLine( eLastName.Text );
FileStream.WriteLn( [seAge.Value, rgMaritalStatus.ItemIndex] );
FileStream.PutLine( eLastEmployer.Text );
FileStream.WriteLn( [seYearsAtJob.Value, seNumJobs.Value,
cbJobTitle.ItemIndex, rgDelphiKnowledge.ItemIndex, rgDatabaseKnowledge.ItemIndex, rgComponentKnowledge.ItemIndex, rgGraphicsKnowledge.ItemIndex] );
finally
FileStream.Free;
end;
OpenDialog.FileName := SaveDialog.FileName;
end;
end;
var
FileStream: TGTextStream;
begin
if OpenDialog.Execute then
begin
FileStream := TGTextStream.Create( OpenDialog.Filename, fmOpenRead );
try
eFirstName.Text := FileStream.GetLine;
eLastName.Text := FileStream.GetLine;
seAge.Value := FileStream.GetInteger;
rgMaritalStatus.ItemIndex := FileStream.GetInteger;
FileStream.SkipSpaces;
eLastEmployer.Text := FileStream.GetLine;
seYearsAtJob.Value := FileStream.GetInteger;
seNumJobs.Value := FileStream.GetInteger;
cbJobTitle.ItemIndex := FileStream.GetInteger;
rgDelphiKnowledge.ItemIndex := FileStream.GetInteger;
rgDatabaseKnowledge.ItemIndex := FileStream.GetInteger;
rgComponentKnowledge.ItemIndex := FileStream.GetInteger;
rgGraphicsKnowledge.ItemIndex := FileStream.GetInteger;
mmApplicant.Lines.Clear;
eJobOffer.Text := '';
eStartingSalary.Text := '';
finally
FileStream.Free;
end;
SaveDialog.FileName := OpenDialog.Filename;
end;
end;
|
|