[Solved] How to find the length of user-defined ? lazarus / 21-General ---------------------------------------------------------------------- loaded · 2021-03-25 07:20 Hi All, In the attached code Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);type   EWeek = (SUN=7,MON=1,TUE=2,WED=3,THU=4,FRI=5,SAT=6);begin  ShowMessage(inttostr(high(EWeek))); //? or   ShowMessage(inttostr(length(EWeek))); //? end;  How can I find the length or high value of the constant definition? ---------------------------------------------------------------------- Mr.Madguy · 2021-03-25 07:30 First of all, it's not array - it's enumeration. ---------------------------------------------------------------------- Handoko · 2021-03-25 07:35 Documentation for Enumurated Types: https://www.freepascal.org/docs- html/current/ref/refsu4.html#x26-280003.1.1 https://www.freepascal.org/docs- html/current/prog/progsu158.html#x202-2070008.2.4 ---------------------------------------------------------------------- loaded · 2021-03-25 07:55 Mr.Madguy, thanks for the answer. I haven't paid attention until this time. You're right, not Array, it should have been the definition. Handoko thank you very much for the answer. I have investigated but haven't got the result I wanted yet. ---------------------------------------------------------------------- PascalDragon · 2021-03-25 08:00 Quote from: loaded on March 25, 2021, 08:20:22 amHow can I find the length or high value of the constant array? As the others wrote, it's an enumeration, not an array. And for enumeration you can use Low(EnumType) to retrieve the lowest value (in your case 1) and High(EnumType) to retrieve the highest value (in your case 7). Please note however that it would be better if you'd use an array without explicit values as that generates RTTI and thus could be used in more circumstances: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   EWeek = (MON,TUE,WED,THU,FRI,SAT,SUN); Of course in this case MON will be 0 and SUN will be 6. If you'd still want to have a range from 1 .. 7 you'd need to use code like this: Ord(enumvalue) + 1 or similar. ---------------------------------------------------------------------- Handoko · 2021-03-25 08:08 @loaded If you meant the size for storing the data, here: ---------------------------------------------------------------------- Zvoni · 2021-03-25 08:16 Quote from: PascalDragon on March 25, 2021, 09:00:09 am Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   EWeek = (MON,TUE,WED,THU,FRI,SAT,SUN); Of course in this case MON will be 0 and SUN will be 6. If you'd still want to have a range from 1 .. 7 you'd need to use code like this: Ord(enumvalue) + 1 or similar. Couldn't you just define the starting value with the first member? SUN sould be 7 in this case Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   EWeek = (MON=1,TUE,WED,THU,FRI,SAT,SUN); ---------------------------------------------------------------------- PascalDragon · 2021-03-25 08:47 Quote from: Zvoni on March 25, 2021, 09:16:09 amQuote from: PascalDragon on March 25, 2021, 09:00:09 am Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   EWeek = (MON,TUE,WED,THU,FRI,SAT,SUN); Of course in this case MON will be 0 and SUN will be 6. If you'd still want to have a range from 1 .. 7 you'd need to use code like this: Ord(enumvalue) + 1 or similar. Couldn't you just define the starting value with the first member? SUN sould be 7 in this case Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   EWeek = (MON=1,TUE,WED,THU,FRI,SAT,SUN); Nope, a well formed enum starts at 0 and has no holes. ---------------------------------------------------------------------- loaded · 2021-03-25 08:50 Handoko, I wanted to find the number of terms in the definition. Thank you very much Zvoni for your reply. I wouldn't have thought of Ord if I thought for 40 years. Thank you so much PascalDragon Master. May your life be long. ---------------------------------------------------------------------- PascalDragon · 2021-03-25 12:39 Quote from: loaded on March 25, 2021, 09:50:25 amI wouldn't have thought of Ord if I thought for 40 years. Thank you so much PascalDragon Master. May your life be long. Ord converts the enum value to an Integer. It works for the value itself, but not the enum type. Low and High work for the enum type. ---------------------------------------------------------------------- 440bx · 2021-03-25 15:28 Quote from: loaded on March 25, 2021, 08:20:22 amHow can I find the length or high value of the constant definition? Just in case it may be helpful to you, read the following explanation, which comes with an example, about enumerated constants https://forum. lazarus.freepascal.org/index.php/topic,53819.msg398852.html#msg398852 HTH. ---------------------------------------------------------------------- engkin · 2021-03-25 16:16 Quote from: 440bx on March 25, 2021, 04:28:05 pmQuote from: loaded on March 25, 2021, 08:20:22 amHow can I find the length or high value of the constant definition? Just in case it may be helpful to you, read the following explanation, which comes with an example, about enumerated constants https://forum. lazarus.freepascal.org/index.php/topic,53819.msg398852.html#msg398852 HTH. The explanation is remarkable. For sometime now I have suspected that you are an instructor. If you are trying to hide it, it is not working, your WinAPI posts are another fantastic proof. ---------------------------------------------------------------------- 440bx · 2021-03-25 16:31 Quote from: engkin on March 25, 2021, 05:16:48 pmThe explanation is remarkable. For sometime now I have suspected that you are an instructor. If you are trying to hide it, it is not working, your WinAPI posts are another fantastic proof. Thank you for the kind words Engkin.  I'm not an instructor by education but, I have trained people in the past and do enjoy it.  I like it when people understand. It's very satisfying. ---------------------------------------------------------------------- loaded · 2021-03-25 17:13 440bx, When I read your article, I realized that I was entering unknown regions in the pascal forest. Thank you very much for the answer. ---------------------------------------------------------------------- 440bx · 2021-03-25 17:30 Quote from: loaded on March 25, 2021, 06:13:55 pmThank you very much for the answer. You're welcome.  I'm pleased you found it useful.