-
Content Count
120 -
Joined
-
Last visited
Everything posted by luebbe
-
Hi everybody, The task at hand is to write column aligned text to an output file. The good old reliable format function can handle this fine unless CJK characters are involved. Generally these occupy two latin character columns, but I cannot blindly assume that a string which has to be formatted only contains CJK characters and multiply by two. Example: en : "Coding:" - seven characters occupy seven columns zh_CN: "编码:" - three characters occupy five columns I have found different solutions for different programming languages on SO, GitHub and other places, for example a wcwidth function in C, but nothing in Pascal (yet). Maybe I haven't uttered the proper incantations. System.Character.TCharHelper doesn't have a property like UnicodeWidth (Full/Half). Does the RTL offer any helper for this problem or do I have to roll my own? Hints are greatly appreciated.
-
How to calculate Unicode text width?
luebbe replied to luebbe's topic in RTL and Delphi Object Pascal
First of all my apologies for not replying sooner. That will teach me (not) to ask a question on a Friday before going on vacation... We have no control over the font that is used to display the text file. It may be any standard console font or a font selected in the editor of the user's choice. So probably the best thing we can come up with is to count how many full width/half width CJK characters are in the string to be written and pad this with a matching number of half width spaces. I tried using tabs, but this only works if the "jiggle" is less than a tab's width, which cannot be guaranteed. I'll check if I can come up with something based on the table I linked above. But since it's only a cosmetic problem, it's not worth that much effort. -
How to calculate Unicode text width?
luebbe replied to luebbe's topic in RTL and Delphi Object Pascal
I was thinking along the lines of TCanvas.TextWidth as well, but since I'm "just" dealing with text file output I thought this may be too much. Delphi characters.inc seems to contain all unicode characters and the TCharHelper derives a lot of info from it. There is also an official unicode property "east asian width" (https://www.unicode.org/reports/tr11/tr11-8.html) and the corresponding lookup table (https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt), but this doesn't seem to be used in TCharHelper. I'd probably import this table and do something similar to TCharHelper. -
Strange bug with string literals in RAD Studio 12
luebbe posted a topic in RTL and Delphi Object Pascal
Hi Folks, I've come across a strange bug with string literals in Delphi. I am in the process of moving from Delphi 11.3 to 12.1 and suddenly one of our tests fails. I could narrow it down to a combination of the less equal or greater equal unicode characters in combination with a tab in the string. Here's the definition: const cExpected: array [0 .. 4] of string = ( '1 Line with <= and no tab', '2 Line with ≤ and no tab', #9'3 Line with ≤ and a', #9'4 Line with ≥ and a tab', #9'5 Line with >= and a tab'); On the left side of the screenshot is the result of the misinterpretation. You see that somehow the first characters of the last line that didn't contain a tab *and* a greater equal/less equal character overwrite the first characters of the lines that contain both. I've never seen this before. Does anyone have an idea what is going on here? Delphi 11 handled it correctly. Originally it was one const separated by sLineBreak instead of a const array of string. This combination also damages TestCase() Attributes in DUnitX. They also get misinterpreted. -
Strange bug with string literals in RAD Studio 12
luebbe replied to luebbe's topic in RTL and Delphi Object Pascal
Still waiting (and hoping) -
Strange bug with string literals in RAD Studio 12
luebbe replied to luebbe's topic in RTL and Delphi Object Pascal
Only about 500 for me. After I knew what was going on, I replaced them all. A systematic search & destroy did the job for me. -
Strange bug with string literals in RAD Studio 12
luebbe replied to luebbe's topic in RTL and Delphi Object Pascal
In fact that's what I did. I concatenated the tabs with "+ #9 +" since they separate the string anyway. Thanks for the hint. -
Definitely need a community vote on this. 🙂
-
Hi Folks, I've come across a problem with VCL styled applications. Some controls (not all) continuously fire WM_SETCURSOR messages, when the mouse cursor is stationary over a scrollbar and VCL styles are active. When the standard Windows style is used, everything works as expected. There are a few WM_SETCURSOR messages and they stop coming, when the mouse stops moving. This may not sound like a big deal, but on my PC the CPU load goes up from 1% to 15%..20% (one core almost at 100%) when this happens. We have a timing critical application, where the timing goes haywire, when the mouse is over a scrollbar of a TListView or a TScrollBox. At least ListView and ScrollBox exhibit this behaviour. EasyListView and VirtualStringTree don't. I haven't found the source of the problem yet, so help is greatly appreciated. Attached you will find an example with a TListView that exhibits the behaviour. Included is an .exe, compiled with Delphi 10.4.2. So if this doesn't happen with a newer compiler, we have a big incentive to upgrade 🙂 StyledWMSetCursor.zip Cheers & thanks Lübbe
-
Exactly, so I will move on. At least this topic is conserved for posterity, so maybe it'll help someone else as well.
-
We know the following: An exe produced by someone else with 10.2 is ok An exe produced by me with 10.4.2 is not ok An exe produced by someone else with 11.3 is ok An exe produced by me with 11.3 is ok (tested it in the mean time) Open question: An exe produced by someone else with 10.4.2 is ???
-
So it looks like a regression in 10.4 (or 10.3) to me. Thanks a lot again! In German we got the nice word "Verschlimmbesserung" for this. A mashup of Verbesserung = improvement and Verschlimmerung = aggravation. 🙂
-
Thanks for testing. Interesting. I wonder if this bug only happens with 10.4? I guess that my 10.4.2 exe shows the described behaviour on your PC?
-
I deleted the Parnassus registry keys from "SOFTWARE\Embarcadero\BDS\21.0\Experts" and now the 10.4.2 IDE starts again. Getit still thinks the parnassus plugins are installed, but uninstalled them via getit and it seems ok now. I then let the 11.2 installer delete all 11.x registry keys and it looks like it will now proceed successfully. So it looks like I could solve the problem.
-
Not a good experience for me so far. I had installed 11.1 alongside 10.4.2 without any problems. I always install from ISO with local admin privileges. Getit packages are installed later, normally without admin privileges. I let the 11.2 installer uninstall the previous version keeping the registry keys. It removes getit packages, finishes installing the core and then crashes with the following error: Running the 11.2 installer again yields the same result. Worst of all, when I now start Delphi 10.4.2 it also crashes with almost the same exception: So the 11.2 installer managed to destroy two installations in one go. But the parnassus dlls seem to be in place: How can I recover from this situation? Probably there are some registry keys which I should delete and then reinstall again, but which registry keys?
-
Hi Folks, in one ouf our projects I'm using @Daniele Teti 's loggerpro library (https://github.com/danieleteti/loggerpro) instead of a homebrew logging solution. A few weeks after switching to loggerpro, a first Eurekalog bug report came in with the message: "EMonitorLockException in ThreadSafeQueueU.pas: {ThreadSafeQueueU}TThreadSafeQueue<LoggerPro.TLogItem>.Enqueue, Zeile 157 (0)". This exception is clearly raised inside loggerpro. I have already asked at GitHub (https://github.com/danieleteti/loggerpro/issues/53), but have received no reply yet. Every month or so, another of these bug reports comes in. The problem is: - I cannot reproduce/trigger it on my development PC, even though I think I can locate exactly, where and under which circumstances it happens - I don't see any obvious error in the loggerpro code - I don't see any obvious error in my code which is why I'm asking for help here. Maybe I have missed something obvious in my code... We have the following scenario: The main thread starts a background task (IFuture), which builds up an index of files for later use. Both, main and background task log their status with LoggerPro. The index updater: procedure TUpdater.Update; var LXxxFiles, LYyyFiles: TFileList; begin if FStatus = stNotLoaded then begin Log.Debug('Renewing Index', 'INDEX'); LXxxFiles := TFileList.Create; LYyyFiles := TFileList.Create; try FStatus := stLoading; ... Prepare XXX and YYY lists ... Log.Info('Check %d Xxx Files', [LYyyFiles.Count], 'INDEX'); Log.Info('Check %d Yyy Files', [LXxxFiles.Count], 'INDEX'); // Check existing files and index their content if FStatus <> stCanceled then if Process(LXxxFiles) and Process(LYyyFiles) then FStatus := stLoaded; if FAutoSave then FIndex.Save; FIndex.LogStats; Log.Debug('Status - ' + TRttiEnumerationType.GetName<TLoadStatus>(FStatus), 'INDEX'); finally LXxxFiles.Free; LYyyFiles.Free; end; end; end; If the main task needs the index, it calls the following routine: function TUpdater.WaitForCompletion: boolean; begin Log.Enter('Updater.WaitForCompletion', 'INDEX'); // Waits until the IFuture task is finished and returns its status // The calling thread is blocked while waiting Result := (FTask.Value = stLoaded); Log.Exit('Updater.WaitForCompletion', 'INDEX'); end; Log.Enter and Log.Exit are just two wrapper functions around Log.Debug that I have added to LoggerPro. The Exception occurs on the `Log.Exit` call Here are the relevant lines of the Eurekalog report: EMonitorLockException Object lock not owned. |005B7380|Application.exe|ThreadSafeQueueU.pas |{ThreadSafeQueueU}TThreadSafeQueue<LoggerPro |TLogItem>.Enqueue |157[0] | |005B61B5|Application.exe|LoggerPro.pas |TLogWriter |Log |557[5] | |0110346B|Application.exe|System.Generics.Defaults.pas | | |39[0] | |010FF5A2|Application.exe|Update.Index.pas |TUpdater |WaitForCompletion |845[4] | |010FF560|Application.exe|Update.Index.pas |TUpdater |WaitForCompletion |841[0] | Normally the update task takes some time, so the typical log output is: 2022-04-21 15:22:13:937 [TID 16780][INFO ] [INDEX ] Updater.Update in: C:\Users\Public\Documents\##### 2022-04-21 15:22:13:937 [TID 16780][DEBUG ] [INDEX ] --> Updater.StopUpdate 2022-04-21 15:22:13:937 [TID 16780][DEBUG ] [INDEX ] <-- Updater.StopUpdate 2022-04-21 15:22:13:987 [TID 16780][INFO ] [INDEX ] Contains 240 Files 2022-04-21 15:22:13:987 [TID 16780][INFO ] [INDEX ] Contains 4931 Entries 2022-04-21 15:22:13:987 [TID 3280][DEBUG ] [INDEX ] Renewing Index 2022-04-21 15:22:13:987 [TID 16780][DEBUG ] [INDEX ] --> Updater.WaitForCompletion 2022-04-21 15:22:14:080 [TID 3280][INFO ] [INDEX ] Remove 0 Files 2022-04-21 15:22:14:080 [TID 3280][INFO ] [INDEX ] Check 238 xxx Files 2022-04-21 15:22:14:080 [TID 3280][INFO ] [INDEX ] Check 2 yyy Files 2022-04-21 15:22:14:242 [TID 3280][INFO ] [INDEX ] Contains 240 Files 2022-04-21 15:22:14:242 [TID 3280][INFO ] [INDEX ] Contains 4931 Entries 2022-04-21 15:22:14:242 [TID 3280][DEBUG ] [INDEX ] Updater.Status - stLoaded 2022-04-21 15:22:14:242 [TID 16780][DEBUG ] [INDEX ] <-- Updater.WaitForCompletion ... Normal work continues here In some cases (no search paths defined or search paths empty), there's "nothing" to do, which results in the following log output: 2022-04-21 14:18:14:972 [TID 22208][INFO ] [INDEX ] Updater.Update in: C:\Users\Public\Documents\##### 2022-04-21 14:18:14:972 [TID 22208][DEBUG ] [INDEX ] --> Updater.StopUpdate 2022-04-21 14:18:14:972 [TID 22208][DEBUG ] [INDEX ] <-- Updater.StopUpdate 2022-04-21 14:18:14:973 [TID 22208][INFO ] [INDEX ] Contains 0 Files 2022-04-21 14:18:14:973 [TID 22208][INFO ] [INDEX ] Contains 0 Entries 2022-04-21 14:18:14:974 [TID 14984][DEBUG ] [INDEX ] Renewing Index 2022-04-21 14:18:14:974 [TID 14984][INFO ] [INDEX ] Remove 0 Files 2022-04-21 14:18:14:974 [TID 14984][INFO ] [INDEX ] Check 0 xxx Files 2022-04-21 14:18:14:974 [TID 14984][INFO ] [INDEX ] Check 0 yyy Files 2022-04-21 14:18:14:977 [TID 14984][INFO ] [INDEX ] Contains 0 Files 2022-04-21 14:18:14:977 [TID 14984][INFO ] [INDEX ] Contains 0 Entries 2022-04-21 14:18:14:977 [TID 14984][DEBUG ] [INDEX ] Updater.Status - stLoaded 2022-04-21 14:18:14:979 [TID 22208][DEBUG ] [INDEX ] --> Updater.WaitForCompletion 2022-04-21 14:18:14:979 [TID 22208][DEBUG ] [INDEX ] <-- Updater.WaitForCompletion ... Normal work continues here Note that in this case the updater was finished (stLoaded) before WaitForCompletion was called. The Log.Enter "--> Updater.WaitforCompletion" line may occur anywhere between the lines of the background thread (TID 14984 in this case). This is the LoggerPro output matching the bug report. The `EMonitorLockException` occured on the `Log.Exit` call in `TUpdater.WaitForCompletion` and this line is missing from the log: 2022-04-21 14:42:03:003 [TID 20620][INFO ] [INDEX ] Updater.Update in: C:\Users\Public\Documents\##### 2022-04-21 14:42:03:003 [TID 20620][DEBUG ] [INDEX ] --> Updater.StopUpdate 2022-04-21 14:42:03:003 [TID 20620][DEBUG ] [INDEX ] <-- Updater.StopUpdate 2022-04-21 14:42:03:004 [TID 20620][INFO ] [INDEX ] Contains 0 Files 2022-04-21 14:42:03:004 [TID 20620][INFO ] [INDEX ] Contains 0 Entries 2022-04-21 14:42:03:004 [TID 3312][DEBUG ] [INDEX ] Renewing Index 2022-04-21 14:42:03:004 [TID 3312][INFO ] [INDEX ] Remove 0 Files 2022-04-21 14:42:03:004 [TID 3312][INFO ] [INDEX ] Check 0 xxx Files 2022-04-21 14:42:03:004 [TID 3312][INFO ] [INDEX ] Check 0 yyy Files 2022-04-21 14:42:03:008 [TID 20620][DEBUG ] [INDEX ] --> Updater.WaitForCompletion 2022-04-21 14:42:03:008 [TID 3312][INFO ] [INDEX ] Contains 0 Files 2022-04-21 14:42:03:008 [TID 3312][INFO ] [INDEX ] Contains 0 Entries 2022-04-21 14:42:03:008 [TID 3312][DEBUG ] [INDEX ] Updater.Status - stLoaded ... Normal work continues here Note that the updater was still working (on nothing ;-)) when WaitForCompletion was called. It looks like Log.Exit('WaitForCompletion') and Log.Debug('Updater.Status - stLoaded') happen in the same millisecond, so I assume that thread 3312 still held the lock, when exception thread 20620 called `Log.Exit`. But I see this all the time (finish/exit happens in the sme millisecond) when I run the code on my PC and never get an EMonitorLock exception. Is there something we are doing wrong or have we come across a race condition in LoggerPro or the Delphi locking implementation?
-
Got the point, thanks 🙂 I was missing the obvious part that the call stack doesn't make sense. Been digging through the RTL to find out when a EMonitorlock Exception would be raised.
-
You're right, the call stack doesn't make sense. I'm using my own fork of loggerpro (https://github.com/luebbe/loggerpro.git) and made two PRs with additional functionality in the original, but I didn't modify any of the queuing code. We're using a very old version (6.x) of Eurekalog. Perhaps this is reason for the wrong stack trace, but still I wouldn't expect any exception to happen here.
-
FTask is an IFuture, so yes, it should wait. I just mentioned this fact but didn't show any code. Here it is: procedure TUpdater.UpdateIndex(const ASearchPathList: string; AForceUpdate: boolean); begin ... cancel running tasks etc ... FTask := TTask.Future<TLoadStatus>( function: TLoadStatus begin Update; Result := FStatus; end); end;
-
Frequent and/or annoying typos you make while coding
luebbe replied to Tommi Prami's topic in General Help
Apart from the obvious "length", "height" and "weight", I tend to mistype phonetically similar consonants. E.g. "t/d", "b/v" like "wader" instead of "water". -
@FPiette do you know https://github.com/neslib/Neslib.Xml? I switched some of my xml parsing from Delphi's native parser to Neslib.Xml and it resulted in around 35x-40x faster parsing (17-20 seconds versus <= 0.5 seconds).
-
Hi Folks, I'm stuck with the problem that I want to prevent a grid to act on the mouse wheel events. The UI layout is the following: On a TFrame (created at runtime) I have a TCategoryPanelGroup. As the application is receiving data in different formats, for each data package a new TCategoryPanel is created at runtime and placed on the TCategoryPanelGroup. Each TCategoryPanel contains two grids who are adjusted to fit the data. The heights of the grids and the TCategoryPanel are adjusted so that in >90% of the cases the grids won't have a scrollbar. Now when I use the mouse wheel over a grid, the grid catches the wheel and happily acts on it, which is not what I want. If the grid has a scrollbar (rare case), the user shall use the scrollbar to scroll the grid. My goal is to always scroll the TCategroyPanelGroup when the mouse wheel is used over one of the grids or a TCategorypanel so the user can quickly flip through the categories. How can I make the grids and the TCategoryPanel "ignore" or "pass up" the mouse wheel events so that the TCategoryPanelGroup receives them and can act on them? Would a different structure of UI elements be a better approach? I'm actually quite happy with the category panels, because the data inside can be clearly identified via their header and they can be collapsed when I don't want to see all different data sets at the same time. I've attached a stripped example of the UI structure that just catches the mouse wheel events for the controls and outputs them in a memo. MouseScroll.zip
-
Sorry no, it doesn't help. The stringgrid still catches all mouse wheel events. And there is a stack overflow in TControl.Defaulthandler when I'm not over a grid.
-
Looks nice. I'm missing information on where to find unigui. A search on GitHub resulted in a lot of hits.
- 5 replies
-
- unigui
- google charts
-
(and 1 more)
Tagged with:
-
Probably a rounding problem? @pyscripter has created a dpi aware base form which IIRC uses muldiv to adjust to dpi changes. Enjoy your vacation!