Maintains a global list of Lazarus resources, and provides methods and types used to stream components.

lresources.pp maintains and stores all standard Lazarus resources in the global LazarusResources list and provides methods and types for component streaming.

A Lazarus resource is streamed as an UTF-8 string, with a name, value and value type.

Lazarus resources are normally included via an include directive in the initialization part of a unit. To create such include files use the BinaryToLazarusResourceCode procedure.

To create an LRS file from an LFM file use the LFMtoLRSfile function which transforms the LFM text to binary format and stores it as Lazarus resource include file.

Author: Mattias Gaertner

lresources.pp is part of the Lazarus Component Library (LCL).

Text of the "automatically generated..." warning in resource files. Signature for a the version of the TFiler instance used to read or write value using a Lazarus Resource Stream (LRS file). Describes a Lazarus resource stored in TLResourceList. Name for the Lazarus resource. The resource type, always uppercase. The value for the resource. Container class used for Lazarus resource descriptions. Member with the list for resource descriptions. List used to MergeSort resources in the list. The number of resource descriptions in the sorted list. Returns the index of the named resource, or -1 if not found.

The list is sorted, if required.

Ordinal position for the named resource in the list, or -1 when not found. Name of the resource to locate in the list of descriptions. Sorts the list by resource name. Implements a MergeSort for the resource descriptions in the list. Performs the merge portion of the MergeSort method. Constructor for the class instance.

Allocates resources needed for the internal lists used in the class instance, and sets the default values for internal members.

Destructor for the class instance.

Frees the values in and resources allocated to the internal lists for the class instance.

Adds a resource description to the list with the specified values.

ValueType is stored in uppercase.

Name for the resource. Name for the Type used in the value. A single AnsiString value string for the type. An array with the String values for the type. Returns the resource in the list with the given name and type. TLResource instance for the resource found with the specified name and value type. Name of the resource to locate in the list. Type name for the resource to locate in the method. Should be uppercase, if present. Gets the number of resource descriptions in the list. The number of resource descriptions in the list. Provides Indexed access to the resource descriptions in the list. Helper class for streaming resources (read only). Resource in FPC format. Initializes the resource descriptor.

The descriptor must already exist.

EResNotFound if the resource does not yet exist.
The resource name. The resource type, can be Nil. Creates an resource stream for a named resource. The resource name. The resource type, can be Nil. Creates an resource stream for a resource ID. The resource ID. The resource type. Creates an resource stream from an resource descriptor. Destructor for the class instance.

Calls the UnlockResource and FreeResource routines when resource descriptors are used for the platform. Calls the inherited method prior to exit.

Raises an error on an attempt to write to the stream.

The stream data must be provided by the implemented constructors and methods.

Raises a EStreamError exception with the message in SCantWriteResourceStreamError.
The resource descriptor, owned by the global resource list. Abstract base class for translators used in the LCL.

TAbstractTranslator is a class which specifies the base class string and property translators used in the Lazarus Component Library (LCL). It defines an abstract virtual method used to translate string properties when they are read from a Lazarus Resource Stream (LRS).

Do not create instances of TAbstractTranslator; use one of the descendent class like TUpdateTranslator, TDefaultTranslator, or TPOTranslator.

TUpdateTranslator TDefaultTranslator TPOTranslator
Specifies a method used to translate a String property.

TranslateStringProperty is an abstract virtual method which defines the method used to translate a String property in a persistent object instance. TranslateStringProperty must be implemented in a descendent class to perform the actions needed to retrieve and translate the specified property value.

The address for the method is assigned as the OnReadStringProperty event handler in TReader class instances.

TReader TFiler
Object for the event notification. Persistent object with the property value translated in the method. RTTI information for the property translated in the method. Variable parameter where the translated value for the property is returned. Variable with the default translator used in CreateLRSReader.

The value for the variable is assigned when SetDefaultLang is called.

SetDefaultLang
Stack item type for the nested resource reader/writer. A list terminated by an EndList. A component has two lists: properties and children. A list with a known (stored) number of entries. Stack item for the nested resource reader. Name for the item on the LRS Reader Object stack. Identifies the type for the stack item. The number of contained collections, needing an EndList. Reader for resource streams.

Uses an stack for reading nested objects.

The input stream buffer. Size of the input buffer. Current position in the input buffer. The number of bytes in the buffer. The object stack. The Length of the allocated stack. Skip the property name, then the property value. Skips until the next empty string. Push a new resource item. The Component whose properties follow. The number of contained lists, which need an EndList. Pop an item, or decrement its PushCount.

Called on EndList (vaNull) encountered

Destroys the stack, during reader destruction. Reads the 1-byte value type. Terminate reading a Component list (properties or children). Reads an 4 byte integer value. The input stream. The stream buffer size to allocate. Peek the next byte (value type indicator). Reads the next ValueType. Pops or pushes a stack item if required (for list or collection). Reads the filer signature from the input. EReadError 'Invalid Filer Signature' on filer signature mismatch. Returns the qualified current item name. Read a number of bytes from the input stream. Reads binary data, stored with a Length prefix. Reads an Extended value (10 Bytes). The result may have less bytes, when Extended is not a 10 byte value. Reads an Single value (4 bytes). Reads an Currency value (8 bytes). Reads an Date value (8 bytes). Reads an identifier, maybe a name or a standard key (which is not stored). GDB error on an unexpected ValueType. The expected type: vaIdent for an stored name, or vaNil, vaFalse, vaTrue, vaNull for an standard string. Reads enum member names, until an empty string is read. The constructed set, as an Integer. The expected set type. Reads an ShortString. Skips an entire Component. If True: skip prefix, component class name and component object name. Skips the next value. The input stream. The root component reader. Tracking what already has been stored or written. now writing header. header saved on stack, not yet written to stream, waiting for data. header written to stream, data written. Stack item for the nested resource writer. waiting for this number of Pops. Index in a collection or list. Object writer for Lazarus Resource Streams. The TLRSObjectWriter can find empty entries and omit writing them to stream. Writes multiples words (WideChar) with reversed byte order. Constructor for the class instance.

Allocates the internal list used to store values in the Data property.

Destructor for the class instance.

Frees resources allocated for the Data property, and calls the inherited method prior to exit.

Removes items stored in the Data property.

Sets the value in the Count property to 0, which causes the items stored in Data to be freed.

Sort the items by LFM or LRS position. True for sorting by LFM position. Searches for an item by LFM or LRS position. True for searching an LFM position. Find a random item within an position range. First acceptable position. First position after the range (exclude). True for searching LFM positions. Change the position of an item within the given position range. First acceptable position. First position after the range (exclude). The new position. True for using LFM positions. Adds a new item to the Data property using the specified positions and pointer to the item data. Indexed access to the LFM positions. Indexed access to the LRS positions. Indexed access to the Data pointers. Parser for identifiers, and string and number literals.

Use to get the next token. The token type also is available in Token.

Allowed whitespace is newline (CR,LF), tab and space.

Allowed identifiers consist of ASCII letters, digits or underscore.

Strings are a sequence of quoted strings or #nn characters.

Numbers are parsed as integer or floating point values, with toFloat values subdivided into number, single, date or currency, according to FloatType.

All other characters are returned literally.

The input stream. The allocated buffer. Number of valid chars (bytes) in the buffer. Current position (index) in the buffer. Buffer-relative begin of the current line. column = fPos - fLineStart + 1 True when reached the end of the input stream. Holds the last parsed token text. The name of a token, maybe the Token character itself. Fills the buffer from the input stream. Skips to the next non-null character. Add the current character to the token string. True when the current character is a digit. True when the current character is a hex digit. True when the current character is an ASCII character (or underscore). Should mean: all allowed characters in an identifier. [To be updated for Unicode identifiers] True when the current character is a digit or IsAlpha. Returns the value of a hex digit. Parses and returns an identifier. EParserError when the current character is not valid for an identifier. Skip CR/LF, adjust SourceLine. Skip space and tab chars. Skip all whitespace characters. Marks end of input reached (fEofReached). Parse an identifier. Parse a number, recognizing trailing floating point format specifiers. Parse a hex number, prefix the token string with '$'. EParserError when no valid hex digit was found. Parse an quoted string, excluding the leading and trailing quotes. EParserError on an unterminated string literal. Parse an decimal Unicode codepoint, return it as an UTF-8 string. Is set to False on a non-ASCII character. Parses a string literal.

The string can consist of quoted strings and Unicode codepoints. Surrounding quote characters are removed.

The result is stored in fLastTokenStr, in UTF-8 encoding.

The resulting token is toString for all-ASCII strings, else toWString.

Tries to parse a negative number, or a single '-' character. Sets Token to the unrecognized character (no error). Constructor for the class instance.

Create is the constructor for the class instance.

Create allocates a 4K buffer used to store the values read from Stream. The buffer is examined in the methods for the class. It initializes internal members used in the parser implementation to their default values. The internal buffer is loaded with the first 4K block of values in Stream, and the NextToken method is called to position the parser on the first token in the buffered values.

Stream with the values parser in the class. Destructor for the class instance.

Destroy is the overridden destructor for the class instance. It moves the stream to the position returned from SourcePos (the position for the last processed value in the internal buffer). Destroy free the memory allocated for the internal buffer in the class instance.

Asserts that Token is of the expected type. EParserError when Token doesn't match the expected type. The expected token type. Asserts that the given name was parsed (case insensitive). EParserError when Token doesn't match the expected type or name. The expected identifier. Raises an EParserError with the given message. The message text. Raises an EParserError with the formatted message. The Format string. The arguments to be formatted. Raises an EParserError with the given message, adding source position information. Writes an hex value into the output stream.

The hex digits must occur in pairs, for every byte.

The binary bytes are written in input order (highest first).

EParserError on unpaired hex digits.
The output stream. Parses the next token. The token type. Returns the current position in the input stream. Parses an (possibly) qualified identifier, after a symbol has been parsed. EParserError when Token is not toSymbol. Returns the binary value of a floating point number. EParserError on an invalid number. Returns the binary value of an integral number. Returns the last parsed token as an string. Compares the parsed symbol with the given string (case-insensitive). True when a matching symbol has been parsed. The type of the parsed floating point number. (number, date...). The current line number in the input stream. The current column number in the source line. The last parsed token type. A queue to stream components, used for multi-threading or network.

ConvertComponentAsString converts a component to binary format with a leading size information (using WriteLRSInt64MB).

When streaming components over network, they will arrive in chunks. TCustomLazComponentQueue tells you, if a whole component has arrived.

Member with the dynamic storage for the queue.. Reads the component size and the length for the size value. False if there is not enough storage in the queue for the component size. Size of the component. Number of bytes needed for the component size value. Constructor for the class instance.

Allocates resources needed for the internal queue storage.

Owner of the class instance. Destructor for the class instance.

Frees resources allocated to the internal queue storage.

Clears all values in the internal queue storage. Pushes values in Buffer onto the internal storage queue. Number of bytes added to the queue in the method. Untyped buffer with values pushed onto the internal queue storage. Number of bytes in Buffer. Copies the specified number of bytes from the stream and pushes the values onto the queue. Determines whether the queue contains the entire contents of the component at the top of the queue. Reads a component from the queue and sets it owner. Converts a component to binary format with a leading size information (using WriteLRSInt64MB). Event handler signalled to get the class type for the specified class name in a TReader instance. Publishes property from the ancestor class. Published Name for the component queue. Published event handler used to get the class type for a give class name. Contains information about a property omitted from LCL component streaming.

TPropertyToSkip is a record type with information about a property in a persistent class that is omitted during LCL component streaming. TPropertyToSkip is the type maintained in the TPropertiesToSkip list when the RegisterPropertyToSkip routine is called.

Class type for the persistent object with the omitted property. Name for the omitted property. A note about the omitted property. Help keyword for the omitted property. Implements a list used to store properties which are skipped during LCL streaming. Handles a notification action when the specified Pointer is added to or removed from the list. Determines if the specified property type and name exists and is handled in the list. Gets the ordinal position in the list where the property type and name is stored. Ordinal position in the list, or -1 when not found. Property instance to locate in the list. Name for the property type to locate in the list. Class type for the property to located in the list. Adds the specified property type and name to the list when not already present. Ordinal position in the list where the skipped property was found or stored. Class type for the skipped property. Name for the skipped property. Note to associate with the skipped property. Help keyword for the skipped property. Provides indexed access to skipped properties in the list by their ordinal position.

Items is an indexed PRemovedProperty property used to access skipped property definitions by their ordinal position in the list. Read and write access for the property value ensures the inherited Get or Put methods are called.

Ordinal position for the indexed property value. The list with all of the loaded standard resources. Unit global variable with all of the registered skipped properties. Class type for Lazarus Object Reader instances. Class type for Lazarus Object Writer instances.

FPC is not optimized for building a constant string out of thousands of lines. It needs huge amounts of memory and becomes very slow. Therefore big files are split into several strings.

ReadLFMHeader is an overloaded procedure used to read the header for the LFM resource. The overloaded variants allow the LFM content to be read from either a TStream instance or a string value.

Values for the LFM resource type (optional), component name, and class name are returned in the corresponding output variables.

ReadLFMHeader is used to implement portions of the Lazarus IDE like the form editor, project inspector, and source code file manager.

Modified in LCL 2.4 to support use of unit name as a name space for classes in a LFM resource.
TStream instance with the LFM content read in the routine. Output variable which returns the type token for a resource item. Output variable which returns the component name token for a resource item. Output variable which returns the class name token for a resource item. Allows unit name to be included as a name space for the class. String type with the LFM content read in the routine. Reads the LFM header from the specified file name. Returns True if the resource header is successfully read from the file and the LFM class name contains a non-empty value. File with the LFM content read in the routine. Returns the resource type in the LFM header. Normally 'object'. Returns the component name read from the LFM header. Like 'Form1'. Returns the class name read from the LFM header. Like 'TForm1', but may also include a unit name space such as 'ns.unit2/TForm2'. Represent the LRS stream format offered as the original content for conversion routines like LRSObjectToText and LRSObjectResToText. Format for the LRS stream is unknown. LRS stream contains binary content. LRS stream contains the text content. Writes a Word value to the specified resource stream.

For platforms where FPC_LITTLE_ENDIAN is defined, the Write method in the Stream is called write the bytes in the word value. For Big Endian platforms, the WriteLRSReversedWord routine is called to write the byte values to the stream.

TStream instance where the value is written. Word value written in the routine. Writes an integer value, using the smallest possible representation. Writes the specified number of Null characters to a TStream instance.

An ASCII NUL character has the value #0.

TStream instance where the Null characters are written in the routine. Number of Null characters written to the stream. If 0 is specified, a single null character is still written to the stream. Registers the component TLazComponentQueue. Raises an EReadError exception. Raises an InvalidPropertyValue EReadError.