Jump to content

pyscripter

Members
  • Content Count

    920
  • Joined

  • Last visited

  • Days Won

    56

Everything posted by pyscripter

  1. pyscripter

    SynEdit just got a major uplift

    A new feature has been added: Scintilla like indicators.
  2. In d2d1svg.h (Direct2D) there is the following declaration of the ID2D1SvgElement interface: /// <summary> /// Sets an attribute of this element using a POD type. Returns an error if the /// attribute name is not valid on this element. Returns an error if the attribute /// cannot be expressed as the specified type. /// </summary> STDMETHOD(SetAttributeValue)( _In_ PCWSTR name, D2D1_SVG_ATTRIBUTE_POD_TYPE type, _In_reads_bytes_(valueSizeInBytes) CONST void *value, UINT32 valueSizeInBytes ) PURE; D2D1_SVG_ATTRIBUTE_POD_TYPE = DWord; I am translating this as function SetAttributeValue(name: LPWSTR; _type: D2D1_SVG_ATTRIBUTE_POD_TYPE; value: Pointer; valueSizeInBytes: UINT32): HResult; overload; stdcall; But it crashes when it is used. The assembly prolog of SetAttributeValue is 564711F0 6690 nop 564711F2 55 push ebp 564711F3 8BEC mov ebp,esp 564711F5 83EC14 sub esp,$14 564711F8 8B4508 mov eax,[ebp+$08] 564711FB 33C9 xor ecx,ecx 564711FD 53 push ebx 564711FE 56 push esi 564711FF 57 push edi 56471200 8D5808 lea ebx,[eax+$08] 56471203 85DB test ebx,ebx 56471205 6A08 push $08 56471207 0F44C1 cmovz eax,ecx 5647120A 8945F8 mov [ebp-$08],eax 5647120D 5A pop edx Any idea what I am doing wrong? Thanks!
  3. I was trying to improve the performance of SynEdit in handling files with super long lines (e.g. 50K characters). In doing so I came across an unexpected optimization that had a spectacular impact on performance. See this innocent looking function probably written two decades ago (fCasedLine is a PChar): function TSynCustomHighlighter.GetToken: string; var Len: Integer; begin Len := Run - fTokenPos; SetLength(Result, Len); if Len > 0 then StrLCopy(@Result[1], fCasedLine + fTokenPos, Len); end; By measuring I found that this function (called zillions of times) was a bottleneck and replaced it with: function TSynCustomHighlighter.GetToken: string; var Len: Integer; begin Len := Run - fTokenPos; SetString(Result, fCasedLine + fTokenPos, Len); end; The impact was massive. Both SetString and StrLCopy in x64 are implemented in pascal (not assembly) using Move. So initially I was puzzled. However here is the reason. Look at StrLCopy: function StrLCopy(Dest: PWideChar; const Source: PWideChar; MaxLen: Cardinal): PWideChar; var Len: Cardinal; begin Result := Dest; Len := StrLen(Source); if Len > MaxLen then Len := MaxLen; Move(Source^, Dest^, Len * SizeOf(WideChar)); Dest[Len] := #0; end; Can you see the problem? It is the call to StrLen(Source)! In my case the Source was very very long strings, the length of which was unnecessarily calculated the hard way. The lesson here is that you need to identify the bottlenecks by measuring. You may be in for surprises, sometimes pleasant ones,
  4. pyscripter

    String optimization

    TStopwatch and occasionally VTune.
  5. I think var SList := Shared<TMyStringList>.Make(TMyStringList.Create(dupIgnore, True, False)); should work.
  6. pyscripter

    python delphivcl development

    I asked you to submit an issue at Embarcadero/DelphiVCL4Python: Delphi's VCL library as a Python module for building Windows GUI (github.com), but you did not bother... The modules are built from this directory: python4delphi/Modules at master · Embarcadero/python4delphi (github.com)
  7. pyscripter

    Python4Delphi Tutorials/Information

    Look at the tutorials python4delphi/Tutorials at master · pyscripter/python4delphi (github.com) and demos python4delphi/Demos at master · pyscripter/python4delphi (github.com). You will also find a lot of stuff in python | Embarcadero RAD Studio, Delphi, & C++Builder Blogs
  8. pyscripter

    Class properties

    I tried to do something like class Test protected class function GetValue: string; virtual; public class property Value: string read GetValue; end; and I got a compiler error message stating the class property read specifier has to be either a class var or a static class method. Any idea about the reason for this restriction?
  9. pyscripter

    Class properties

    This looks like an inconsistency in the language with regard to class methods and class properties. And I don't think it is documented.
  10. pyscripter

    Class properties

    You access class properties through a class or an instance reference. That reference could be passed to a virtual class getter. Why do they have to be static? This is my question. A related question. How do virtual class methods work? Is there an equivalent to VMT for classes? By the way this works correctly: class Test protected class function GetValue: string; virtual; public property Value: string read GetValue; end; i.e. a normal property with a virtual class getter
  11. pyscripter

    SynEdit preferred version?

    Good suggestion. Go to Next/Previous modification Editor commands · Issue #165 · TurboPack/SynEdit (github.com)
  12. pyscripter

    SynEdit just got a major uplift

    This is correct, but this is the reason GPU support is disabled by default: D2D1RenderTargetProperties( {$IFDEF GPUSupport} D2D1_RENDER_TARGET_TYPE_DEFAULT, {$ELSE} D2D1_RENDER_TARGET_TYPE_SOFTWARE, // much faster in my desktop with a slow GPU {$ENDIF} As far as CPU utilization goes, I have tried with a 10K lines pascal file with highlighting, code folding and indentation lines. Scrolling by pressing continuously the Page Down key results in CPU utiliization around 5% (I7 12700). With GPUSupport enabled (currently incompatible with Gutter.ShowLineNumbers - will be fixed), CPU utilization remains close to 0% but GPU utilization rises to 5% (Intel UHD 770).
  13. pyscripter

    SynEdit preferred version?

    I will ask Embarcadero to update the Getit packages once the current versions is thoroughly tested and optimized, probably in a few weeks time. But the latency you mentioned is always going to be there, since the development is currently very active. So if you want the latest fixes and improvements do use the Github version.
  14. pyscripter

    SynEdit just got a major uplift

    This is not the experience here and in the other testers. Performance with highlighted 10000s of lines is very good. Could you please submit an issue at the Issue Tracker with sample project and text file?
  15. pyscripter

    Spell Checker implementation?

    There were many options mentioned in this thread, but there was no mention of the most obvious one at least on Windows: the built-in Windows spellchecker available since Windows 8. There many advantages compared to the options discussed here. It is free. Very easy to use. Minimal code to add to your project. No need to distribute dictionaries. If the user wants a given language dictionary they can get it through Windows language settings. It persists words added, ignored and autocorrected. It detects duplicate words. I got the idea from Ian Boyed's answer in this Stackoverflow question, but I could not find a Delphi translation of the Windows Spellcheck API. So I created my own. It is included in the attached zip file, along with a demo program. SpellCheck.zip
  16. pyscripter

    SynEdit just got a major uplift

    I suppose it does a bit. FMX is using DirectWrite on Windows, and its graphics engine matches the constructs of DirectX (FMX.Canvas.D2D). One would have to create a VCL abstraction of DirectX that it is similar (possibly identical) to that of FMX. It could be based on Vcl's Direct2DCanvas. That would be useful in porting not just SynEdit but other components from Vcl to FMX and the opposite.
  17. pyscripter

    TSynEdit - Custom Highlighter

    - Update your SynEdit to the latest version from TurboPack/SynEdit: SynEdit is a syntax highlighting edit control, not based on the Windows common controls. (github.com) - Look at the SynGen folder. The file Highlighters-HowTo.htm explains the basic steps. You need to create a grammar file and then SynGen.exe will generate your highlighter.
  18. pyscripter

    Direct2D 1.1 canvas much slower that Direct2D 1.0

    I see you are using ID2D1HwndRenderTarget. However your project also refers to Vcl.Direct2D_1 which should be ..\..\Direct2D_1\Vcl.Direct2D_1.pas but that directory is not part of the project. I wonder whether you can share that as well.
  19. pyscripter

    Direct2D 1.1 canvas much slower that Direct2D 1.0

    By the way FMX graphics on Windows are based on DirectX and they use the IDXGIDevice stuff (units FMX.Context.DX11 and FMX.Canvas.D2D).
  20. pyscripter

    Direct2D 1.1 canvas much slower that Direct2D 1.0

    It has been a while, but did you get a better understanding of the differences in the two approaches and the reasons for the slowness?
  21. pyscripter

    Place image in a TImage

    Demo 29 might be of help.
  22. pyscripter

    [FMX] Dll not found

    Looks like it is looking for python3.3. This is no longer supported. Just check the properties of TPythonEngine. Is UseLastKnownVersion checked?
  23. pyscripter

    Can't execute from ... import

    See MaskFPUExceptions · pyscripter/python4delphi Wiki (github.com)
  24. Something like Module := Import(ModuleName) if Module.__dir__().Contains(FunctionName) then Module.FunctionName()
  25. Wrong assumption. You need to call Free on the Python side or free it from Delphi. You can examine the ownership of a Delphi object in Python using the __owned__ attribute. If __owned__ is true it will be freed automatically. When you wrap objects yourself using DelphiWrappper.Wrap, you can specify the ownership. But here you are returning the object as a function result and you cannot tell who owns the object. Objects returned as function results or by accessing properties are wrapped using Wrap(obj, soReference);
×