Jump to content

pyscripter

Members
  • Content Count

    779
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by pyscripter

  1. pyscripter

    UCS4StringToWideString broken?

    You don't have to use USC4 for that and using USC4 would not solve this problem. There are mainly two issues: 1) Surrogates pairs (two widechars correspond to one glyph) UCS4 would help with this one. UTF-16 Encoding: 0xD83D 0xDCBC “💼” 2) Combining characters (more than one Widechars shown as one glyph). But UCS4 would not help with this one. Åström ḱṷṓn Precomposed vrs Decomposed ḱṷṓn (U+1E31 U+1E77 U+1E53 U+006E) ḱṷṓn (U+006B U+0301 U+0075 U+032D U+006F U+0304 U+0301 U+006E) Windows provides CharNext/Prev that deals with both issues, but not perfectly. You have to use Uniscribe or DirectWrite for greater accuracy. In SynEdit there is this function: function SynCharNext(P: PWideChar; out Element : String) : WideChar; overload; Var Start : PWideChar; begin Start := P; Result := Windows.CharNext(P); SetString(Element, Start, Result - Start); end; It is very easy to write an enumerator that works with CharNext.
  2. pyscripter

    UCS4StringToWideString broken?

    Why should any Delphi program use UCS4? The main use case is for inter-operability. You would need to pass the result to some external function. Having to manually add the null-terminator, would be inconvenient.
  3. pyscripter

    UCS4StringToWideString broken?

    I suppose this is understandable. The Windows world is on UTF-16 and the rest on UTF-8. UCS4 (UTF-32) is very rarely used. With the benefit of hindsight, UTF-8 would probably have been a better choice for Windows. Now Microsoft is trying to bring UTF-8 back into Windows via the A routines and by offering to make UTF-8 the default character encoding.
  4. pyscripter

    UCS4StringToWideString broken?

    It needs to be when you interoperate with libraries in which the default character encoding is USC4 (eg. python API on Linux https://www.python.org/dev/peps/pep-0513/).
  5. pyscripter

    UCS4StringToWideString broken?

    This was all covered in
  6. pyscripter

    Project Magician gotcha

    Project Magician is wonderful and a must for all Delphi programmers. Thank you @Uwe Raabe. However I recently run into the following problem. As I was debugging, whenever I tried to step into Vcl.Graphics the file would open and get marked as modified. Moreover stepping into the code would not work. Also when I opened Vcl.Graphics and some other files in the IDE, it would automatically marked them as modified. I was puzzled. I thought this was a new bug in the 10..4.1 Delphi IDE. But it turns out this was due to a Project Magician, otherwise very useful option to "Clean Line Feeds" under global settings. Vcl.Graphics has mixed line breaks in Delphi 10.4.1, so whenever it is opened in the IDE it would be automatically marked as modified since the mixed line breaks were detected and marked for fixing. And then debugging is hampered + you get all these annoying messages about the IDE being unable to create a backup. One suggestion to @Uwe Raabe is that Delphi library files are excluded from line-feed cleaning.
  7. pyscripter

    Project Magician gotcha

    @Uwe Raabe One issue I had recently was with the IDE crashing badly when going View Form as Text and then back. I disabled Project Magician and the issue went away. Using Delphi 10.4.1 and the latest version of Project Magician. Delphi Magician options: The crash also occurred with a fresh VCL application and an empty Form.
  8. pyscripter

    Per monitor DPI awareness - how to prevent flickering?

    @dummzeuchAll these limitations of LockWindowUpdate are well known and noted. Yes you should avoid using LockWindowUpdate if you can and prefer WM_SETREDRAW. Fully agree. WM_SETREDRAW was the first thing I tried and did not work. As Raymond Chen says in the above articles One can well argue therefore, that dragging a Window from one monitor to another is a valid case for using LockWindowUpdate. If it is OK to lock the whole desktop when you do OLE drag&drop it should be OK to lock a single window while dragging it between monitors, just for the time it rescales.
  9. pyscripter

    Per monitor DPI awareness - how to prevent flickering?

    InputBox/Query are still broken.
  10. pyscripter

    Per monitor DPI awareness - how to prevent flickering?

    There are a number of ways to reduce scaling time: If you are using VirtualLists with many Icons try RtlVclFixes.pas Use ParentFont := True in child controls to avoid scaling fonts For custom components try to fine-tune/override DefaultScalingFlags
  11. pyscripter

    Per monitor DPI awareness - how to prevent flickering?

    !? Why not 96 to avoid scaling?
  12. pyscripter

    Per monitor DPI awareness - how to prevent flickering?

    procedure TForm1.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer); begin LockWindowUpdate(0); end; procedure TForm1.FormBeforeMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer); begin LockWindowUpdate(Handle); end;
  13. pyscripter

    TTitlebarpanel and VCL styles

    The TitleBarPanel is used by the IDE. I guess it was developed to resolve the problem with the disappearing/flickering controls of the IDE title bar (search, layout controls, etc.), It can accommodate Toolbars (including the ActionMainMenuBar) and other controls, so you can place the main menu on the titleBar (see the sample app). And to answer the original question, you would need to manually adjust the Titlebar colors every time there is a style change. This is probably how the IDE styles its TitleBarPanel. @Vincent Parrett I also do not like the overcrowding of TForm and other controls with rarely used properties. (e.g. CustomHint that can be linked to a Balloon Hint all but abandoned - not DPI aware).
  14. pyscripter

    Direct2D 1.1 canvas much slower that Direct2D 1.0

    Regarding the RenderTarget I showed the code above. For details have a look at https://github.com/EtheaDev/SVGIconImageList/blob/master/Source/D2DSVGFactory.pas) . What I am suggesting is that you build your app as if it was a GDI app. And just use D2D in your painting code (override Paint, OnPaint event etc) utilising a single DCRenderTarget.
  15. pyscripter

    Direct2D 1.1 canvas much slower that Direct2D 1.0

    You can get a Device context from the Render Target. I am using ID2D1DeviceContext5 which was introduced with the Creators Update. if Supports(RenderTarget, ID2D1DeviceContext5, DeviceContext5) And as I said you do not need (multiple) D2D Windows. Just use standard forms and one DCRenderTarget to use in the OnPaint event of the form or by overriding the Paint method of Controls. And in terms of speed D2DSVG renders 300 svgs to bitmaps in less than 15ms.
  16. The most common way do text-processing in Delphi is to load a file into a TStringList and then process the text line-by-line. Often you need to save the contents of the StringList back to the file. The TStringList is one of the most widely used RTL classes. However there are a number of limitations discussed below: a) No easy way to preserve line breaks on Load/Save TStringList does not make any effort to recognize the type of line breaks (LF, CR or CRLF) in the files it opens, let alone save that for use on saving. b) Information loss without any warning or any option for dealing with that. Internally TStringList uses unicode strings, but when you save its contents to a file using the default encoding (ANSI), this may result in information loss, without getting any warning or having any means for dealing with that. TEncoding.GetBytes also suffers from that. c) No easy way to determine whether a file you loaded into a TStringList contained a BOM When you load a file (LoadFromFile method), the encoding of the file is stored but not the information about whether the file contained a BOM or not. The WriteBOM property is only used when you save a file. d) Last but not least, no easy way of dealing with utf8 encoded files without a BOM The default text file format in Linux systems, in Visual Studio Code and other editors, as well as in languages such as python 3 is utf8 without BOM. Reading such files with TStringList is problematic and can result in errors, because it thinks such files are ANSI encoded. You could change the DefaultEncoding to utf8, but then you get errors when you read ansi files. No effort is made to detect whether a file without a BOM contains utf8 sequences. Overall, it is desirable that, when you load a file using LoadFromFile and then you save it using SavetoFile, the saved copy is identical to the original. I am attaching a general purpose TStringList descendent that deals with all the above issues in case anyone has a use for that. XStringList.pas
  17. pyscripter

    Direct2D 1.1 canvas much slower that Direct2D 1.0

    I have used D2D to draw SVG images (see https://github.com/EtheaDev/SVGIconImageList/blob/master/Source/D2DSVGFactory.pas) and the performance is very good! I found that Vcl.Direct2D was not worth the trouble and that it was easier to work directly with the D2D interfaces. Also I preferred to use the DCRenderTarget as opposed to HWndRendertarget, since the former blends better with GDI and GDI+ applications. One issue I had was with hardware acceleration. if not Succeeded(D2DFactory.CreateDCRenderTarget( D2D1RenderTargetProperties( {$IFDEF GPUSupprt} D2D1_RENDER_TARGET_TYPE_DEFAULT, {$ELSE} D2D1_RENDER_TARGET_TYPE_SOFTWARE, // much faster in my desktop with a slow GPU {$ENDIF} D2D1PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED), 0, 0, D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE), RenderTarget)) In the code above D2D1_RENDER_TARGET_TYPE_SOFTWARE avoids hardware acceleration and it was massively faster in a Desktop with a slow GPU. You may want to try that.
  18. pyscripter

    What is wrong with TStringList

    Agree. In the old days (pre Unicode) I wrote the attached Strmtxt.pas (converts a stream to a text file). It would need to be updated to work with recent versions of Delphi. And it works great with buffered streams such as @David Heffernan's TReadOnlyCachedFileStream. With that you could do something like: var Stream := TReadOnlyCachedFileStream.Create('c:\temp\t'); AssignStream(Txt, Stream); while not EOF(Txt) do begin Readln(Txt,S); Writeln(MemoText, S); end; However when you build a text editor such as SynEdit, you typically load the whole file in memory. In any case, the focus of this topic was the limitations of TStringList with regards to dealing with encodings, BOM and Line breaks. It was not about what is the most efficient way to do text processing in Delphi. STRMTXT.PAS
  19. LIBSUFFIX AUTO has been a much requested feature for ages. The Delphi 10.4.1 announcement said: Sounded interesting so I decided to try that. I first searched the documentation and found the following: So I added {$LIBSUFFIX AUTO} to a package of mine say xyz.dpk and the bpl file generated was indeed xyz270.bpl. However I got an error message saying: This much for "full support" for this feature. Am I missing something??
  20. pyscripter

    Delphi 10.4.1 LIBSUFFIX AUTO

    Already reported by @Remy Lebeau!😀 https://quality.embarcadero.com/browse/RSP-30820?jql=
  21. pyscripter

    Delphi 10.4.1 LIBSUFFIX AUTO

    Thanks Darian. I did. The problem only happens when you have a dpk file without a project file. If the dpk file contains the new directive {$LIBSUFFIX AUTO} the IDE does not recognize that and thinks the actual suffix is "AUTO".
  22. pyscripter

    Use of Ansistring in Unicode world?

    I would like to add that if you change the default Windows page to 65001 and have pas files containing ASCII characters > 127 then your files will be messed up when you open them in Delphi. Also if you build your Delphi projects you will get warnings or even worse produce erroneous executables without warnings. Try to compile SynEdit for example. Having said that, this option is great for interacting with console applications and system processes and being able to at last handle unicode console input/output.
  23. pyscripter

    Use of Ansistring in Unicode world?

    Agree with all the above, except that UTF8String is an an AnsiString with a Code Page 65001 and is also Unicode compliant and incurs no conversion loss. It is the default string type in FPC. In Linux systems everything is UTF8. And nowadays 65001 it can be set as the default code page in Windows.
  24. pyscripter

    Delphi 10.4.1 LIBSUFFIX AUTO

    During building the package from inside the IDE,
  25. pyscripter

    Grep search empty window with 10.4.1

    Amazing! After installing a few packages in 10.4.1 (Synedit was one of them) Gexperts Grep Results now works! Nice because Grep Search and Unit Clause Manager are my favorite Gexperts.
×