Re: [fpc-pascal] Get highest element of a StringList
On 12/09/2022 07:52, Jean SUZINEAU via fpc-pascal wrote: As Bart suggested, you can use too the for/in loop: for s in sl do WriteLn( s); And that is IMHO by far the most elegant, and least error prone, representation. Cheers, Peter ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get highest element of a StringList
The problem with the for in loop is that I need the index. I'm sometimes searching through the stringlist looking for a match, and when I find a match, I want to read the value And then do a break, because there is no point is searching once I found what I am looking for: For I:= 0 to MyStringlist.high Do Begin If MyStringlist[I].Names = SearchName Then Begin MyValue := MyStringlist[I].ValueFromIndex; Break; End; End; I agree that the for - in loop is a great way if you are always processing the entire list and don't need the index for anything. James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get highest element of a StringList
On 12/09/2022 14:16, James Richters via fpc-pascal wrote: The problem with the for in loop is that I need the index. Hi James, You don't need a loop for that: index:=MyStringlist.IndexOfName; see: https://www.freepascal.org/docs-html/rtl/classes/tstrings.indexofname.html martin. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get highest element of a StringList
So I could just do this? Index:= MyStringlist.IndexOfName(SearchName); If Index >=0 then MyValue := MyStringlist[Index].ValueFromIndex; That sure is nice to know, Thank you! I guess for my dynamic arrays of records, I still need to search with a loop... or is there a cool thing I don't know about for that as well? James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get highest element of a StringList
On 12/09/2022 15:37, James Richters via fpc-pascal wrote: So I could just do this? Index:= MyStringlist.IndexOfName(SearchName); If Index >=0 then MyValue := MyStringlist[Index].ValueFromIndex; Hi James, I would probably do try with MyStringList do MyValue:=ValueFromIndex[IndexOfName(SearchName)]; except MyValue:=''; end; cheers, Martin. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Getting Shift key with PTCCRT
On 9/10/22 17:57, James Richters via fpc-pascal wrote: Thanks for the suggestion I think the syntax should be: type myKeyEvent = IPTCKeyEvent; Var myShiftStatus : boolean; myShiftStatus := myKeyEvent.Shift; but I get IPTCKeyEvent not found. I wonder if it's only designated as internal.. or if I need to use something other than PTCGraph and PTCCRT It's internal if you use ptccrt and ptcgraph, but it's available if you use ptc directly. These are two different APIs: ptc - low level, non-Borland compatible API ptcgraph, ptccrt, ptcmouse - these use ptc to provide a Borland BGI-compatible and CRT-unit compatible support (plus mouse, which was never supported by Borland, but is nice to have also ;-) ). Recently, I don't have much time to work on ptc (unfortunately), but you can look at the source yourself and write a patch by yourself to get what you need. The conversion of ptc key events to CRT-like key codes happens in ptccrt.pp, procedure GetKeyEvents (lines 113..534). It tries to convert ptc key events to what CRT in dos used to return. There are lots of compatibility factors involved, which results in some key data loss, but you can modify it at your will for your own purposes. Perhaps we can extend ptccrt to be able to return the whole ptc key event as well? It can be done, unfortunately, the Borland ReadKey/KeyPressed API wasn't designed to do that, so new functions appear to be necessary. James looking at the list of constants in ptcpas, i find PTCKEY_SHIFT... i also find, in Classes, the IPTCKeyEvent which has a GetShift function as well as a Shift property... seems like you should be able to the shift status with something like type myKeyEvent : IPTCKeyEvent; type myShiftStatus : boolean; myShiftStatus := myKeyEvent.Shift; ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Getting Shift key with PTCCRT
On 2022-09-12 21:41, Nikolay Nikolov via fpc-pascal wrote: On 9/10/22 17:57, James Richters via fpc-pascal wrote: Thanks for the suggestion I think the syntax should be: type myKeyEvent = IPTCKeyEvent; Var myShiftStatus : boolean; myShiftStatus := myKeyEvent.Shift; but I get IPTCKeyEvent not found. I wonder if it's only designated as internal.. or if I need to use something other than PTCGraph and PTCCRT It's internal if you use ptccrt and ptcgraph, but it's available if you use ptc directly. These are two different APIs: ptc - low level, non-Borland compatible API ptcgraph, ptccrt, ptcmouse - these use ptc to provide a Borland BGI-compatible and CRT-unit compatible support (plus mouse, which was never supported by Borland, but is nice to have also ;-) ). Recently, I don't have much time to work on ptc (unfortunately), but you can look at the source yourself and write a patch by yourself to get what you need. The conversion of ptc key events to CRT-like key codes happens in ptccrt.pp, procedure GetKeyEvents (lines 113..534). It tries to convert ptc key events to what CRT in dos used to return. There are lots of compatibility factors involved, which results in some key data loss, but you can modify it at your will for your own purposes. Perhaps we can extend ptccrt to be able to return the whole ptc key event as well? It can be done, unfortunately, the Borland ReadKey/KeyPressed API wasn't designed to do that, so new functions appear to be necessary. Old TP/BP programs were usually accessing the BIOS ShiftState "variable" (using direct BIOS memory access). TV unit Drivers provided this functionality using function GetShiftState (available in FreeVision as well, of course). If you're looking for adding something compatible to TP/BP functionality, ShiftState (e.g. as a property), or GetShiftState function might be good candidates for such an addition, IMHO. Tomas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal