-
Content Count
983 -
Joined
-
Last visited
-
Days Won
62
Everything posted by pyscripter
-
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.
-
Class helpers compiler or documentation error - RAD Studio Service - Jira Service Management
-
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?
-
How to get a pandas dataframe in delphi
pyscripter replied to ricardo chapingo's topic in Python4Delphi
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. -
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?
-
Ignoring nil values with ΤJsonSerializer
pyscripter replied to pyscripter's topic in RTL and Delphi Object Pascal
It includes a number of converters to handle generic collections, but I think you have to add them manually: -
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.
-
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.
-
Ignoring nil values with ΤJsonSerializer
pyscripter replied to pyscripter's topic in RTL and Delphi Object Pascal
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 -
Component with sub-property event
pyscripter replied to Anders Melander's topic in Delphi IDE and APIs
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. -
Component with sub-property event
pyscripter replied to Anders Melander's topic in Delphi IDE and APIs
You need to overwrite the TTestSub.GetOwner. -
executing a command with ssh-pascal runs into timeout
pyscripter replied to dummzeuch's topic in Network, Cloud and Web
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. -
executing a command with ssh-pascal runs into timeout
pyscripter replied to dummzeuch's topic in Network, Cloud and Web
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 -
executing a command with ssh-pascal runs into timeout
pyscripter replied to dummzeuch's topic in Network, Cloud and Web
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? -
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.
-
TTreeNode.Data is a Pointer property and WrapDelphi does not support raw pointer properties. The only pointer property supported is PPyObject. So if your wrapped class had a property declared as PPyObject it would work. This also explains the error message. To be able to use the Data property you would need to modify the TTreeNode wrapper and do some custom wrapping of the TreeNode.Data property. Alternatively you could save whatever info you need to store in a python data structure (possibly dict for easy access).
-
@Alex7691Good work. It is useful to have a drop-in fast generics replacement. A couple of questions: Is there an impact on code size? I see a lot of code included that it is not directly related to generics. (e.g. TSyncSpinlock, TSyncLocker, TaggedPointer, TCustomObject. TLiteCustomObject etc.). Are they actually essential for the rapid collections?
-
Linking to a C obj file that makes Windows calls
pyscripter posted a topic in RTL and Delphi Object Pascal
I am trying to link an .obj file generated using Visual Studio from C file. The C file makes Windows calls such as VirtualFree; When I try to compile the Delphi source code with {$L} directive in 32 bits Delphi complains about [dcc32 Error] ExtPCRE.pas(889): E2065 Unsatisfied forward or external declaration: '__imp__VirtualFree@12' Is there a way to resolve this without changing the C code? In 64 bits the name comes undecorated as __imp_VirtualFree and I am resolving this as: type TVirtualFree = function(lpAddress: Pointer; dwSize: SIZE_T; dwFreeType: DWORD): BOOL; stdcall; const __imp_VirtualFree: TVirtualFree = WinApi.Windows.VirtualFree; Is this correct? And a related question fpc provides for the following syntax: Var MyVar : MyType; external name ’varname’; The effect of this declaration is twofold: No space is allocated for this variable. The name of the variable used in the assembler code is varname. This is a case sensitive name, so you must be careful. Can you achieve the same somehow in Delphi? -
I believe they do among other styles. (see images in the home page) @Carlo Barazzetta Can you enlighten us on this?
-
Good alternative styled Task Dialog implementation: EtheaDev/StyledComponents: Components similar to Delphi VCL Buttons, Toolbar, DbNavigator, BindNavigator, ButtonGroup and CategoryButtons with Custom Graphic Styles, and an advanced, full-customizable TaskDialog, also with animations!
-
[RSP-41990] Style the Windows Task dialog (Vcl) - Embarcadero Technologies
-
xaml island Ask if Embarcadero will integrate UWP & WinUI in comming Version of Radstudio
pyscripter replied to bravesofts's topic in Windows API
Not quite. See for instance Ohh...WinUI3 is really dead! - When can we expect the announcement? · microsoft/microsoft-ui-xaml · Discussion #9417 The Microsoft strategy for GUI App development is utterly messed up: WinForms WPF Xamarin Forms UWP WinUI3 MAUI And there is no longer a GUI designer. You have to develop XAML in a text editor. Discussion: WinUI 3.0 XAML Designer · Issue #5917 · microsoft/microsoft-ui-xaml -
FWIW, the latest version of GExperts from Experimental GExperts Version – twm's blog installs and works fine here with Delphi 12.3.
-
VCL Forms with Border Style as bsDialog increase their width and height from Delphi 10.4 to Delphi 12
pyscripter replied to Oscar Hernández's topic in VCL
Yes I do notice the difference. However I do not have 10.4 installed to compere. Delphi 12 behaves the same as Delphi 11 though. -
VCL Forms with Border Style as bsDialog increase their width and height from Delphi 10.4 to Delphi 12
pyscripter replied to Oscar Hernández's topic in VCL
Are you using Vcl? Are you using styles? I can see that in your images the form title bars are styled differently. I don't see that in a simple dialog: Delphi 11: Client width 269, Width 285 Delphi 12: Same.