Jump to content

Jean_D

Members
  • Content Count

    24
  • Joined

  • Last visited

Posts posted by Jean_D


  1. 33 minutes ago, Remy Lebeau said:

    Hard to say when you didn't show the Delphi code to compare.

    Fair point, here is the Delphi code:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      iCnt: Byte;
      iCpt: Byte;
      iSection: String;
      iIniFile: TIniFile;
      iIdentifier: String;
    begin
      iIniFile := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
      for iCnt := 1 to 6 do
      begin
        iSection := 'Tab #' + IntToStr(iCnt);
        for iCpt := 1 to 45 do
        begin
          iIdentifier := 'Key #' + IntToStr(iCpt);
          iIniFile.WriteInteger(iSection, iIdentifier, Random(999));
        end;
      end;
      iIniFile.Free;
    end;
    34 minutes ago, Remy Lebeau said:

    On a side note...

    Thanks for all the pointers. In terms of Visual Studio C++ (or C++ in general), I have very little knowledge. I used AI to help me write the code. The code that I posted is the code that I got with its help. I will use your inputs to improve it and learn from it.


  2. The C++ code might not be 100% identical to the Delphi one. But its essence is the same.

    void CreateIniFile(const char* iniFileName) {
        // Get the directory of the executable
        std::wstring exeDir = GetExecutableDirectory();
        if (exeDir.empty()) {
            return; // Exit if we couldn't get the executable directory
        }
    
        // Combine the executable directory with the INI file name
        std::wstring iniFilePath = exeDir + L"\\" + std::wstring(iniFileName, iniFileName + strlen(iniFileName));
    
        // Define the sections
        const char* sections[] = { "Section1", "Section2", "Section3", "Section4", "Section5", "Section6" };
    
        // Convert iniFile to wide-character string (LPCWSTR)
        std::wstring wIniFile = iniFilePath;
    
        // Loop through the sections
        for (int i = 0; i < 6; ++i) {
            std::string section = sections[i];
            std::wstring wsection;
            ConvertToWideChar(section, wsection);
    
            // Generate a random number of keys between 40 and 50 for this section
            int numKeys = RandomNumber(40, 50);
    
            // Loop through the keys in each section
            for (int j = 1; j <= numKeys; ++j) {
                // Create a key name (e.g., Key1, Key2, ... KeyN)
                std::string key = "Key" + std::to_string(j);
                std::wstring wkey;
                ConvertToWideChar(key, wkey);
    
                // Create an integer value for the key (e.g., 123, 456, ...)
                int value = RandomNumber(1, 1000);  // You can change the range as needed
                std::string valueStr = std::to_string(value);
                std::wstring wvalue;
                ConvertToWideChar(valueStr, wvalue);
    
                // Write the key-value pair to the INI file
                BOOL result = WritePrivateProfileString(wsection.c_str(), wkey.c_str(), wvalue.c_str(), wIniFile.c_str());
    
                if (!result) {
                    std::cout << "Error writing key " << key << " to section " << section << std::endl;
                }
            }
        }
    
        std::wcout << L"INI file created successfully at " << iniFilePath << std::endl;
    }

     


  3. Using 'Delphi 12 Update 1,' I created a simple project. The purpose of the project was to create an 'ini' file (via the TIniFile component) made up of ten sections. Each section holding forty-five keys. Each key having a random integer (between 0 and 999) as value.

     

    When the executable is run under an older 32-bit Windows OS, the creation of the 'ini' takes less than two hundred milliseconds. However, when the same executable is run under a newer 64-bit Windows OS (such as 'Windows 10'), the creation of the 'ini' is considerably slower. Indeed, it took almost three seconds for the file to be created.

     

    As anybody else experienced this 'new' behavior? I am saying 'new' behavior because prior to February 2025, the execution times were almost identical between the older OS and the newer one.


  4. When installing the latest version of Delphi (Delphi 12.1), I forgot to request the installation of Delphi Help. If I try to re-run the installer in order to install the Help, the installer wants to, first, uninstall my current version of Delphi. I don't want to do that as I would have to reinstall all my third-party components.

     

    Is there a way to manually install Delphi Help without having to reinstall Delphi in its entirety?


  5. I have created a DLL with one exported function using the latest version of Delphi (12.1). The function takes one parameter: a record type variable.

    library MyDLL;
    
    uses
      System, SysUtils;
    
    type
      TMyRecord = record
        MyString: AnsiString;
        MyInteger: Integer;
      end;
    
    function FillRecord(var Rec: TMyRecord): Boolean; stdcall; export;
    begin
      Rec.MyString  := 'Hello from Delphi';
      Rec.MyInteger := 42;
      Result := True;
    end;
    
    exports
      FillRecord;
    
    begin
    end.

    In my C++ Builder 6.0 application, I have declared the following:

    struct TMyRecord {
      char *MyString;
      int MyInteger;
    };
    
    extern "C" __declspec(dllimport) bool __stdcall FillRecord(TMyRecord *Rec);

    When calling the 'FillRecord' function from my C++ Builder application, I do not get the expected results:

       TMyRecord iMyRec;
       Memo1->Lines->Clear();
       Memo1->Lines->Add(Format("Address: %p", ARRAYOFCONST((&iMyRec))));
       if (FillRecord(&iMyRec)) {
          String iData = iMyRec.MyString;
          Memo1->Lines->Add("iMyRec.MyString:  " + iData);
          int iNumber = iMyRec.MyInteger;
          Memo1->Lines->Add("iMyRec.MyInteger: " + IntToStr(iNumber));
       } else {
          Memo1->Lines->Add("Error calling FillRecord");
       }

    I am expecting:

    iMyRec.MyString:  Hello from Delphi
    iMyRec.MyInteger: 42

    But I am getting:

    iMyRec.MyString:  H
    iMyRec.MyInteger: 42
    

     

    I am drawing a blank when trying to figure out what I am doing wrong. Any inputs/suggestions to solve my issue would be greatly appreciated. Thank you
     

     

     


  6. We have a small cross-platform application written in 'Delphi 12.' Within the application, we have a few lists (TListView) of various data. In order to 'filter' the data displayed within a list, we set the 'SearchVisible' property of our lists to 'true.'

     

    This works flawlessly when our application runs on an iOS device. However, when the application runs on an Android device, the user is not even able to input text in the search box. The virtual keyboard does display. But none of its inputs are displayed within the search box. As a result, the data is not filtered.

     

    Has anybody else experienced the same issue? If you did, have you found a work around?


  7. 5 hours ago, Jirka52 said:

    Try to set property StyleName to Windows. I had the same problem, I put all controls on panel, set property StyleName to Windows and now it is ok. But it was not MDI application

    Clipboard_02-16-2024_01.jpg

    Thanks for the tip. I gave it a try to no avail. Everything appears to be working fine as long as form style is not set to 'fsMDIForm.'


  8. Wanting to test the 'CustomTitleBar' feature that comes with the newer versions of Delphi, I created a small Delphi 12 application for testing purposes. To my main form, I added a 'TitleBarPanel' that I assigned to the 'Control' property of my main form 'CustomTitleBar.'

     

    If I set my form style to 'fsNomal,' I am able to change the colors of the custom title bar at design time and the bar displays properly at run time.

     

    However, if I set my form style to 'fsMDIForm,' I am still able to change the colors of the custom title bar at design time. But the bar does not display properly at run time (my custom colors are ignored).

     

    Is this normal behavior or am I doing something wrong? 


  9. We have an app for Android (originally created using the Delphi 11 but, now, maintained using Delphi 12). After a fresh install, the login process will behave properly. However, after logging out, any attempt to log back in will have the 'caret' not aligned with the 'cursor' (see below). By the way, both the username and pin are TEdit. How do I force the 'caret' to be aligned with the 'cursor?'
     

    1249962580_Screenshot_20240110-160521-Clean.thumb.jpg.cab0638ae88c924d3aa208018571e66e.jpg

     

    Then, once in a while, if we tap the username field in order to enter a new value, we get the following error:

     804556882_Screenshot_20240110-163939-Clean.thumb.jpg.af5f482a192e9ae2205485bd21e27c27.jpg

     

    Has anybody else experienced this strange behavior/error and found a way to solve it? By the way, none of these issues were present under Delphi 11.


  10. Quote

    In case you have to call RequestPermissions(), are you waiting for request_Result()?

    Yes, I was. But your solution is more elegant.

     

    Quote

    No.  It (MANAGE_EXTERNAL_STORAGE) is a permission like any other.  The user has to grant access to it.

    Since it is not defined within the 'Androidapi.JNI.Os.pas' file, I didn't think that I had to follow the same process as I did for 'WRITE_EXTERNAL_STORAGE'. How would I do that.

     

    Quote

    Are you getting any kind of runtime error about the file not being created?

    No, I am not getting any error. The application runs 'properly.' The issue is that, instead of storing the 'zip' file within the external SD card, it saves it within the internal 'Documents' folder. Since I am running out of space 'internally,' the compression does not complete.


  11. 1 hour ago, Remy Lebeau said:

    What problem are you having with it, exactly?  Can you be more specific?  What does your code look like that is not working?  Did you grant permission to your app to access the external SD card?  Do you have code that prompts the user if permission has not been granted yet?

    Did you grant permission,? Do you have code that prompts the user if permission has not been granted yet?

     

    I believe that I do:

    procedure TForm_Main.request_Result(const aPermissions: TClassicStringDynArray; const aGrantResults: TClassicPermissionStatusDynArray);
    begin
      v_PermissionGranted := ((Length(aGrantResults) = 1) and (aGrantResults[0] = TPermissionStatus.Granted));
    end;
    
    procedure TForm_Main.request_Permissions(aPermission: String);
    begin
      PermissionsService.RequestPermissions([aPermission], request_Result);
    end;
      v_PermissionGranted := PermissionsService.IsPermissionGranted(JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE));
    
      if not v_PermissionGranted then
        request_Permissions(JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE));

    In terms of 'MANAGE_EXTERNAL_STORAGE,' it is only defined within in the manifest file. Is that not enough?

     

    My issue is that, when I execute the following code, the 'zip' file is not created on the SD card.

    iZipFile := TZipFile.Create;
    iZipFile.Open(System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetSharedDocumentsPath, 'Folder-Content.zip'), zmWrite);

     


  12. I have a Moto G6 with an 'external' SD card. Because, my device 'internal' storage is running low in space, I thought that I would attempt to write a Delphi app that would allow me to compress the content of my 'internal' Camera folder into a 'zip' archive stored on my 'external' SD card. I understand that I could use the 'built-in' Files manager app to move the files onto my 'external' SD card. But for practice purposes, I decided to try to create my own app.

     

    I am using the latest version of Delphi Alexandria (v. 11.2). I am able to access my 'internal' DCIM folder and read its content as well as to add files to a 'zip' file. However, I am unable to 'force' the saving of my 'zip' file to my 'external' SD card. Any input would be greatly appreciated.


  13. I have Delphi 11.2 Alexandria installed on a VMware vSphere Hypervisor (ESXi) 6.5 virtual machine (hosted outside of my work enviroment). I access the virtual machine via a Microsoft Remote Desktop Connection. For my iOS app I have a MacBook Air next to my PC.

     

    How do I 'connect' my 'inhouse' MacBook Air to the VM hosting my work environment in the Cloud? Is that event feasible?

     

    Any input would be greatly appreciated.


  14. When creating a small test app for Android using Delphi 10.4.1, I use a TMemo component with WordWrap set to true.

     

    When running the app, when it is time to the word wrapping to become active, the cursor jumps to the top of the memo. Has anybody else experienced this issue?

     

    By the way, the app works properly when created with Delphi 10.3.3

    • Thanks 1
×