Multiple recording options

I am writing a small tool for processing SWF files using Delphi XE2. So far, I am just following the SWF specification , and now I am faced with a small problem when implementing a data structure for representing shapes.

SWF forms contain multiple form entries. Form records can be edge or limitless records, and each of these two types has two additional subtypes.

In particular, on page 135 of the specification, two types of edgeless entries are described; EndShapeRecord and StyleChangeRecord . In a SWF file, the way to distinguish between them is to check whether all five bits of the flag (after TypeFlag) are 0; if they are, it is a EndShapeRecord , otherwise it is a StyleChangeRecord .

To help me process the form entries later, I would like to combine the edge and non-edge entries into a single entry type using a variant entry. The distinction between the different kinds of records is quite simple; writing a nested variant allows me to easily switch to writing edges, and for records without an edge, I can declare 5 flags from StyleChangeRecord and write the IsEndRecord function.

However, in the interest of keeping my source code as close to the specification as possible, I would like to take it one step further. The presence of other fields in StyleChangeRecord based on the values ​​of these 5 flags, so I would like to be able to declare 5 record options, one per flag, which contain the fields added by each flag. (I understand that this will not affect memory usage in any way, but it is not.)

Unfortunately, Delphi does not seem to allow more than one variant part per β€œlevel”, and trying to define these 5 variants of parts on the same level simply throws a ton of syntax errors.

 TShapeRecord = record case EdgeRecord: Boolean of False: ( case StateMoveTo: Boolean of True: ( MoveBits: Byte; MoveDeltaX: Int32; MoveDeltaY: Int32; ); case StateLineStyle: Boolean of // << Errors start here True: (LineStyle: UInt16); //Additional flags ); //Fields for edge records end; 

In slightly simpler terms, the goal is to be able to formulate a record as follows:

 TNonEdgeRecord = record case StateMoveTo: Boolean of True: ( MoveBits: Byte; MoveDeltaX: Int32; MoveDeltaY: Int32; ); case StateLineStyle: Boolean of True: (LineStyle: UInt16); end; 

... without deleting variants of a part of a record and without their nesting (since nesting will mean an incorrect attitude from a syntactical point of view).

Is there any other way I can declare a few (non-nested) variants of parts in the records, or can I just return to not using variant records for the inner part?

+6
source share
1 answer

Not. The Borland Pascal branch only accepts part variations at the end of a recording.

Nesting is the only way.

For some interesting examples and observations, see this article by Rudi Veltius:

http://rvelthuis.de/articles/articles-convert.html (search for the "union" part)

+5
source

Source: https://habr.com/ru/post/900401/


All Articles