Delphi uses Streams to read your components' default parameters from the *.dfm files (which are actually stored as a resource in the *.exe files).
It is fairly difficult to determine what stream classes are available - I have never found a list of them. (A partial list is available on the TStream help page.) The following hierarchy is based on searching the source files for class(TStream).
Class | Source File | Comment | ||||
---|---|---|---|---|---|---|
TStream | classes.pas | Abstract base class | ||||
TCustomMemoryStream | classes.pas | |||||
TMemoryStream | classes.pas | Converts a buffer (block of memory) to/from a stream | ||||
TResourceStream | classes.pas | Used to create (initialize) form components | ||||
TStringStream | classes.pas | Converts a string to/from a stream | ||||
THandleStream | classes.pas | |||||
TFileStream | classes.pas | |||||
TOleStream | axctrls.pas | Used to read and write via a COM interface | ||||
TBlobStream | dbtables.pas | Used with BLOB fields | ||||
TIBBlobStream | ibblob.pas | Interbase BLOB fields | ||||
TIBDSBlobStream | ibcustomdataset.pas | Interbase Data Set BLOB fields | ||||
TWinSocketStream | scktcomp.pas | |||||
IStream | ole2.pas | Abstract interface |
Streaming Utilities
ObjectBinaryToText ObjectTextToBinary
TMemoryStream
procedure abc; var temp: String; xx: TMemoryStream ; pc : pchar; begin xx := TMemoryStream.Create; temp := '12345'; pc := PChar(temp); xx.Write( temp, length(temp)); // fails xx.Write( @temp, length(temp)); // fails xx.Write( pc, length(temp)); // fails xx.Write( '12345', length(temp)); // works xx.Write(PChar(temp)^, length(temp)); // works xx.Write( pc^, length(temp)); // works end;
XP RichEdit Design Problem
Using text files greater than
procedure TForm1.asText1Click(Sender: TObject); var temp: String; begin temp := PlainText_UIRichEdit.Lines.Text; Formatted_UIRichEdit.Lines.Text := temp ; // This line fails end;The following code works in both 98 and XP.
procedure TForm1.xx1Click(Sender: TObject); var temp : String; xx : TMemoryStream ; pc : pchar; yy : integer; begin xx := TMemoryStream.Create; temp := PlainText_UIRichEdit.Lines.Text; pc := PChar(temp); yy := xx.Write(pc^, length(temp)); xx.Position := 0; // reset to the beginning of the stream Formatted_UIRichEdit.Lines.LoadFromStream(xx) ; xx.Free; end;This also works in both.
procedure TForm1.viaStringStream1Click(Sender: TObject); var temp : String; xx : TStringStream ; begin temp := PlainText_UIRichEdit.Lines.Text; xx := TStringStream.Create(temp); xx.Position := 0; // reset to the beginning of the stream Formatted_UIRichEdit.Lines.LoadFromStream(xx) ; xx.Free; end;This change also improved the program speed - from 12 seconds (string assignment) to 1 second (LoadFromStream) to copy the data. Author: Robert Clemenzi - clemenzi@cpcug.org