| Description | uses | Classes, Interfaces, Objects and Records | Functions and Procedures | Types | Constants | Variables |
Kambi class utilities.
This unit contains stuff for dealing with non-visual classes. Basically, it can be considered as the extension of Classes unit from RTL. It contains many wrappers for classes that are defined in the Classes unit and also defines some basic useful classes made entirely on my own. It also contains many global functions that deal with some classes defined in Classes unit.
Some notes about TStream descendants :
I call a stream "purely sequential" (or just "sequential") if it allows only reading and/or writing of data and does not allow free "Seek" calls, in particular — it does not allow Seek to move back in a stream.
I call a stream "growing" if it's read-only and it's purely sequential and it's Size property is useless. In other words, when you read a "growing" stream, you don't know when it ends, until you reach the end. You just have to read data until Read returns 0.
Some question related to "growing" streams:
Reading the Borland's help it's not clear whether after
ReadCount := Stream.Read(Buf, Count)
one should test
ReadCount = 0
or rather the test
ReadCount < Count
is sufficient.
In other words, if Read can't read exactly Count bytes but it can read some bytes (more than zero) : can we then be sure we're standing at the end of a stream ? Or maybe we should call Read once again and only if this time ReadCount = 0 we are sure it's the end of stream ? Answer : test "ReadCount = 0" is good. Test "ReadCount < Count" is not sufficient in many cases (e.g. with THandleStream when handle is stdin (so StdinStream defined in this unit is "growing") or with net socket streams).
This question occurs only when you have to deal with "growing" streams — with non-growing streams you can always test whether Stream.Position <= Stream.Size. And, thinking about implementation of various non-growing streams, one can be relatively sure that the test "ReadCount < Count" will be usually sufficient.
| Name | Description |
|---|---|
Class TTextReader |
TTextReader reads given Stream line by line. |
Class TKamIniFile |
TIniFile with minor enhancements. |
Class TObjectsList_Abstract |
|
Class TMemoryFileStream |
This is TMemoryStream that at the end of construction loads it's contents from file AFileName, and (if not ReadOnly) at the beginning of destruction saves it's contents to file. |
Class EStreamNotImplemented |
|
Class EStreamNotImplementedWrite |
|
Class EStreamNotImplementedSeek |
|
Class EStreamNotImplementedSetSize |
|
Class TPeekCharStream |
This is a purely sequential read-only stream. |
Class TSimplePeekCharStream |
This is a simplest non-abstract implementation of abstract TPeekCharStream class. |
Class TBufferedReadStream |
This implements abstract TPeekCharStream class, so this is purely sequential read-only stream that reads from underlying SourceStream and you can use PeekChar and ReadChar and ReadUpto routines. |
procedure FreeWithContentsAndNil(var Obj); |
procedure StringsAdd(Strs: TStrings; Count: integer; itemVal: string='dummy'); overload; |
procedure AddStrArrayToStrings(const StrArr: array of string; strlist: TStrings); |
procedure Load_Strings(IniFile: TIniFile; const section: string; Strs: TStrings); overload; |
procedure Save_Strings(IniFile: TIniFile; const section: string; Strs: TStrings); overload; |
procedure AddPathsFromFileLines(slist: TStrings; const fname: string); |
procedure AddPathsFromEnvironmentVar(slist: TStrings; const varname: string); |
procedure AddPathsFromPathList(slist: TStrings; const pathlist: string); |
function StringsSeparated(slist: TStrings; const separator: string): string; |
function SearchSortedList(List: TStrings; const Value: string): Integer; |
procedure Strings_AddSplittedString(Strings: TStrings; const S, Splitter: string); |
procedure Strings_AddVrmlEngineProgramHelpSuffix( Strings: TStrings; const DisplayProgramName: string; const Version: string; WrapLines: boolean); |
procedure Strings_SetText(SList: TStrings; const S: string); |
procedure Strings_Trim(Strings: TStrings; MaxCount: Cardinal); |
procedure StringList_FreeWithContentsAndNil(var StringList: TStringList); |
procedure AppendStream(DestStream, OwnedSourceStream: TStream); |
procedure StreamWriteLongWord(Stream: TStream; const Value: LongWord); |
function StreamReadLongWord(Stream: TStream): LongWord; |
procedure StreamWriteByte(Stream: TStream; const Value: Byte); |
function StreamReadByte(Stream: TStream): Byte; |
procedure WriteStr(Stream: TStream; const S: string); overload; |
procedure WritelnStr(Stream: TStream; const S: string); overload; |
procedure WriteStr(const S: string); overload; |
procedure WritelnStr(const S: string); overload; |
function StreamReadChar(Stream: TStream): char; |
function StreamReadZeroEndString(Stream: TStream): string; |
function StreamReadUpto_NotEOS(Stream: TStream; const endingChars: TSetOfChars; backEndingChar: boolean; out endingChar: char): string; overload; |
function StreamReadUpto_NotEOS(Stream: TStream; const endingChars: TSetOfChars; backEndingChar: boolean): string; overload; |
function StreamReadUpto_NotEOS(Stream: TStream; const endingChars: TSetOfChars; out endingChar: char): string; overload; |
function StreamReadUpto_NotEOS(Stream: TStream; const endingChars: TSetOfChars ): string; overload; |
function StreamReadUpto_EOS(Stream: TStream; const endingChars: TSetOfChars; backEndingChar: boolean; out endingChar: integer): string; overload; |
function StreamReadUpto_EOS(Stream: TStream; const endingChars: TSetOfChars; backEndingChar: boolean): string; overload; |
function StreamReadUpto_EOS(Stream: TStream; const endingChars: TSetOfChars; out endingChar: integer): string; overload; |
function StreamReadUpto_EOS(Stream: TStream; const endingChars: TSetOfChars ): string; overload; |
function StreamPeekChar_NotEOS(Stream: TStream): char; |
function StreamPeekChar_EOS(Stream: TStream): integer; |
function CreateReadFileStream(const filename: string): TStream; |
procedure ReadGrowingStream(GrowingStream, DestStream: TStream; ResetDestStreamPosition: boolean); |
function ReadGrowingStreamToString(GrowingStream: TStream): string; |
procedure StreamWriteString(Stream: TStream; const s: string); |
function StreamReadString(Stream: TStream): string; |
function StreamToString(Stream: TStream): string; |
procedure StreamSaveToFile(Stream: TStream; const FileName: string); |
procedure CreateIfNeeded(var Component: TComponent; ComponentClass: TComponentClass; Owner: TComponent); |
TStringListCaseSens = TStringList; |
DefaultReadBufferSize = 1024 * 1024; |
StdInStream:TStream; |
StdOutStream:TStream; |
StdErrStream:TStream; |
StdInReader: TTextReader; |
procedure FreeWithContentsAndNil(var Obj); |
|
Equivalent to FreeAndNil, but calls FreeWithContents instead of Free. Be careful — pass here only TObjectsList_Abstract descendants ! |
procedure StringsAdd(Strs: TStrings; Count: integer; itemVal: string='dummy'); overload; |
|
Add some strings to TStrings |
procedure AddStrArrayToStrings(const StrArr: array of string; strlist: TStrings); |
|
Add all strings from string array to TStrings object. |
procedure Save_Strings(IniFile: TIniFile; const section: string; Strs: TStrings); overload; |
procedure AddPathsFromFileLines(slist: TStrings; const fname: string); |
|
Append to SList some directiories.
All appended directories are guaranteed to end with PathDelim. |
procedure AddPathsFromEnvironmentVar(slist: TStrings; const varname: string); |
procedure AddPathsFromPathList(slist: TStrings; const pathlist: string); |
function StringsSeparated(slist: TStrings; const separator: string): string; |
|
zwraca wszystkie stringi z slist sklejone separatorem. |
procedure Strings_AddVrmlEngineProgramHelpSuffix( Strings: TStrings; const DisplayProgramName: string; const Version: string; WrapLines: boolean); |
|
Something like SVrmlEngineProgramHelpSuffix, but appends contents as a couple of lines to Strings. |
procedure Strings_SetText(SList: TStrings; const S: string); |
|
Use this instead of |
procedure Strings_Trim(Strings: TStrings; MaxCount: Cardinal); |
|
If Strings.Count is larger than MaxCount then it will delete the last strings (to make Strings.Count = MaxCount). |
procedure StringList_FreeWithContentsAndNil(var StringList: TStringList); |
|
Free all objects within the StringList, then free and set to |
procedure StreamWriteLongWord(Stream: TStream; const Value: LongWord); |
function StreamReadLongWord(Stream: TStream): LongWord; |
procedure StreamWriteByte(Stream: TStream; const Value: Byte); |
function StreamReadByte(Stream: TStream): Byte; |
procedure WriteStr(Stream: TStream; const S: string); overload; |
|
This simply writes Length(s) bytes starting from s[1]. Versions with "ln" append nl, end of the line marker, to this. Versions without Stream param write to StdOutStream. |
procedure WritelnStr(Stream: TStream; const S: string); overload; |
procedure WriteStr(const S: string); overload; |
procedure WritelnStr(const S: string); overload; |
function StreamReadChar(Stream: TStream): char; |
|
reads one char from stream using ReadBuffer (so EReadError will be raised if end of stream) |
function StreamReadZeroEndString(Stream: TStream): string; |
function StreamReadUpto_NotEOS(Stream: TStream; const endingChars: TSetOfChars; backEndingChar: boolean; out endingChar: char): string; overload; |
|
StringReadUpto_NotEOS czyta strumien az do jakiegos znaku sposrod endingChars. Jezeli wczesniej napotka koniec strumienia - exception Stream Read Error. Zwrocony result nie zawiera endingChar. Wersja 2-argumentowa po prostu o nim "zapomina" - jezeli jej uzyjesz i backEndingChar = false, nie dowiesz sie jaki znak sposrod endingChars zatrzymal czytanie. Jezeli nie podasz backEndingChar to bedzie znaczylo ze nie ma go zwracac (tak samo jakbys podal false). NOTE: not every stream can back characters - it is implemented as Seek(-1, soFromCurrent) and some streams in FCL/VCL simply raise exception when we're doing this ! This is a problem with TStream class, not with our code. Use TPeekCharStream if you want to avoid this uncertainty, i.e. if you need functionality of StreamReadUpto_Xxx without using tricks with changing Position of the stream. |
function StreamReadUpto_NotEOS(Stream: TStream; const endingChars: TSetOfChars; backEndingChar: boolean): string; overload; |
function StreamReadUpto_NotEOS(Stream: TStream; const endingChars: TSetOfChars; out endingChar: char): string; overload; |
function StreamReadUpto_NotEOS(Stream: TStream; const endingChars: TSetOfChars ): string; overload; |
function StreamReadUpto_EOS(Stream: TStream; const endingChars: TSetOfChars; backEndingChar: boolean; out endingChar: integer): string; overload; |
|
StringReadUpto_EOS czyta az napotka znak sposrod endingChars lub koniec strumienia. Zwraca endingChar = -1 w tym przypadku, jezeli endingChar <> -1 to mozesz swobodnie wziac Chr(endingChar) i masz znak ktory zakonczyl czytanie. Podobnie jako _NotEOS, zwrocony result nie zawiera endingChar. |
function StreamReadUpto_EOS(Stream: TStream; const endingChars: TSetOfChars; backEndingChar: boolean): string; overload; |
function StreamReadUpto_EOS(Stream: TStream; const endingChars: TSetOfChars; out endingChar: integer): string; overload; |
function StreamReadUpto_EOS(Stream: TStream; const endingChars: TSetOfChars ): string; overload; |
function StreamPeekChar_EOS(Stream: TStream): integer; |
function ReadGrowingStreamToString(GrowingStream: TStream): string; |
|
This is like ReadGrowingStream, but it returns read contents as a string. |
procedure StreamWriteString(Stream: TStream; const s: string); |
|
read and write string as Length(s) (4 bytes) + s contents (Length(s) bytes). |
function StreamReadString(Stream: TStream): string; |
function StreamToString(Stream: TStream): string; |
|
Convert whole Stream to string. This changes Stream.Position to 0 and then reads Stream.Size bytes, so be sure that Stream supports these operations. |
procedure StreamSaveToFile(Stream: TStream; const FileName: string); |
procedure CreateIfNeeded(var Component: TComponent; ComponentClass: TComponentClass; Owner: TComponent); |
|
If Component = nil then it will do Component := ComponentClass.Create(Owner); |
TStringListCaseSens = TStringList; |
|
This is supposed to be TStringList that is case sensitive. TODO: In FPC >= 2.0.0 TStringList.CaseSensitive property was added. However, TStringList.CaseSensitive should always be left false (because of a bug, see [http://www.freepascal.org/bugs/showrec.php3?ID=4698]). So with FPC 2.0.0 and 2.0.2 we can't have CaseSensitive TStringList. I use this type to mark the places in my code that are vulnerable to this FPC bug. |
DefaultReadBufferSize = 1024 * 1024; |
StdInStream:TStream; |
|
Streams that wrap standard input/output/error of the program. Note that you can't simultaneously read from Notes for Windows:
|
StdOutStream:TStream; |
|
Streams that wrap standard input/output/error of the program. Note that you can't simultaneously read from StdInStream and StdInReader (see comments at TTextReader class). Notes for Windows:
|
StdErrStream:TStream; |
|
Streams that wrap standard input/output/error of the program. Note that you can't simultaneously read from StdInStream and StdInReader (see comments at TTextReader class). Notes for Windows:
|
StdInReader: TTextReader; |