The DataCAD Developer Network (DDN) is an online resource for information and support for DCAL® (DataCAD Applications Language) developers as well as anyone interested in creating fonts, toolbars, hatch patterns, or linetypes for use in DataCAD.
#41786 by Jsosnowski
Mon Feb 23, 2009 12:30 pm
In reviewing the Urecords.pas file I found a basic Delphi language question. The declaration for an "Entity" is a pcked record with a series of standard fields follwowed by a case statement that identifies the differences in the specific entity types. (ie Lines have 2 points, circles have point radius and other data, etc.) The Case statement reads:
Code: Select all CASE aSInt OF
         entlin: (linpt1,
            linpt2: point);
         entln3: (ln3pt1,
            ln3pt2: point);
         ....
End;


aSint (an integer) is a declared type, not a variable, so what is the variable that determines what type of entity is in the record? The first field is enttype, but it is a byte, not an aSint.

Does anyone have any ideas, thoughts, knowledge, snide remarks?
#42034 by ERT
Sun Mar 08, 2009 4:53 pm
Hello,

aSint only is a declared type: this is no determines anything,
it's a needed structure formula

This is a variable record.

Only you determines that read the data from the record.
#42062 by Jsosnowski
Tue Mar 10, 2009 10:30 am
Here is what I learned:

When presented with a case statement in a record declaration, Delphi will allocate memory to encompass the largest requirements defined in the Case statement using the same memory area. The data for a line, circle polygon etc. all have the same offset (start point) in the memory structure for the record. The asint reference is not relevant except as a place holder for writing the record structure using the case statement. In use, the code that uses the data knows how to read the specifics. In the case of entities, the enttype field tells datacad what format should be used to read the data from the case statement. If the entity is a circle, it is read from the datablock as data for a circle. If you identified the data as a polygon, instead, but handed it the same data record, it would try to read the same memory area as if it contained a polygon (it would get meaningless information, but would still try).

Thanks ERT. Variable Records were an element of Delphi I had not been aware of in my reading. (I guess I fell asleep in that chapter.)
#42083 by ERT
Thu Mar 12, 2009 12:39 am
Hello

The RECORD structure is a simple structure.
Only data, have not knowledge. It is a simple data.

My favorite structure:
Code: Select all   
   TInteger = packed record case Byte of
       0: (L: Integer);
       1: (LW: LongWord);
       2: (WL, WH: Word);
       3: (W: array[0..1] of Word);
      13: (Wx: array[1..2] of Word);
       4: (SL, SH: SmallInt);
       5: (S: array[0..1] of SmallInt);
      15: (Sx: array[1..2] of SmallInt);
       6: (B0, B1, B2, B3: Byte);
      16: (Bx1, Bx2, Bx3, Bx4: Byte);
       7: (B: array[0..3] of Byte);
      17: (Bx: array[1..4] of Byte);
       8: (C0, C1, C2, C3: Char);
      18: (Cx1, Cx2, Cx3, Cx4: Char);
       9: (C: array[0..3] of Char);
      19: (Cx: array[1..4] of Char);
   end ;


All line read the same four bytes, but on different mode.

The other simple structures:
Code: Select all    TString: packed record case byte of
        1: (Str: ShortString);
        2: (Len: Byte;
             Data: array[1..255] of Byte);
    end ;

    TData: packed record case byte of
        1: (SS: ShortString);   //use all 256 bytes
        2: (I: Integer);        //use first 4 bytes
        3: (E: Extended);       //use first 10 bytes
        4: (W: Word);           //use first 2 bytes
        5: (C: Char);           //use first byte
        6: (AS: AnsiString);    //use first 4 bytes
    end ;

and a simple, one bye length structure: this is a simple converter
Code: Select all    TByte: packed record case byte of
        1: (B: Byte); 
        2: (I: ShortInt);       
        3: (O: Boolean);     
        4: (C: Char);           
    end ;

    var A: TByte;
        X: Char;

    begin
        A.B := 65;
        X := A.C;         //same X := Char(65); or X := Chr(65);
    end .                 //     type convert   or   special function



This is a game with bytes.

or a game with words:
Code: Select all    TWord: packed record case byte of
        1: (W: Word); 
        2: (B: array[1..2] of Byte);       
        3: (O: WordBool);     
        4: (S: SmallInt);           
    end ;


IMPORTANT: these games are only working correctly with packed record

From Delphi Help:
By default, the values in a structured type are aligned on word or double-word boundaries for faster access.
When you declare a structured type, you can include the reserved word packed to implement compressed data storage.
Using packed slows data access.


and look for "Variant parts in records" in Delphi Help.
You can found there excact description.
(Beacuse my English known is few.)

Who is online

Users browsing this forum: No registered users and 9 guests

About DataCAD Forum

The DataCAD Forum is a FREE online community we provide to enhance your experience with DataCAD.

We hope you'll visit often to get answers, share ideas, and interact with other DataCAD users around the world.

DataCAD

Software for Architects Since 1984