Jump to content

Navid Madani

Members
  • Content Count

    34
  • Joined

  • Last visited

Community Reputation

1 Neutral

Recent Profile Visitors

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

  1. RAD Studio 11.3 (2024 build) was posted on my.embarcadero.com on 2/20/2024. Does anyone have further details about this re-release? Thanks in advance.
  2. Navid Madani

    When will be binding to Swift libraries possible ?

    Looking at Swift 5.9 release notes, there is talk of bidirectional C++ interoperability. Has anyone tried it? https://www.swift.org/documentation/cxx-interop/
  3. TDirectory.GetFiles in System.IOUtils has a bug on macOS: In the returned dynamic string array, valid files with names that contain three or four consecutive periods are not included. I ended up having to use macOS system functions instead. If it would help others who could run into this problem, my solution is below. Please post if you find any errors. macOS programming is certainly not my forte. unit Nm.IOUtils; interface uses System.SysUtils , System.Types {$IFDEF MACOS} , Macapi.ObjectiveC , Macapi.CocoaTypes , Macapi.Foundation , Macapi.Helpers {$ENDIF} ; {$IFDEF MACOS} type EItemType = (itFiles, itDirectories); EItemTypes = set of EItemType; function macOS_GetDirectoryContents(const DirectoryPath: string; const ItemTypes: EItemTypes): TStringDynArray; {$ENDIF} implementation {$IFDEF MACOS} function macOS_GetDirectoryContents(const DirectoryPath: string; const ItemTypes: EItemTypes): TStringDynArray; const ARRAYSIZEINCREMENT = 32; var FileManager: NSFileManager; URL, FileURL: NSURL; FileEnum: NSDirectoryEnumerator; Options: NSDirectoryEnumerationOptions; Error: NSError; IsDirectoryVal: Pointer; IsDirectory: Boolean; Candidate: string; i: Integer; ArraySize: Integer; begin FileManager := TNSFileManager.Wrap(TNSFileManager.OCClass.defaultManager); URL := TNSURL.Wrap(TNSURL.OCClass.fileURLWithPath(StrToNSStr(DirectoryPath), True)); Options := NSDirectoryEnumerationSkipsSubdirectoryDescendants; FileEnum := FileManager.enumeratorAtURL(URL, nil, Options, nil); FileURL := TNSURL.Wrap(FileEnum.nextObject); ArraySize := ARRAYSIZEINCREMENT; SetLength(Result, ArraySize); i := 0; while Assigned(FileURL) and FileURL.isFileURL do begin IsDirectoryVal := nil; if FileURL.getResourceValue(@IsDirectoryVal, StrToNSStr('NSURLIsDirectoryKey'), @Error) and Assigned(IsDirectoryVal) then begin if i >= ArraySize then begin Inc(ArraySize, ARRAYSIZEINCREMENT); SetLength(Result, ArraySize); end; Candidate := UTF8ToString(FileURL.path.UTF8String); IsDirectory := TNSNumber.Wrap(IsDirectoryVal).boolValue; if IsDirectory then begin if (itDirectories in ItemTypes) then begin Result[i] := Candidate; Inc(i); end; end else begin if (itFiles in ItemTypes) then begin Result[i] := Candidate; Inc(i); end; end; end; FileURL := TNSURL.Wrap(FileEnum.nextObject); end; SetLength(Result, i); end; {$ENDIF} end.
  4. https://quality.embarcadero.com/browse/RSP-26436 Such a fundamental pattern being broken, it could be a sign of more ominous problems.
  5. I have encountered a strange problem: Delphi Athens is running via Parallels on Apple Silicone. In the following demo, none of the destroyers are called when targeting macOS ARM 64, while everything works OK targeting Windows). Also, I can get the Windows target to report the memory leak when I comment out fDebug.Free in FormDestroy, but not with macOS ARM 64. Can anyone else reproduce this? Am I missing something? Thanks! unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs; type TForm1 = class(TForm) procedure FormDestroy(Sender: TObject); procedure FormCreate(Sender: TObject); private fDebug: TObject; public destructor Destroy; override; end; var Form1: TForm1; implementation {$R *.fmx} // TForm1.FormDestroy is not called when Target is macOS ARM 64-bit procedure TForm1.FormDestroy(Sender: TObject); begin ShowMessage('FormDestroy Called'); fDebug.Free; end; // TForm1.Destroy is not called when Target is macOS ARM 64-bit destructor TForm1.Destroy; begin ShowMessage('Destroy Called'); inherited; end; procedure TForm1.FormCreate(Sender: TObject); begin fDebug := TObject.Create; end; end.
  6. Navid Madani

    TClientDataSet's odd behavior with hyphens in string fields

    Duh! Thank you! I should have tested adding other characters on the tests. When the REST API added the hyphens, that's when everything broke down ...
  7. Thanks, David. No, I don't shun any value types, but we're talking about large record sets, too large for the stack. I was referring to bugs that creep in when the integrity of (mutable) data on the heap is not guaranteed, when variables are mutable. Certainly, records can emulate data integrity patterns with private fields, but that approach is not front and center with Delphi records. Interfaces too can cause memory leaks, and be complicated when weak references are needed. But again, it's an overall safer pattern in Delphi, at least in my experience. Interfaces also help write testable and more easily maintainable code by keeping things decoupled. And yes, try-finally blocks are written by the compiler, but compilers ultimately write machine code. That's the whole purpose of using a high-level language: so we don't have to write all that code. It helps keep things readable. I agree that it's the same basics with memory allocation and release patterns. But again, different languages implement them in different ways, and some patterns are more idiomatic for a specific language, as in this case. I think our discourse is more over language semantics than technical. While I understand and appreciate your points, I am not convinced to change my approach to large amounts of data on the heap.
  8. Navid Madani

    TClientDataSet's odd behavior with hyphens in string fields

    Thank Dmitry, but I did not grasp the implication of your terse comment. The size of string fields needs to be set?
  9. Value types are copied unless passed by reference. That can impact performance. Classes and interfaces would be more efficient. Interfaces can emulate data immutability and prevent bugs. Interfaces obviate the need for try-finally blocks, keep code cleaner and easier to maintain. Interfaces can prevent memory leaks. It is not always a simple case of memory allocation/de-allocation with records on the heap. There can be issues with access violations, and hard to detect bugs if record pointers are accessed but point to invalid data. Again, I said that is what I do when using Delphi as opposed to C.
  10. Depending on what you are trying to do, keeping records on the heap could become an anti-pattern and cause problems. For one, your records could be duplicated on assignments, on the stack, and if your application relies on their consistency, bugs can creep in. Unlike languages like Rust and Swift, all variables in Delphi are mutable. If I needed a large dataset on. the heap, I would either wrap the records in a class or define a class, and in order to maintain their integrity, I would use interface references to access them and avoid memory leaks. Just my two cents.
  11. Navid Madani

    How to test FDConnection with SQLite

    Check the Params TStrings property to check for the database name and other properties. procedure TForm1.Button1Click(Sender: TObject); begin if FDConnection1.Params.Values['Database'] <> '' then ShowMessage('Database name is ' + FDConnection1.Params.Values['Database']); end;
  12. Navid Madani

    TClientDataSet's odd behavior with hyphens in string fields

    Reported as bug: RSP-44009.
  13. In the DUnitX tests below, the first 4 cases fail: the last character is omitted. It seems that for each hyphen added after the first, an extra character from the end is not written to the TClientDataSet field. Is this normal behavior? Thanks in advance. unit uCDSTest; interface uses DUnitX.TestFramework , Data.DB , Datasnap.DBClient ; type [TestFixture] TClientDataSetTest = class private fCDS: TClientDataSet; public [Setup] procedure Setup; [TearDown] procedure TearDown; [Test] [TestCase('Test0','S0002-9270(99)00035-0')] [TestCase('Test1','S0002-9270(99)00035-1')] [TestCase('Test2','S0002-9270(99)00035-2')] [TestCase('Test3','S0002-9270(99)00035-3')] [TestCase('Test4','S0002-9270(99)000353')] [TestCase('Test5','S00029270(99)00035-3')] [TestCase('Test6','S00-02-9270(99)00035-3')] [TestCase('Test7','S00-02-92-70(99)00035-3')] procedure TestCDS(const AValue : string); end; implementation const cFieldname = 'AFieldName'; procedure TClientDataSetTest.Setup; var fd: TFieldDef; begin fCDS := TClientDataSet.Create(nil); fd := fCDS.FieldDefs.AddFieldDef; fd.Name := cFieldname; fd.DataType := ftString; fCDS.CreateDataSet; end; procedure TClientDataSetTest.TearDown; begin fCDS.Free; end; procedure TClientDataSetTest.TestCDS(const AValue : string); begin fCDS.Insert; fCDS.Edit; fCDS.FieldByName(cFieldname).AsString := AValue; fCDS.Post; Assert.AreEqual(AValue, fCDS.FieldByName(cFieldname).AsString, 'Assignment failed.'); end; initialization TDUnitX.RegisterTestFixture(TClientDataSetTest); end.
  14. Navid Madani

    MMX 15.1.8 build 2580: Possible Source Indexer Bug?

    I'll take that back: not a bug - each time I add a unit to the project, the IDE messes up the conditional defines, sometimes inserting two uses clauses into the DPR. While editing, I also erroneously deleted the comma after the unit in the excluded MACOS clause. Restoring the missing comma allowed MMX to index everything.
×