Forum > General
[Solved] What is wrong with my record declaration.
(1/1)
BrunoK:
The following program compiles (kept a bit of non concerned code) :
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program pgmCasedRecord; {$mode Delphi}{$H+}{$Modeswitch advancedrecords} type PDWordSub = ^RDWordSub; { RDWordSub } RDWordSub = packed record public type TSubsType = (stSet0, // Work on set pairs : Record belongs to set 0 stSet1); // TSubsTypes = set of TSubsType; private function InitBound(aDw: DWord; aRngHead: boolean): PDWordSub; public case boolean of False: (dw: DWord; // DWord boundary ss: shortint; // set id, bitset [0..6] indicating which set holds the record // [0] is the lead set. h: shortint); // 0 -> start of subset , 1 (or >1)-> end of subset True: (plim: PDWordSub); // Used to store work in list pointers end;const cMaxWSubs = 1 shl 12; // 2^12 4 k items -> 2k subranges type { Work array created 'on the fly' by routines needing range manipulation } TArSubs = array[0..cMaxWSubs] of RDWordSub; // [cMaxWSubs]=Count(used). { RDWordSub } function RDWordSub.InitBound(aDw: DWord; aRngHead: boolean): PDWordSub;begin Result := nil;end; begin end.But this one with the private (same if it had been public btw) declaration moved after the case boolean fails with messages
project1.lpr(27,3) Error: Identifier not found "private"
project1.lpr(28,5) Error: Illegal expression
project1.lpr(28,5) Error: Syntax error, ":" expected but "FUNCTION" found
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program pgmCasedRecord; {$mode Delphi}{$H+}{$Modeswitch advancedrecords} type PDWordSub = ^RDWordSub; { RDWordSub } RDWordSub = packed record public type TSubsType = (stSet0, // Work on set pairs : Record belongs to set 0 stSet1); // TSubsTypes = set of TSubsType; public case boolean of False: (dw: DWord; // DWord boundary ss: shortint; // set id, bitset [0..6] indicating which set holds the record // [0] is the lead set. h: shortint); // 0 -> start of subset , 1 (or >1)-> end of subset True: (plim: PDWordSub); // Used to store work in list pointers private function InitBound(aDw: DWord; aRngHead: boolean): PDWordSub; end;const cMaxWSubs = 1 shl 12; // 2^12 4 k items -> 2k subranges type { Work array created 'on the fly' by routines needing range manipulation } TArSubs = array[0..cMaxWSubs] of RDWordSub; // [cMaxWSubs]=Count(used). { RDWordSub } function RDWordSub.InitBound(aDw: DWord; aRngHead: boolean): PDWordSub;begin Result := nil;end; begin end.
What is wrong with the second declaration of case of boolean ?
bytebites:
Variant part must last in record declaration?
BrunoK:
--- Quote from: bytebites on September 07, 2024, 12:56:50 pm ---Variant part must last in record declaration?
--- End quote ---
Thank you, that's it. The documentation https://www.freepascal.org/docs-html/ref/refsu15.html states :
--- Quote ---The variant part must be last in the record.
--- End quote ---
I just, wrongly, expected that advanced methods would not be considered as part of the record data.
jamie:
If you want a Variant record in the middle of your record with more data following, you need to wrap it with a record within.
of Course, this adds a name space in your record since you can't have anonymous record in there for nameless unions.
But I am sure you already know this.
Navigation
[0] Message Index