Nigel Thomas 35 Posted April 23 Using Delphi D2007. I'm trying to do the following: type FileSig = record Offset: Integer; arrSig: array of byte; end; const sig1: FileSig = (Offset: 10; arrSig: array [0..2] of byte = ($00,$01,$02); ) But I can't: E2029 ')' expected but ',' found In D10+ I can do: const sig1: FileSig = (Offset: 10; arrSig: [$00,$01,$02]; ) Is there a way I can do similar in D2007? Share this post Link to post
JonRobertson 72 Posted April 23 27 minutes ago, Nigel Thomas said: But I can't: E2029 ')' expected but ',' found What do you get when you try const sig1: FileSig = (Offset: 10; arrSig: [$00,$01,$02]; ) in D2007? Share this post Link to post
Nigel Thomas 35 Posted April 23 3 minutes ago, JonRobertson said: What do you get when you try const sig1: FileSig = (Offset: 10; arrSig: [$00,$01,$02]; ) in D2007? E2010 incompatible types: 'dynamic array' and 'Set' Share this post Link to post
pmcgee 10 Posted April 23 1 hour ago, Lars Fosdal said: Replace the brackets with parenthesis? ^ I don't have D2007. Your D10+ version works in freepascal using {$mode delphi} and this works in fpc without it : sig2: FileSig = (Offset: 10; arrSig: ($00,$01,$02); ); 1 Share this post Link to post
David Heffernan 2345 Posted April 23 (edited) Sorry, content remove, I'm talking nonsense Edited April 23 by David Heffernan 1 Share this post Link to post
JohnLM 14 Posted April 23 (edited) This works for me in XE7. type FileSig = record Offset: Integer; text: string; arrSig: array of byte; arrStr: array of char; end; const sig1: FileSig = ( offset:10; text:'test'; arrsig:[65,66,67]; arrStr:['a','b','c'] ); var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin memo1.Lines.Add(sig1.Offset.ToString()); memo1.Lines.Add(sig1.text); memo1.Lines.Add( inttostr(sig1.arrSig[0]) ); memo1.Lines.Add('[' + ansistring(sig1.arrSig) + ']'); memo1.Lines.Add('[' + string(sig1.arrStr) +']'); end; Output Results: 10 test 65 [ABC] [abc] Edited April 23 by JohnLM removed pstring() Share this post Link to post
David Heffernan 2345 Posted April 23 (edited) Sorry, content removed, I'm talking nonsense. Edited April 23 by David Heffernan Share this post Link to post
David Heffernan 2345 Posted April 23 8 hours ago, Nigel Thomas said: Using Delphi D2007. I'm trying to do the following: type FileSig = record Offset: Integer; arrSig: array of byte; end; const sig1: FileSig = (Offset: 10; arrSig: array [0..2] of byte = ($00,$01,$02); ) But I can't: E2029 ')' expected but ',' found In D10+ I can do: const sig1: FileSig = (Offset: 10; arrSig: [$00,$01,$02]; ) Is there a way I can do similar in D2007? No, this is not possible in Delphi 2007. You can declare typed constants for fixed length arrays, but not dynamic arrays. 1 Share this post Link to post
Nigel Thomas 35 Posted April 23 5 hours ago, David Heffernan said: No, this is not possible in Delphi 2007. You can declare typed constants for fixed length arrays, but not dynamic arrays. Thanks. I've worked around it by declaring FileSig.arrSig as a fixed array, e.g: array [0..4] of byte, then I can set the const array using padding where necessary e.g. arrSig: ($00, $01, $02, $00, $00); By adding a SigLength to the FileSig type I will know what padded bytes I can remove when I come to using the array. Share this post Link to post