Jump to content

PeterBelow

Members
  • Content Count

    447
  • Joined

  • Last visited

  • Days Won

    12

Posts posted by PeterBelow


  1. 10 hours ago, robertjohns said:

    Thanks , no it is not a text file it is binary file where I need to search all instances of t.o.p.s and need to replace only t as h in all the instances by inc method and save the file

    Since the replacement does not change the total size of the data you can load the file into a buffer suitable for binary data, do the replacement in this buffer and finally write it back to the file. A suitable buffer would be a TMemoryStream. The question is what these '.' bytes in your target string are. If these are actually zero bytes displayed as '.' in a hex viewer the target would be simply the UTF16 string 'tops', if these are real dot characters it would probably rather be the ANSI string 't.o.p.s'.  You can probably answer that by looking at the byte following the 's', it should be 0 if this is UTF16 text. Let's assume it is, then the algorithm would be like this (untested!):

     

    procedure ReplaceBytesInFile(const aFilename: string; const
        aSearchBytes, aReplaceBytes: TBytes);
    var
      LBuffer: TMemoryStream;
      LNumBytes: Integer;
      LPos, LEnd: PByte;
    begin
      LNumBytes := Length(aSearchBytes);
      Assert(LNumBytes = Length(aReplaceBytes), 'Arrays have to be of the same length!');
      if LNumBytes = 0 then
        Exit;
    
      LBuffer := TMemoryStream.Create();
      try
        LBuffer.LoadFromFile(aFilename);
        LPos := LBuffer.Memory;
        LEnd := LPos;
        Inc(LEnd, LBuffer.Size - LNumBytes );
        while LPos < LEnd do begin
          if LPos^ = aSearchBytes[0] then begin
            if CompareMem(LPos, @aSearchBytes[0], LNumBytes) then begin
              CopyMemory(LPos, @aReplaceBytes[0], LNumBytes);
              // or
              // Move( aReplaceBytes[0], LPos^, LNumBytes );
              Inc(LPos, LNumBytes);
            end
            else
              Inc(LPos);
          end
          else
            Inc(LPos);
        end;
        LBuffer.SaveToFile(aFilename);
      finally
        LBuffer.Free;
      end;
    end;
    
      ReplaceBytesInFile(theFilename,
        TEncoding.Unicode.GetBytes('tops'),
        TEncoding.Unicode.GetBytes('hops')
        );

     


  2. 1 hour ago, aehimself said:

    Yes, and unfortunately loading the stream overwrites this setting; it has no effect in the new document being loaded.

    My issue with ConsistentAttributes is that it needs a selection - and for that I need to reposition the cursor again, most probably ending up at the same slowdown.

     

    I'm attempting to experiment with EM_GETTEXTRANGE but unfortunately it doesn't seem to care about formatting at all, just returns as many characters as I desire.

    As far as I know the MS richedit common control does not support owner drawing at all, which is the reason why styling does not work for it. You could try to parse the rich text and modify the main color table in it before it is loaded, but I would rate that as a desparate measure; the RTF format is complex, to say the least.

     

    You could try to select larger blocks of text  (e.g. lines or paragraphs) to find some with consistent text color; if your text is mainly the default color that may reduce the number of SelStart/SelLength calls needed to a managable number.

     


  3. Have you tried to just set DefAttributes.Color  before calling the inherited StreamIn method? SelAttributes.ConsistentAttributes may also be of use if you really need to manually correct the font color.


  4. 3 hours ago, Al T said:

    I'm trying to find a automatic solution that will force Delphi to reload a design time package every time the project that contains that component loads.

     

    Anyone know of a solution?

     

    I'm not sure I understand your requirement, but what you can do is this:

    With no project or project group loaded in the IDE, go to the Component -> Install packages menu. The appearing dialog list all design-time packages the IDE knows about (from the registry). Make sure package in question is not checked in the list. Close the dialog with OK. You may want to close and restart the IDE and call up the dialog again to vertfy that the package ist still unchecked.

    Now open the project in question, call up the dialog again and this time check the package. OK the dialog, do a save all for good measure.

    These steps should make sure the component package is only loaded for projects that explicitely want that. The project-specific package selection is stored in the project's DPROJ file.


  5. 2 hours ago, Chris-J said:

    Hello All,
    I hope this is the right place to ask this question.

    I am trying to make my desktop app (written in C++Builder) look slightly more modern/cloud/browser-like.  Researching this, I find that one (aesthetic) way of giving more of a cloud impression, is to use use (Google) web-fonts rather than (Microsoft) desktop fonts.   But when I click on "Font" in any of my VCL components (labels, etc) the fonts offered to me are all (Microsoft) desktop fonts.
    So my question is: how can I use a web-font such as 'Open Sans', which is free/open-source: 
    https://fonts.adobe.com/fonts/open-sans ... in C++Builder ?

    Thanks in advance for any suggestions.

    To be able to use a font on Windows it has to be installed (Font applet in the control panel or using the Windows font API, i. e. AddFontResourceEx).  You have to do this on your user's systems as well, so have to distribute the font with your application.


  6. 10 hours ago, Heremik said:

    Hello,

    I work with Delphi from the begining (even begun with turbo pascal).

    I have to make calculation with very big array. if I use dynamic array no problem for the size.

    But dynamic array are very slow vs static array (about at least 2X).

    So my intention was to use static array to perform my objective.

    But, i have a problem.

     

    When I try a clean VCL projet and I declare that :

            Table : array[0..536870473] of integer; => Ok
            Table : array[0..536870474] of integer; => Access violation (74 to 76)
            Table : array[0..536870477] of integer; => Compilation error, data too big > 2Go...

     

    I have tried with boolean  :

                Table: array [0 ..  2147481895] of Boolean; => Ok
                Table: array [0 ..  2147481896] of Boolean; => Access violation (896 to 911)
                Table: array [0 ..  2147481911] of Boolean => Compilation error, data too big > 2Go...

     

    Ok, Access violation is just an error to the limitation. But in 64 bits why limitation to 2 Go ???????

    I have 80 Go of RAM on my computer, and I don't understand why my static array are limited.

     

    Is there a solution ? (with performance, because I always need speed).

    This seems to be a limitation of the compiler, System.GetMem does use NativeInt for the size parameter, so can allocate more than 2GB for a 64 bit target.

    This works:

    procedure TForm2.Test;
    var
      p: pinteger;
    begin
      GetMem(p, NativeInt(High(Integer)) * Sizeof(Integer));
      try
        Caption := Format('p= %p',[p]);
      finally
        FreeMem(p);
      end;
    end;

    The only problem is that you cannot declare a proper static array type for this memory block, so would have to do all the index calculations in code.

    However, you  can size a dynamic array to more than 2GB:

    procedure TForm2.Test2;
    var
      a: array of integer;
    begin
      SetLength(a, High(Integer));
      try
        Caption := Format('p= %p',[pointer(a)]);
      finally
        setlength(a, 0);
      end;
    end;

     


  7. 16 hours ago, Al T said:

    I'm just worried "Developer license" will downgrade all previous versions like my Enterprise license did...

     

    When I upgraded from 10.4 developer to Delphi 11.0 Enterprise... all previous versions of Delphi upgraded to Enterprise.   I'm wondering if I install Delphi 12 Developer... would it downgrade all previous versions to developer?

    No, all previous licences for higher editions will stay valid.


  8. 18 hours ago, Al T said:

    Hi,

     

    Anyone know if it's possible to have a Delphi Enterprise and Developer license on the same computer for two different versions?

     

    Thank you in advance!

     

    P.S.

     

    I have Delphi 11 Enterprise and can't afford either subscription or new price.  I was thinking of buying the full price developer version instead.

    Two different editions of the same Delphi/RAD Studio major version cannot coexist on the same PC, different editions of different major versions can, however. If you need the former you have to install one of the editions in a VM or different PC.


  9. 22 hours ago, karl Jonson said:

    I have this procedure:

    
    procedure FindDuplicate(Qry : TADOQuery);

    The Qry contains just 1 column: "Codes"
    Which the most efficient way to check that "Codes" column doesn't contain any duplicates ?

    TIA

    Modify the SELECT statement for the query to include an ORDER BY clause for the code column. Then you can walk over the query result and just compare the current record's code to the one from the previous record (which you remember in a local variable in the loop).

    You can also formulate a SELECT statement that just returns the duplicates of course...


  10. 19 hours ago, Levente said:

    check the Library path in the Tools -> Options dialog, Language -> Delphi -> Library page. It should start with $(BDSLIB)\$(Platform)\release. The "debug dcus" path on the same page should be $(BDSLIB)\$(Platform)\debug. Check this for every of the platforms you have installed (combobox at the top of the page).

     

    I checked, and everything seems OK.

    Any other idea?

     

    The next thing to check would be whether the folder $(BDSLIB)\$(Platform) resolves to for your target platform ( should be C:\Program Files (x86)\Embarcadero\Studio\22.0\lib\android64 for an install using the default folders) is actually there, contains release and debug subfolders, and see if these contain the file(s) the error message moans about, e.g. system.classes.dcu and system.classes.o. I think that should be the file names. I have not installed Android platforms, so cannot check directly.

     

    If the files are there go and check the pathes in the specific project options, also check what path the BDSLIB environment variable resolves to.

     


  11. 8 hours ago, Levente said:

    I have installed Delphi 11.2, I am having problems.

    I used the migration tool, web Install. Keep Existing registry option. With Android, IOs.

    Restored the data (from migration tool).

     

    After installation, I can't run android project. A Windows project can be compiled.

    There is only one button on the form, nothing else, the following error appears when compile to the Android platform:

    [DCC Fatal Error] Project1.dpr(6): F2613 Unit 'System.Classes' not found.

     

    Where can I found a solution?

     

    check the Library path in the Tools -> Options dialog, Language -> Delphi -> Library page. It should start with $(BDSLIB)\$(Platform)\release. The "debug dcus" path on the same page should be $(BDSLIB)\$(Platform)\debug. Check this for every of the platforms you have installed (combobox at the top of the page).


  12. 14 minutes ago, Stano said:

    In such cases I use RadioGroup. It is easier and the user immediately sees what he can and cannot do. The principle is the same.

    Does only work if only one item can be selected from the group, but IO think in OPs case selecting both OptionOne and OptionTwo would be valid.


  13. 9 hours ago, AlanScottAgain said:

    Hi

    I have a gauge that draw I on a Skia paintbox.

    I can move the gauge with the mouse. 0-100

     

    SkPaintBox1.Hint:= IntToStr(Position);
     SkPaintBox1.ShowHint:= True;

     

    Shows the hint but not as the mouse moves.


    How can I show a hint to display the current value as the mouse moves to update the gauge?

     

    Do I need to create my own hint window?

     

    Thanks

    Alan

     

    The hint system is designed to show a hint for a certain time when the mouse enters a control's real estate. In your case the mouse stays over the paintbox, so the hint is not shown again even if its value changed. Try to call Application.CancelHint after changing the value. And if you draw the gauge anyway, why not draw the value as well instead of using a hint window?


  14. 2 hours ago, Zazhir said:

    I need to set a focus inside a Tedit, simple like this. But the problem is, the component is inside a TRibbonPage, which is only showed if a clicked on. The only event that have is the RibbonTabChange (in TRibbon).

     

    I've done like this, but all the others attempts have gonne wrong....

     

    image.png.0fbcd64e77df6e325db86f4f9e3c41a7.png

    CODIGO needs to be focused, how can I do that??

     

    You have a timing issue here, the event fires before the page has become visible and the controls on it can be focused. The usual fix for such problems is to post (PostMessage) a custom message to the form and do the focus change in the handler for this message. There is also a OnTabVisibleChanged event for TRibbon, perhaps that fits better with your goal.


  15. I would rewrite this code using the routines from System.IOUtils. Use TDirectory.GetFiles to get a list of files in a directory you can then walk over.  TPath.GetTempPath gets you the user's temp folder, TFile.Delete deletes a file. Use a try except block around this statement to catch a failure to delete a file.


  16. 12 hours ago, Zazhir said:

    I have a complete delphi application using tatuk and a lot of components. 

     

    When i use a OpenDialog to call or search to a file in the Windows Explorer, and I give a right click in the mouse button the follow popup is showed.

    I bilieve that the write is corean or japanese, but I really don't know why this language is displayed, since the Windows native language that I'am using to the aplication and to my PC is Portuguese.

     

    Any help to what is going on here and how can I fix it?

     

    image.thumb.png.a310faf32e7175836402f01945c3b4fe.png

    Scan you PC for malware, looks like something installed context menu extensions for Windows explorer...


  17. 11 hours ago, Berocoder said:

    Hi, I am using latest delphi with all patches. Delphi 11 Version 28.0.46141.0937

    When I debug my application by singlestep code with F7 or F8 sooner or later I cannot continue.
    IDE is still responsive but programcounter hang and singlestep code have no effect.

    I have seen this problem before also with previous 10.4.

    Anyone with similar experience ? What can I do as workaround except to restart my application and try again.
    It seems to be completely random...

    Are you working on a 32 or 64 bit target?


  18. 6 hours ago, JohnLM said:

    Windows 7 Home 64bit

    Delphi XE7 Professional update 1 with FireDAC and Mobile add-on

    Indy version 10.6.1.518

    Android devices: (smartphone v10, and tables v4.4.4, and  v4.4.2)

     

    I am having trouble trying to get these projects copied via Save-as and Save-project-as from the IDE, to another version'ized folder. 

     

    When I start a project, I normally create a folder that describes the application name. Then, I create a version folder (i.e., v01, v02, ... v10, and so on) so that I can see the version of that project.  This helps me to keep project apps organized, debugging, etc..

     

    ** My steps are as follows for working with and saving a project into a new version folder: **

    (this is just before I close down Delphi for the project) 

     

    1. open or create a project, E:\XE7\VCL\JasonParser\v01\JasonParser_v01.dproj

    2. do work on that project. If the project is working well, I will quickly determine if that will be the final working version. If I decide, yes, then I will create a new version folder.

     

    ** Create new version folder: ** 

     

    3. Save-as (this saves the unit) thus, save into E:\XE7\VCL\JasonParser\v02\unit1.pas

    4. Save-project-as, thus, save into E:\XE7\VCL\JasonParser\v02\JasonParser_v02.dproj

    5. then, either I shut down Delphi or start a new project via steps 1 through 5.

     

    However, being my first time creating a project-group, I am lost as to how to copy over the whole project to a new version folder so that I can work on the project. 

     

    The issue I am having is that the second project group is not carrying over.  How do I fix this?

     

    With your steps you are not creating a new project group, you just rename the project. If you saved the project group before closing the IDE (the IDE should prompt you to do this) the group should contain the renamed project the next time you open it. To have more than one version in the same project group you have to explicitely add the old version to the group.

    • Like 1

  19. 13 hours ago, alogrep said:

     

    in Tbasicdm.DatamoduleCreate, is there really an underscore in the line after begin? That would be the source of the first error. The second may be a false positive, error insight is easily confused by conditional compilation...


  20. 9 minutes ago, Lainkes said:

    I have a question.
    When I start my program, there is always one of the DBCheckboxes that is active.

    How can I disable that. So that by default no value is selected.

     

    Thanks

    Set the form's ActiveControl property to some other control that can take the focus, e.g. a button.


  21. 1 hour ago, omnibrain said:

    And if I install 11.2 now, I have still to install the patch and do the fix, because there is no updated install file?

    The installer will probably only be updated when (if) a 11.3 release comes out. Just run the installer and then check the IDE about dialog. Mine shows build  28.0.46481.1287 after the patch was installed.


  22. 3 hours ago, Lainkes said:

    Hello,

     

    I have a DBGrid with records.

    On column contains a True of False value.

    Now I want this to be changed into a green icon (True) of red icon (False).

    And when clicking on the icon, it must be changed from T to F or F to T.

    Any idea how I can achieve this?

     

    Thanks

     

    Lainkes

    Handle the OnDrawColumnCell event of the grid, in it call DefaultDrawColumnCell if the cell you are asked to draw is not one in the boolean column, draw the icon on the grid canvas if it is in your special column. The OnCellClick event fires on a mouse click on the cell. The attached dataset's current record is already set to the record shown in the row clicked on, so just change the field value if the click lands on your boolean cell.

    • Like 1
×