Jump to content

pyscripter

Members
  • Content Count

    1065
  • Joined

  • Last visited

  • Days Won

    70

Everything posted by pyscripter

  1. pyscripter

    New Hint in D13

    The following gives a hint in D13: H2077 Value assigned to Test never used: function Test(Value: Integer): Integer; begin Result := -1; if Value > 0 then Result := 0 else Assert(False); end; Is the hint justified? What if Assertions are turned off? Note that in earlier versions you would get a warning if you omit the first line.
  2. pyscripter

    New Hint in D13

    Indeed.
  3. D13 does not let me add breakpoints in Vcl.Forms. Use debug dcus is set and I can debug other Vcl units such as Vcl.Controls. Does anyone else have the same issue?
  4. pyscripter

    Cannot debug Vcl.Forms with D13

    https://embt.atlassian.net/servicedesk/customer/portal/1/RSS-4094
  5. pyscripter

    New Hint in D13

    The following correctly produces the same hint, whilst in some earlier Delphi versions it wrongly produced a hint if the offending statement was omitted. function Test(Value: Integer): Integer; begin Result := -1; if Value > 0 then Result := 0 else Abort; end;
  6. pyscripter

    New Hint in D13

    Actually I am getting the hint with both Win32/Win64 (32 bit IDE) and a DEBUG configuration that looks like a release configuration. The funny thing is that if I remove the offending line and disable assertions, then I get a warning about the undefined result! You can't win.
  7. pyscripter

    New Hint in D13

    It does not produce a hint when you target x86, but it does when you target x64.
  8. @Uwe Raabe Is it just me? I am using the standard Windows Defender.
  9. pyscripter

    New Delphi features in Delphi 13

    Yes sure. They can work side-by-side.
  10. pyscripter

    Cannot download MMX. Virus detected

    I had to turn Real Time Protection (Windows security setting) off to download the file. Then as soon as I turned it back on, the anti-virus detected Trojan:Script/Wacatac.B!ml and immediately deleted the file.
  11. As per title. The MultiInstaller in the Install subdirectory has also been updated and now installs P4D in both the 32-bit and 64-bit IDEs. It is the fastest way to install P4D. Just clone the repo and run MultiInstaller. It only takes a few seconds to install in both IDEs and configure the search paths. The provided setup.ini expects the folder to be called P4D. If not, you need to edit the setup.ini file accordingly. The only catch is that in the dialog box you should specify the parent folder of "P4D" (i.e. the folder containing the directory to which you have copied/cloned P4D) and not the P4D folder itself.
  12. pyscripter

    New Delphi features in Delphi 13

    There have been some significant improvements to TJSONSerializer. The following have been added: TJsonValueSerialization = (Always, ExcludeDefault, ExcludeSpecial, ExcludeAll); TJsonReferenceHandling = (None, Preserve, IgnoreCycles, ErrorOnCycles); Also the following related issues I had submitted have been fixed. TJSONSerializer support for Null value and default value handling. - RAD Studio Service - Jira Service Management TJsonObjectWriter,Container should be declared as TJSONAncestor - RAD Studio Service - Jira Service Management TJsonDictionaryConverter cannot serialize TDictionary descendent classes - RAD Studio Service - Jira Service Management Allow empty keys in JSON objects - RAD Studio Service - Jira Service Management In addition the a couple of my older issues have been addressed: https://quality.embarcadero.com/browse/RSP-41987 TDockTabSet does not DPI scale the images displayed - RAD Studio Service - Jira Service Management Note that, for some reason, the list of issues fixed in New features and customer reported issues fixed in RAD Studio 13.0 - RAD Studio does not include some of the above fixed issues. So the list does not appear to be comprehensive.
  13. Whilst there are many Delphi components for detecting changes to file system folders they suffer from serious limitations: typically they only allow you to monitor a single folder they do not support the monitoring of specific files they rely on the FindFirstChangeNotification API which gives no information about what has changed, requiring an inefficient search. I have created a new file system monitoring library that addresses the above limitations. Features: Easy to use, but also suitable for heavy duty monitoring Single unit with no external dependencies Allows monitoring folders and/or specific files Uses the ReadDirectoryChangesW API which provides information about what exactly was changed A single instance of the component can handle the monitoring of many folders and/or files Uses an I/O completion port for efficient handling of large numbers of requests A single thread handles all requests A different notification handler can be specified for each request You can have multiple handlers for each folder or file When you monitor folders you can specify whether you want to also monitor subfolders Installation: You do not need to install the library. Just download or clone the repo and add the source subdirectory to the Library path. Usage: procedure TForm1.FormCreate(Sender: TObject); begin // Create the IFileSystemMonitor interface FFileSystemMonitor := CreateFileSystemMonitor; // Monitor a directory FFileSystemMonitor.AddDirectory(TPath.GetTempPath, False, HandleChange); // Also monitor a specific file FFileSystemMonitor.AddFile('pathtoyourfile', HandleChange); end; procedure TForm1.HandleChange(Sender: TObject; const Path: string; ChangeType: TFileChangeType); begin with lvEventList.Items.Add do begin Caption := GetEnumName(TypeInfo(TFileChangeType), Integer(ChangeType)); SubItems.Add(Path); end; end; To stop monitoring a specific file or folder you use the following methods: function RemoveDirectory(const Directory: string; OnChange: TMonitorChangeHandler): Boolean; function RemoveFile(const FilePath: string; OnChange: TMonitorChangeHandler): Boolean;
  14. pyscripter

    New YAML Parser Library - VSoft.YAML

    With JSON writing/reading, adding serialization for Delphi 10.4+ should be trivial.
  15. pyscripter

    New YAML Parser Library - VSoft.YAML

    I understand. Json serialization (System.JSON.Serializer) became reliable only with Delphi 11 and later. I think it was introduced in Delphi 10.4.
  16. pyscripter

    New YAML Parser Library - VSoft.YAML

    Nice job. It would be great, if there was also a serialization layer. For instance you have a config object and you save it to a YAML file with a single command. You then deserialize it and use it directly without having to query the YAML document. See for instance pyscripter/toml-delphi: Toml parser and writer for Pascal and Delphi.
  17. pyscripter

    Better TStringList in Spring4D or elsewhere

    This is not quite true. TStrings does not define Insert/DeleteStrings but it has an AddStrings function. This function is inefficient (adds the strings one-by-one), but the operation is enclosed in Begin/EndUpdate, so you only get change notifications before and after the whole operation. In an analogous way, an InsertStrings function would/should only notify before and after the whole operation. There is no need/requirement for calling Changing/Changed per item. @Dave Novo It is indeed easy to write a TStringList class helper that adds efficient implementations of Insert/DeleteStrings. You can get access to the private variable FList using the well known "with Self" trick as @Anders Melander pointed out earlier. It is worth noting, that, unfortunately, these functions cannot be implemented efficiently at the TStrings level. The underlying data structure of SynEdit is a TStrings descendent. Whether that is a good choice is debatable, but It does define such functions (InsertStrings, DeleteLines) and implements efficiently with a single Move, so you could have a look at SynEdit/Source/SynEditTextBuffer.pas at master · pyscripter/SynEdit to get ideas about how to implement them for TStringList. It is worth creating an enhancement request to the Delphi issue tracker, asking for such functions to be added. Insert/DeleteStrings could be declared as virtual in TStrings with inefficient implementations and then implemented efficiently in descendent classes. Also, the following procedure procedure AddStrings(const Strings: array of string); overload; should be declared virtual and implemented efficient in descendent classes.
  18. pyscripter

    Select multiples lines at once

    Indeed, but this is just one of the many IDE Editor limitations:
  19. pyscripter

    A smart case statement in Delphi?

    And writing everything in assembly may save you a few miliseconds.... This is not about efficiency, but about writing better and more readable code. It is the compiler's job to convert source code to the most efficient machine code.
  20. pyscripter

    Am I doing something wrong ?

    The variable HW is defined in the main interpreter and is not available in the newly created sub-interpreter, which is isolated from the main interpreter. Hence the error. PS: I wonder why everyone is so obsessed with running python in threads, especially GIL owning ones. This is quite an advanced feature and requires deep understanding of the topic. P4D makes it easy to use this feature, but this does not mean that users do not need to study the python documentation and understand the nuances. To use an analogy, Delphi encapsulates threads pretty well but doing thread programming in Delphi is not trivial and requires understanding the pitfalls.
  21. pyscripter

    A smart case statement in Delphi?

    You could even take it a few steps further as in python's structural pattern matching What’s New In Python 3.10 — Python 3.10.18 documentation or C# pattern matching Patterns - Pattern matching using the is and switch expressions. - C# reference | Microsoft Learn Of course I am day-dreaming. Who knows. Maybe one day...
  22. pyscripter

    New file system monitoring component

    You will still have the same issue if the parent directory (or the parent of the parent...) gets deleted or renamed. Even if not, you may be getting many more notifications than you need. Also you would have to watch subfolders, which you may not want. It is not worth it. Checking every x seconds whether the monitored directories still exist, is a tiny overhead.
  23. pyscripter

    New file system monitoring component

    @mjustin Have a look at the source code. https://github.com/pyscripter/FileSystemMonitor/blob/2dd27a0570ae2f839acb9de3bf67bb2247893784/Source/FileSystemMonitor.pas#L415C16-L415C41 All the thread does is wait on the I/O complection port using GetQueuedCompletionStatus. This function blocks until a change happens. The only polling that takes place is to check every 5 seconds, for deletion/rename of the monitored directories themselves, which are not reported by ReadDirectoryChanges. Folders can be attached to/detached from the completion port at any time, without any problem.
  24. pyscripter

    Correctly let python free a result

    For the benefit of anyone reading this thread, the most powerful way to allow your python script to create instances of a Delphi class (e.g. TEntry) is to create a wrapper: type TEntryClassWrapper = class(TPyClassWrapper<TEntry>) constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); overload; override; end; { TEntryClassWrapper } constructor TEntryClassWrapper.CreateWith(APythonType: TPythonType; args, kwds: PPyObject); var _obj : PPyObject; begin if GetPythonEngine.PyArg_ParseTuple( args, 'O:CreteWith',@_obj ) <> 0 then begin Create(APythonType); DelphiObject := TEntry.Create(GetPythonEngine.PyObjectAsString(_obj)); end; end; You need to register and initialize the wrapper in your Form.Create: procedure TForm1.FormCreate(Sender: TObject); begin PyDelphiWrapper1.RegisterDelphiWrapper(TEntryClassWrapper).Initialize; end; and then in python: from spam import * entry = Entry('Test') print(entry.Name()) entry = None The Delphi TEntry class is exposed as the python type Entry in your python code.
  25. pyscripter

    Correctly let python free a result

    Not really. You can use the following ExecStrings overload procedure ExecStrings(strings: TStrings; locals, globals: PPyObject; const FileName: string = '<string>'); overload; providing your own globals and locals so that you do not mess up the python namespace. Please search in this forum. There was a discussion about this.
×