Can I define a fixed length array of record types as a constant in the code file? The syntax in Delphi in Delphi is a bit convoluted, but does work
Thanks
Can I define a fixed length array of record types as a constant in the code file? The syntax in Delphi in Delphi is a bit convoluted, but does work
Thanks
why records?
Alternatively, you could define a list of objects, and flag it as a readonly property then fill it in your forms constructor.
Hi Alan, Thanks for your reply. So much of my learning is seeing how my old Delphi habits, developed over many years (good or mostly bad!), fit or donât fit the new environment. Typically, I have used arrays a lot, where each element of the array can be a complex set of data defined as a record type, so as an example (in Delphi syntax):
type TMyDataRec = record
ID: string;
Description: string;
intValue: integer;
end;
type TMyFixedArrayOfDataRecs = array[0âŚ9] of TMyDataRec;
To initialise this array with âFactoryâ ie constant values, as an initial default, I define a constant array to hold the initial 10 sets of hard coded values, then put these into the working dynamic array (also of type TMyDataRec) as its initial values.
Probably with the new stuff in Elements, all this is unnecessary, but I just wondered if a constant array of elements where each element is like TMyDataRec above is possible.
Your thoughts are very welcome.
Bob
You can do something like these:
type Tvec = record x,y,z : double; end;
var
testarray : array of Tvec :=
[
new Tvec(x := 0, y := 0, z := 1),
new Tvec(x := 0, y := 0, z := 1)
]; readonly;
These will be more or less the same a a const declaration because of the readonly
Great! That does the trick. All Iâve got to do now is work out the syntax where one element of the record Tvec, is actually another array of another record type!
Thanks for your help.
Bob
Iâm trying to use the Windows function GetSystemDefaultLangID. As a general question, what would I have to do in a Winforms project to incorporate that? Intellisense doesnât list it, and Iâm not sure what reference to include to get at it.
Thanks.
In my humble opinion, iâd start getting in the habit of using classes instead of records. They are a hell of a lot more flexible. Also, arrays are still fine to use, but especially if you are developing on .NET, I urge you to read about and learn how LINQ works. Lists are very popular, and LINQ makes âqueryingâ lists, creating subsets of lists, etc, so easy.
Hi Alan. Many thanks for your comments. This kind of advice is invaluable. As a self taught Delphi person, I managed to get through all my development applications, some quite large and complex, without ever having defined a class! So all application wide variables and constants were global, as were 99% of the supporting procedures and functions. I normally used multiple pas units to segregate the code into logical areas, and removed pretty well all routines out of the Form.pas files. I used arrays of records to hold the data brought in from the database (usually Access, sometimes SQL Server) using local in code instances of TADOQuery. I didnât use collections, because the functionality seemed limited. I have read a little about LINQ but never really got into it.
So I really would like to get out of the Delphi âmindsetâ and start to work with the Dot Net ideas. I have found it difficult to get into the âclassesâ frame of mind, and have found the RemObjects documentation limited in the tutorials and example projects - Iâve looked and understood, but lack more chunky âreal worldâ examples. Can you point me towards documentation that might help? Iâm currently reading a book about WPF, and look forward to the UI possibilities which that provides.
Anyway, your input is much appreciated, and please feel free to comment anytime.
Regards
Bob
bugs://78993 got closed with status fixed.