Jump to content

pyscripter

Members
  • Content Count

    983
  • Joined

  • Last visited

  • Days Won

    62

pyscripter last won the day on May 16

pyscripter had the most liked content!

Community Reputation

752 Excellent

7 Followers

Technical Information

  • Delphi-Version
    Delphi 12 Athens

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. pyscripter

    Class helpers catch

    Class helpers compiler or documentation error - RAD Studio Service - Jira Service Management
  2. I would like to share the following in case you encounter the same issue. Class and Record Helpers (Delphi) - RAD Studio states that: Actually, this is not entirely correct. Consider the following: Unit HelperUnit1.pas: TObjectHelper1 = class helper for TObject procedure Test; end; Unit2 HelperUnit2.pas: TObjectHelper2 = class helper for TObject procedure Test; end; Unit SupportClasses,pas: uses HelperUnit1; type TMyClass: class end; Unit MainUnit.pas interface implementation uses SupportClasses, HelperUnit2; begin var MyClass:= TMyClass.Create; MyClass.Test; end; MyClass.Test will use the HelperUnit1.TObjectHelper1.Test implementation even if HelperUnit1 is not even in scope, let alone being "in nearest scope". So it appears that if a class helper is in scope where a class is defined, it is used unconditionally in all units of a project. If not, then what it is stated in the documentation applies.
  3. pyscripter

    How to get a pandas dataframe in delphi

    See python4delphi/Demos/Demo36 at master · pyscripter/python4delphi for an example of using the buffer protocol to read/write numpy arrays in Delphi using the buffer protocol. If you do not care about speed watch the video tutorials and the tutorial demos that show you how to create numpy arrays from delphi and pass them to python and back. In a similar way you can work with dataframes directly.
  4. It includes a number of converters to handle generic collections, but I think you have to add them manually:
  5. pyscripter

    JSON benchmarks

    Since you asked for Serializer benchmakrs: paolo-rossi/delphi-neon: JSON Serialization library for Delphi includes a benchmark against the Rest.Json serializer and it beats it hand down: I have replaced the Rest.Json serializer with the System.Json.Serializers TJSONSerializer. Here are the results: So now TJsonSerializer beats Neon hands down. TJsonSerializer looks good but it has some rough edges. To run the benchmarks I had to add a converter that handles Enumerated values as strings instead of the default integers: type TEnumStringConverter = class(TJsonConverter) public function CanConvert(ATypeInf: PTypeInfo): Boolean; override; function ReadJson(const AReader: TJsonReader; ATypeInf: PTypeInfo; const AExistingValue: TValue; const ASerializer: TJsonSerializer): TValue; override; procedure WriteJson(const AWriter: TJsonWriter; const AValue: TValue; const ASerializer: TJsonSerializer); override; end; { TEnumStringConverter } function TEnumStringConverter.CanConvert(ATypeInf: PTypeInfo): Boolean; begin // This converter can handle any type that is an enumeration Result := (ATypeInf.Kind = TTypeKind.tkEnumeration) and (ATypeInf <> TypeInfo(Boolean)); end; function TEnumStringConverter.ReadJson(const AReader: TJsonReader; ATypeInf: PTypeInfo; const AExistingValue: TValue; const ASerializer: TJsonSerializer): TValue; var LIntValue: Integer; begin LIntValue := System.TypInfo.GetEnumValue(ATypeInf, AReader.Value.AsString); if LIntValue = -1 then // GetEnumValue returns -1 if the name is not found raise EJsonSerializationException.CreateFmt('Invalid string value "%s" for enumeration "%s".', [AExistingValue.AsString, ATypeInf.Name]); // Create a TValue of the specific enum type using its ordinal value. Result := TValue.FromOrdinal(ATypeInf, LIntValue); end; procedure TEnumStringConverter.WriteJson(const AWriter: TJsonWriter; const AValue: TValue; const ASerializer: TJsonSerializer); begin AWriter.WriteValue(System.TypInfo.GetEnumName(AValue.TypeInfo, AValue.AsOrdinal)); end; See also: Bummer: System.Json.Converters already includes TJsonEnumNameConverter that does the job.
  6. pyscripter

    JSON benchmarks

    No. Most of the alternatives do not support serialization. Grizzy and Superobject do. Delphi offers a couple of ways. But serialization is not necessarily dependent on JSON parsing. For example NEON is using System.JSON.
  7. pyscripter

    JSON benchmarks

    hydrobyte/TestJSON: A simple project to test JSON libraries with Delphi and C++Builder. presents JSON library benchmarks comparing a large number of alternatives. One thing that strikes me, is that the System.JSON rtl library is doing relatively well compared to the competition, both in terms of performance and in terms of JSON validation. With the exception of Find, is very competitive in all other areas. I have seen many claims that System.JSON is very slow and that the xyz library is so many times faster. Do these benchmarks suck (like most benchmarks)? Or is it the case that System.JSON is not that bad? What is your experience?
  8. Feature requests added: TJSONSerializer support for Null value and default value handling. - RAD Studio Service - Jira Service Management Add an overload to TJSONSerializer, that serializes without using converters - RAD Studio Service - Jira Service Management
  9. When I serialize a an object with object fields that are nil I get null values in the Json result e.g. { "capabilities": { "positionEncoding": [], "textDocumentSync": { "openClose": true, "change": 2, "willSave": false, "willSaveWaitUntil": false, "save": null }, "notebookDocumentSync": null, "completionProvider": null, } How can I ignore fields that have nil values? System.JSON.Types defines the following: TJsonDefaultValueHandling = (Include, Ignore, Populate, IgnoreAndPopulate); but it is not used anywhere. I also tried to use a converter, but I could not get it to work. And in any case converters are used after the property name is written. Any ideas?
  10. pyscripter

    Component with sub-property event

    It works with Components if you call SetSubComponent or set csSubComponent. Then Events are displayed. e.g, So you can change TTestSub to inherit from TComponent.
  11. pyscripter

    Component with sub-property event

    You need to overwrite the TTestSub.GetOwner.
  12. This is roughly what I had in mind. Suggestions: Have one event with an Enumerated parameter TExecOutput = (eoStdout, eoStdErr) Pass to the callback only the newly added bytes in a TBytes. They can be easily converted to strings using the ISshClient encoding. Keep the output as is. The user has a choice of not providing a callback. The overhead is small.
  13. This is how it is designed to work. I will add an event that is triggered whenever output is added. Add an event to access partial output of ISshExec.Exec · Issue #20 · pyscripter/Ssh-Pascal
  14. ISshExec.Exec was substantially revised and now works in non-blocking mode. Are you using the latest source? Are you using the latest linssh2 binaries? You can execute ISshExec in a thread. Note that then it can be cancelled from the main thread using ISshExec.Cancel. Also you memory leak in TSshExec.Exec · Issue #18 · pyscripter/Ssh-Pascal has been fixed. Can you confirm that?
  15. pyscripter

    TreeView Child Node Data

    In the latest commits, I have added the ability to handle pointer fields and properties. They are converted to python integers. So you could store for example an integer to the TTreeNode.Data. You could also store pointers to python objects using ctypes. See for example the following: from ctypes import py_object, pointer, addressof, cast, POINTER # Create a py_object original = "Hello" py_obj = py_object(original) # Get its address addr = addressof(py_obj) # e.g., 0x7f8b5c403020 # Recover the py_object py_ptr = cast(addr, POINTER(py_object)) recovered_py_obj = py_ptr.contents recovered = recovered_py_obj.value print(recovered) # "Hello" print(original is recovered) # True (same object) addr is an int type (python integer) that can be stored in Delphi pointer property.
×