delphi - C#: How to access an unmanaged, 2-Dbinary array nested in a struct? -
problem: i'm trying access binary records created in borland delphi , stored in sql server database (as blob).
q: heck syntax accessing two-d array in c#????
here's example: const max_bowlers = 8; gmax_frames = 40; ...
type
tframe = record balls : array[1..3] of shortint; // pins standing: balls 1, 2 , 3 pins : array[1..3] of shortint; currentball : byte; score : integer; // current score (-1= undefined) attributes : tframeattributes; ...
tframes = array[1..max_bowlers, 0..gmax_frames] of tframe;
tgamerec = record side : byte; bowlers : tbowlers; frames : tframes; ...
soooooooo....
i've got valid "gamerec" on c#-land.
i want access gamerec.frames[ibowler, iframe].
q: how define c# type "tframes = array[1..max_bowlers, 0..gmax_frames] of tframe;" can it?
thank in advance .. psm
i found solution:
treat 2-d array own struct, containing array.
the contained array 1d, consisting of cols * rows elements
provide c# "indexed property" external clients can access elements though in 2-d array (which, in terms of memory layout, are!)
// c# definition delphi 2-d array [structlayout(layoutkind.sequential, pack = 4)] public unsafe struct tframes { [marshalas(unmanagedtype.byvalarray, sizeconst=(max_bowlers)*(gmax_frames+1))] private tframe[] row; public tframe this[int ibowler, int iframe] { { int ioffset = (ibowler * (gmax_frames+1)) + iframe; return row[ioffset]; } } }
// c# client example public static string convertsplittostring(tgamerec currentgame, int ibowler) { stringbuilder sb = new stringbuilder(); tframes frames = currentgame.frames; (int iframe = 0; iframe < 10; iframe++) { if (frames[ibowler, iframe].fsplit != 0) sb.append('.'); else sb.append(' '); } return sb.tostring (); }
Comments
Post a Comment