for achar := 'A' to 'Z' do lazarus / 62-General ---------------------------------------------------------------------- Fred vS · 2022-10-23 18:49 Hello. I just tested this 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 loop_of_char;varachar : char;begin  for achar := 'A' to 'Z' do writeln(achar);end;  And (Wow) it gives me all the uppercase letters of the latin alphabet. But it is safe to do that ? ---------------------------------------------------------------------- Thaddy · 2022-10-23 19:02 This is a bit more safe: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 var a: char;begin   for a in ['A'..'Z'] do writeln(a);end.But your code is safe too. ---------------------------------------------------------------------- MarkMLl · 2022-10-23 19:02 I think it should be, because of the strictures that apply to Pascal identifiers: I remember comment on this from Jonas et al. when somebody wanted to know if the compiler could be modified to run on an EBCDIC-based mainframe. However it might still be safer to use AnsiChar. MarkMLl ---------------------------------------------------------------------- Thaddy · 2022-10-23 19:38 I agree that - given modern Pascal - dialects it is always better to write the intention. But in this case it makes no difference either way. So yes, explain your char or string type by proper declaration. ---------------------------------------------------------------------- MarkMLl · 2022-10-23 19:44 One might laugh but... I've used a tool in the past which made no assumption about character set, i.e. collation order or what characters could appear in an identifier, but /did/ assume that digits were sequential and ordered 0...9. And  damme, but if you look hard enough you can find character sets where even that doesn't apply. MarkMLl ---------------------------------------------------------------------- Fred vS · 2022-10-23 20:01 @Thaddy and @Mark : Thanks for the infos and happy to discover it. It does not work with: 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 for achar := 'Ά' to 'Ω' dobut personnaly I dont need it (at the moment). ---------------------------------------------------------------------- MarkMLl · 2022-10-23 20:16 Yeah, well they're outside the set of characters that can be legitimately used in Pascal identifiers, so all bets are off. I've given a bit of thought to "simple" rules of thumb determining what can be in an identifier, what can be used as an operator and so on... but at the same time I think that the Unicode Consortium has put a serious amount of work into it some of which might actually be useful. MarkMLl ---------------------------------------------------------------------- Kays · 2022-10-23 20:19 Quote from: Fred vS on October 23, 2022, 08:49:51 pm[…] But it is safe to do that ?To quote from the ISO standard 7185 (“Standard Pascal”):Quote6.4.2.2 Required simple-types The following types shall existinteger-type. […]real-type. […]Boolean- type. […]char-type. […] The following relations shall hold.The subset of character values representing the digits 0 to 9 shall be numerically ordered and contiguous.The subset of character values representing the upper case letters A to Z, if available, shall be alphabetically ordered but not necessarily contiguous.The subset of character values representing the lower case letters a to z, if available, shall be alphabetically ordered but not necessarily contiguous.That’s all fine, but the compiler still needs to claim ISO- compliance. Bottom line, your algorithm is “safe”, i. e. produces the expected result, as long as ord('A') + 25 = ord('Z'). ---------------------------------------------------------------------- MarkMLl · 2022-10-23 20:36 Note that the ISO standard doesn't declare that there are 26 characters in the range A through Z. MarkMLl ---------------------------------------------------------------------- Bart · 2022-10-23 20:40 If you really want to be safe (in the sense that there are guaranteed to be no other characters in between, regardless of character set) you can do: 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 const  Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';begin  for aChar in Alphabet do writeln(AChar);end. Yes, I know it's silly  Bart ---------------------------------------------------------------------- Fred vS · 2022-10-23 20:53 Thanks all for the light. By the way, the goal is to get all the devices on a Windows system with something like this:  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    var    achar : char    ...     for achar := 'A' to 'Z' do        begin       if directoryexists(achar + ':\') then writeln(achar + ':\ exists'');     Maybe (surely) there are other ways but this code works as expected. ---------------------------------------------------------------------- Kays · 2022-10-23 20:59 Quote from: MarkMLl on October 23, 2022, 10:36:39 pmNote that the ISO standard doesn't declare that there are 26 characters in the range A through Z.Well, if your comment is meant to say it could be less than 26 characters:Quote4 Definitional conventions […] The characters required to form Pascal programs shall be those implicitly required to form the tokens and separators defined in 6.1. […] 6.1.1 General […] The representation of any letter (upper case or lower case, differences in font, etc.) occurring anywhere outside of a character- string (see 6.1.7) shall be insignificant in that occurrence to the meaning of the program.letter = ‘a’ | ‘b’ | ‘c’ | ‘d’ | […] ‘w’ | ‘x’ | ‘y’ | ‘z’ .Because you can write, compose, say, identifiers as a sequence of letters A – Z, you can specify these letters in a character-string, too. Furthermore, the ISO standards 7185 and 10206 incorporate clauses from ASCII (ISO standard 646:1983), but I’m not sure what exactly. Quote from: Fred vS on October 23, 2022, 10:53:38 pm[…] By the way, the goal is to get all the devices on a Windows system with something like this: […]Maybe it won’t catch unformatted devices, I don’t know. ---------------------------------------------------------------------- Fred vS · 2022-10-23 21:09 Quote from: Kays on October 23, 2022, 10:59:28 pmQuote from: Fred vS on October 23, 2022, 10:53:38 pm[…] By the way, the goal is to get all the devices on a Windows system with something like this: […]Maybe it won’t catch unformatted devices, I don’t know. I hope so and also no mounted devices. So all seems ok, I can go to sleep (after commit all that, of course). Many thanks to all and have a good night and day (or day and night). Fre;D ---------------------------------------------------------------------- Fred vS · 2022-10-23 21:21 Allez, for the game, this one works too  : 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 inc_char;varachar : char = 'A';begin  while achar <= 'Z' do      begin      writeln(achar);      inc(achar);     end;end; ---------------------------------------------------------------------- Bart · 2022-10-23 21:50 Quote from: Fred vS on October 23, 2022, 10:53:38 pmBy the way, the goal is to get all the devices on a Windows system with something like this: I haved a DriveComboBox for that... You can specify what type of drive when populating (e.g. removables only). Windows only of course. Bart ---------------------------------------------------------------------- Jorg3000 · 2022-10-24 06:55 Hi! And if you need information about the type of a drive, see ... 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 aType:=Windows.GetDriveType(PChar(aRootPath)); DRIVE_REMOVABLE=2; DRIVE_FIXED=3; DRIVE_REMOTE=4; DRIVE_CDROM=5; DRIVE_RAMDISK=6; https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf- fileapi-getdrivetypea Jörg ---------------------------------------------------------------------- MarkMLl · 2022-10-24 07:03 Quote from: Kays on October 23, 2022, 10:59:28 pm4 Definitional conventions […] The characters required to form Pascal programs shall be those implicitly required to form the tokens and separators defined in 6.1. But that is distinct from your earlier Quote6.4.2.2 Required simple-types This was the point in the discussion a few years ago of a mainframe port: FPC could quite happily have EBCDIC-based string types (i.e. section 6), but changing the compiler itself to use anything other than an ASCII representation for the program (i.e. section 4) would have been decidedly non-trivial. So a cross-compiler would have been viable, at least for newer variants of the IBM mainframe architecture, but a native compiler much less so. MarkMLl ---------------------------------------------------------------------- ASerge · 2022-10-24 16:43 Quote from: Fred vS on October 23, 2022, 10:53:38 pmBy the way, the goal is to get all the devices on a Windows system with something like this: 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 {$MODE OBJFPC}{$APPTYPE CONSOLE}{$LONGSTRINGS ON} uses SysUtils, Windows; procedure PrintDrives;var  BufSize: DWORD;  P, Buffer: PUnicodeChar;  S: UnicodeString;begin  BufSize := GetLogicalDriveStringsW(0, nil);  if BufSize = 0 then    RaiseLastOSError;  GetMem(Buffer, BufSize * SizeOf(UnicodeChar));  try    if GetLogicalDriveStringsW(BufSize, Buffer) = 0 then      RaiseLastOSError;    P := Buffer;    while P[0] <> #0 do    begin    S := P;      Inc(P, Length(S) + 1);      Writeln(S);    end;  finally    FreeMem(Buffer);  end;end; begin  PrintDrives;  Readln;end. ---------------------------------------------------------------------- Fred vS · 2022-10-24 17:52 @Jorge3000 and @ASerge and @Bart: many thanks for that execellent options. But I forgot to note that I prefer a cross-os code and not use window unit . So I will stay with one of the options using a loop with if directoryexists((achar + ':\') in it. Fre;D ---------------------------------------------------------------------- wildfire · 2022-10-24 18:12 Quote from: Fred vS on October 24, 2022, 07:52:37 pm@Jorge3000 and @ASerge and @Bart: many thanks for that execellent options. But I forgot to note that I prefer a cross-os code and not use window unit . So I will stay with one of the options using a loop with if directoryexists((achar + ':\') in it. Fre;D Which in itself is not cross OS. ---------------------------------------------------------------------- MarkMLl · 2022-10-24 18:37 Quote from: wildfire on October 24, 2022, 08:12:36 pmWhich in itself is not cross OS. I have to agree, since I'm sure that Fred is interested in more than Windows and DOS. But allowing that the other OSes tend to be unix- based, it's difficult to decide on an appropriate alternative unless we try to do something like enumerating / plus any other filesystems that some system component can access without actually mounting it. MarkMLl ---------------------------------------------------------------------- Fred vS · 2022-10-24 18:45 Quote from: wildfire on October 24, 2022, 08:12:36 pmQuote from: Fred vS on October 24, 2022, 07:52:37 pm@Jorge3000 and @ASerge and @Bart: many thanks for that execellent options. But I forgot to note that I prefer a cross-os code and not use window unit . So I will stay with one of the options using a loop with if directoryexists((achar + ':\') in it. Fre;D Which in itself is not cross OS. It depend what you call cross OS, the previous code of course will have no result on Unix. Here part of the code to populate a grid, like a filedialog.  (of course using {$ifdef windows} for the afphabet drivers and {$ifdef unix} for "/" in path will make code lighter but will not generate crash without it.) 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 // this will be for Windows only{$ifdef windows}  // optional  for achar := 'A' to 'Z' do    begin     if directoryexists(achar + ':\') then       begin        Inc(x);        fo.places.rowcount := x+1;         fo.places[1][x] := string(achar + ':\');       end;   end;       if directoryexists('C:\users') then  // only Windows    begin      Inc(x);      fo.places.rowcount := x+1;      fo.places[1][x] := string('C:\users');    end;{$endif}    {$ifdef unix} // optional    if directoryexists('/') then // only Unix    begin      Inc(x);      fo.places.rowcount := x+1;      fo.places[1][x] := string('/');    end;    if directoryexists('/usr') then // only unix    begin      Inc(x);      fo.places.rowcount := x+1;      fo.places[1][x] := string('/usr');    end;    {$endif}     if directoryexists(tosysfilepath(sys_getuserhomedir)) then // Windows and Unix    begin      Inc(x);      fo.places.rowcount := x+1;      fo.places[1][x] := string(tosysfilepath(sys_getuserhomedir));    end;    if directoryexists(tosysfilepath(sys_getuserhomedir + directoryseparator + 'Desktop')) then // Windows and Unix    begin    Inc(x);      fo.places.rowcount := x+1;      fo.places[1][x] := string(tosysfilepath(sys_getuserhomedir + directoryseparator + 'Desktop'));    end;.... ---------------------------------------------------------------------- PascalDragon · 2022-10-25 05:47 Quote from: wildfire on October 24, 2022, 08:12:36 pmQuote from: Fred vS on October 24, 2022, 07:52:37 pm@Jorge3000 and @ASerge and @Bart: many thanks for that execellent options. But I forgot to note that I prefer a cross-os code and not use window unit . So I will stay with one of the options using a loop with if directoryexists((achar + ':\') in it. Fre;D Which in itself is not cross OS. If you need to work with drive letters you already are not cross platform. And sometimes you need to provide a platform specific view (e.g. displaying the full root on *nix systems, but displaying the drive letters on Windows for the user to find themselves at home).