Jump to content

Jacek Laskowski

Members
  • Content Count

    267
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by Jacek Laskowski


  1. On 4/17/2020 at 1:31 PM, A.M. Hoornweg said:

    You shouldn't, because the component's owner manages its lifetime.  Refcounted objects do not have an owner, they manage their own lifetime. Freeing an object twice is a really bad idea.

    Very common, basically always, used database classes like TDataset, etc. I create in runtime, they are for example part of business classes, as "Owner" I give them nil. There I would like to use them in the interface model, not in the VCL management model.


  2. How to set the generic class field to the value provided by Variant?

     

    The following code is not compiled.

      ToField<T> = class
      private
        fData : T;
      protected
        procedure SetFromVariant<T>(const aValue : Variant);
    
     [...]
    
    
    procedure ToField<T>.SetFromVariant<T>(const aValue : Variant);
    var
      val: TValue;
    begin
      val := TValue.FromVariant(aValue);
      fData := val.AsType<T>; <=== [dcc32 Error] E2008 Incompatible types

    [dcc32 Error] E2008 Incompatible types

     


  3. 1 hour ago, Darian Miller said:

    I imagine it could certainly happen - but I haven't witnessed that I recall in any debugging session using this type of code over quite a few years. 

     

    Do you have knowledge of all native threads created and what they are used for? 

    Unfortunatelly I don't.

     

    When it comes to the order of starting the "initialization" section it's not always the same, it all depends on the uses section, in my case your code is launched before RTL/VCL threads.
    I bypassed this problem by adding a anonymous thread with delay:

    procedure NameDelphiThreads(const pMainThreadId : THandle);
    begin
      TThread.CreateAnonymousThread(
                                    procedure
                                    var
                                      vSnapshot:THandle;
                                      vProcessId:THandle;
                                      vTE32:TThreadEntry32;
                                      i:Integer;
                                    begin
                                      Sleep(100);
                                      vProcessId := GetCurrentProcessId();
                                      vSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, vProcessId);
                                      if vSnapshot <> INVALID_HANDLE_VALUE then
                                      begin
                                        [...]
                                      end; 
                                    end
      ).Start;
    end;

     

    • Like 1

  4. I got a Chad Z. Hower article:

     

    https://www.codeproject.com/Articles/1252175/Fixing-Delphis-Interface-Limitations

     

    The author is very critical about the interfaces in Delphi. But he gives examples where he mixes interface and object access, which is doomed to failure in advance.
    I use interfaces very much, and I don't agree with the statement that there is more trouble with them than good.
    I don't know e.g. C++ and I don't know how interfaces are solved there, probably my ignorance limits my understanding of the problem. Can someone enlighten me if the interfaces in Delphi are really that badly done?

     


  5. 10 hours ago, David Schwartz said:

    Aside from the tags that cannot be replaced, and the text that you want displayed, I'm not sure what you can remove. It's not like javascript where you can change all of the variable names to 2- or 3-letter codes and remove most of the white space.

     

    What do you imagine can be compressed out? 

    You can:
    - delete end of lines (CR, CRLF)

    - delete spaces between fields in css: style="color: white; border: 5px" => style="color:white;border:5px"
    - delete all spaces and tabs of which there is more than one next to each other (except the <pre></pre> tag)
    - if the styles are defined within HTML in <style type="text/css"> then all long style names like bold_red_important_text can be replaced by short names


  6. 20 minutes ago, Alexander Sviridenkov said:

    @Jacek Laskowski, no, only duplicated attributes are removed automatically. Library doesn't know do you need alt="nothing" attribute or not, you should decode this yourself.

    Duplicated CSS properties can be removed by one line code, but this is not done automatically too, because by default (if there was no style changes) style attribute remains unchanged. 

     

    I know that the attribute will not be removed because the library does not know that it is unnecessary.
    But notice that in the example I gave you, the alt="nothing" attribute appears twice in one tag! 

    This is an example of ugly, junk HTML code that I have to clean up. I would like to do it as automatically as possible, because manual work is very tedious.
    I imagined that your parser could make it easier for me.


  7. On 3/28/2020 at 11:29 AM, Alexander Sviridenkov said:

    Yes, this is possible. Simply iterate DOM after parsing (use Count and Elements or NextElement), remove all unecessary attributes and tags and use Document,OuterHTML to get HTML string.

    But I mean AUTOMATIC removal of duplicate or unnecessary attributes by library. That's what I'm asking.

    A library that parses HTML and CSS and creates object-oriented structure (DOM) does it automatically, right?


  8. I have one question, is it possible to optimize HTML and CSS code with your library, i.e. remove unnecessary attributes?
    For example, I have a code:

    <img src="logo.jpg" alt="nothing" style="color: white; border: 50px; color: black" alt="nothing" ><div>

    This tag has an unnecessary attribute alt="nothing" and one of the CSS attributes: "color: white" because both are overwritten.


    To remove such redundant attributes you would need to parse HTML and CSS (what your library does) and build HTML and CSS from the metadata again.

     

    Is this possible in the HTML Library?

     


  9. I need to enable preUnGreedy option in TRegEx, PCRE supports this parameter:

     

    unit System.RegularExpressionsCore;
    
    interface
    [...]
    
    type
      TPerlRegExOptions = set of (
        preCaseLess,       // /i -> Case insensitive
        preMultiLine,      // /m -> ^ and $ also match before/after a newline, not just at the beginning and the end of the string
        preSingleLine,     // /s -> Dot matches any character, including \n (newline). Otherwise, it matches anything except \n
        preExtended,       // /x -> Allow regex to contain extra whitespace, newlines and Perl-style comments, all of which will be filtered out
        preAnchored,       // /A -> Successful match can only occur at the start of the subject or right after the previous match
        preUnGreedy,       // Repeat operators (+, *, ?) are not greedy by default (i.e. they try to match the minimum number of characters instead of the maximum)
        preNoAutoCapture   // (group) is a non-capturing group; only named groups capture
      );
    

    But the PCRE parameters are set by mapping:

    constructor TRegEx.Create(const Pattern: string; Options: TRegExOptions);
    begin
      FOptions := Options;
      FRegEx := TPerlRegEx.Create;
      FRegEx.Options := RegExOptionsToPCREOptions(FOptions);   <--- mapping PCRE params to Delphi TRegEx
      if (roNotEmpty in Options) then
        FRegEx.State := [preNotEmpty];
      FRegEx.RegEx := Pattern;
      FNotifier := TScopeExitNotifier.Create(FRegEx);
      if (roCompiled in FOptions) then
        FRegEx.Compile;
    end;

    And for a reason unknown to me, this parameter was omitted:
     

    function RegExOptionsToPCREOptions(Value: TRegExOptions): TPerlRegExOptions;
    begin
      Result := [];
      if (roIgnoreCase in Value) then
        Include(Result, preCaseLess);
      if (roMultiLine in Value) then
        Include(Result, preMultiLine);
      if (roExplicitCapture in Value) then
        Include(Result, preNoAutoCapture);
      if roSingleLine in Value then
        Include(Result, preSingleLine);
      if (roIgnorePatternSpace in Value) then
        Include(Result, preExtended);
    end;

    Bug?

     

    Is there any way to solve this?

     

    Delphi 10.3

     


  10. I have a strange problem with FireDAC (Delphi 10.3.2)


    I create TFDMemTable dynamically, then I create its structure and index on base key (by memTable.Indexes.Add()).
    Next, I import data from JSON file (saved previously by TFDQuery object):

     

    memTable.LoadFromStream(x, sfJSON);

     

    AV is raised in this FD code:

     

    procedure TFDDatSView.RemRef;
    begin
      FRefs.RemRef;
    end;
    

    And on this import I get access violation in FireDAC code, because internal TFDDatSView field is nil (see attached screenshot)!

     

    When I remove the creation of the index there is no error. But I can't do it, because it's part of a big, generic mechanism and it's needed.

     

    The index is created when MemTable is in dsInactive mode, can it be the cause?

    I also noticed that when I do Open/Close this MemTable, there is no error either.


    What is the cause and how to avoid it without performing spells (like close/open)?

     

    vps_2020.03.12_02.png


  11. I noticed one regression in the last beta version of MMX. When I add a local variable via ctrl+L the default text is not selected in the "Type name" field. So when I start typed the new text, the new one sticks to the old one and the stupidity comes out 🙂

×