Jump to content

luebbe

Members
  • Content Count

    119
  • Joined

  • Last visited

Posts posted by luebbe


  1. Thanks Stefan,

    in the debugger I saw in ItemCallback(..) that the addresses of FItem and AItem were similar but not equal, so I suspected that there was something wrong with the interface being passed around instead of the object.

     

    I put a breakpoint on the first line of

    procedure TestIntfItem.ItemCallback(AItem: IMyIntfItem);
    begin
      Assert.IsNotNull(AItem);
      FCallbackResult := AItem.Caption;
    end;
    
    

    with TOnMyIntfItemSelected<T: IMyIntfItem> = procedure(AItem: T) of object; I see:

    Name    Wert
    Self    (TMyIntfItemA<List.Intf.IMyIntfItem>($3AA2840) as IMyIntfItem, '')
    AItem    Pointer($3AA2828) as IMyIntfItem
    

    This told me that something was wrong, but I couldn't understand what.

     

    with TOnMyIntfItemSelected<T: IMyIntfItem> = procedure(AItem: IMyIntfItem) of object; I see:

    Name    Wert
    Self    (TMyIntfItemA<List.Intf.IMyIntfItem>($3AC38D8) as IMyIntfItem, '')
    AItem    TMyIntfItemA<List.Intf.IMyIntfItem>($3AC38D8) as IMyIntfItem
    

    That's an evil trap. Thanks for shedding light on it. So if something is wrong I have to watch out for $18 byte address offsets 😉


  2. Back from vacation...

    Thanks for further feedback, I probably oversimplified the interface in order to produce a minimal example. In fact I do have stuff in the interface. The attached project contains two different implementations, one interface based and one skeleton based, with a few unit tests.
    You need TestInsight installed and the path to DUnitX in the $(DUNITX) variable to run it.
    I needed a callback for a list item (selection) and for the list itself (changed). The skeleton based implementation works as expected, but the interface based callback for the list item fails with an A/V and I don't understand why. I'm probably still doing something wrong with the generic definition.
    Could someone please enlighten me what my mistake is?

    Project4.zip


  3. I think the skeleton is what I'm heading towards.

     

    Next question. How can I implement a callback with the list itself? I tried different variations, but this is as far as I can get.


     

    type
      IMyIntf = interface;
      TMyList<T: IMyIntf> = class;
    
      TOnListItemSelected = procedure(AItem: IMyIntf) of object;
      TOnListUpdated = procedure(AList: TMyList<IMyIntf>) of object;
    
      IMyIntf = interface
        ['{FCAFF2E8-5F8E-4473-8795-89BD41C89D57}']
      end;
    
      TMyList<T: IMyIntf> = class
        FItems: TList<T>;
        FOnListUpdated: TOnListUpdated;
        procedure ListUpdated;
      end;
    { TMyList<T> }procedure TMyList<T>.ListUpdated;
    
    begin
      if Assigned(FOnListUpdated) then
        FOnListUpdated(Self);  // E2010 Inkompatible Typen: 'Project4.TMyList<Project4.IMyIntf>' und 'Project4.TMyList<Project4.TMyList<T>.T>'
    end;
    

     


  4. Hi Folks,

     

    I'm banging my head against the wall trying to understand, why the compiler throws "E2008 Incompatible Types" errors at the marked lines. I must be missing something completely... :classic_unsure:

     


     

    program Project4;
    
    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    
    uses
      System.Generics.Collections,
      System.SysUtils;
    
    type
      IMyIntf = interface
        ['{FCAFF2E8-5F8E-4473-8795-89BD41C89D57}']
      end;
    
      TMyList<IMyIntf> = class
        FItems: TList<IMyIntf>;
        procedure AddItem(AItem: IMyIntf);
        function GetItem: IMyIntf;
      end;
    
      TMyType = class
      end;
    
      TMyTypeList<TMyType> = class
        FItems: TList<TMyType>;
        procedure AddItem(AItem: TMyType);
        function GetItem: TMyType;
      end;
    
    { TMyList<IMyIntf> }
    
    procedure TMyList<IMyIntf>.AddItem(AItem: IMyIntf);
    var
      Value: IMyIntf;
    begin
      FItems.Add(AItem); // E2008 Incompatible Types
      FItems.Add(Value); // Compiler is happy
    end;
    
    function TMyList<IMyIntf>.GetItem: IMyIntf;
    begin
      Result := FItems[0]; // E2008 Incompatible Types
    end;
    
    { TMyTypeList<TMyType> }
    
    procedure TMyTypeList<TMyType>.AddItem(AItem: TMyType);
    var
      Value: TMyType;
    begin
      FItems.Add(AItem); // E2008 Incompatible Types
      FItems.Add(Value); // Compiler is happy
    end;
    
    function TMyTypeList<TMyType>.GetItem: TMyType;
    begin
      Result := FItems[0]; // E2008 Incompatible Types
    end;
    
    begin
      try
        { TODO -oUser -cConsole Main : Code hier einfügen }
      except
        on E: Exception do
          Writeln(E.ClassName, ': ', E.Message);
      end;
    
    end.
    

     

    • Like 1

  5. 13 minutes ago, Joe Sansalone said:

    Hi,

    I've encountered something weird.  Delphi 10.4.2

    I loop through the items in a list.

    But also may add to that list in the loop.

    Thus, extend the loop iterations.

    Ouch. Are you sure you want to do this? How are you going to ensure that your loop terminates when you keep adding items inside the loop?

     

    Consider

    list.count-1

    to be a constant while the loop is executed. This ensures termination.
    If you really want to change the list content while iterating over the list, use a while loop and ensure termination yourself.


  6. Yes, immediately reproducible on my home PC

     

    Screen layout:

    image.png.cf410c88b4c911629b95642ef115b54a.png

     

    Monitor 1: 1920x1080 (24")

    Monitor 2: 2560x1440 (27")

     

    When both monitors align at the top, everything is fine.

     

    This is also sufficient.

    image.png.07af4102c7eefbf52febbade5a9e176f.png

     

    You have to toggle the app between normal and maximized mode after you change the screen alignment. If you leave the app maximized while changing the screen alignment, everything will stay ok.


  7. Sorry for the late reply. It was a very busy week.

     

    Monitor 1: 1920x1080 (??" Laptop screen)

    Monitor 2: 2560x1440 (27")

    Both set to 100% font scaling

     

    It also happens on my desktop PC at work, which has two 24" monitors with different resolutions

    Monitor 1: 2560x1440 (24")

    Monitor 2: 1920x1080 (24")

    Both set to 100% font scaling

    They have a slight vertical offset IIRC (working from home, desktop is in the office)

     

    May be driver antics, but our IT department keeps everything as up-to-date as possible.

     

    I'll compile it with the community edition on my home PC and try what happens there.


  8. I was half fearing @lars' answer :)
    Thanks to @dwrbudr for confirming it.

     

    This is my monitor setup with (1) being the laptop monitor as secondary screen and (2) the desktop monitor as primary screen.

    image.thumb.png.39adca32b891edc7534acd1c83015bd9.png


  9. I didn't touch anything knowingly in the manifest. Just dropped a menu on the form and activated a VCL style.

    The minimal app has "per monitor v2"

    Our standard app has "none"

    So I guess it doesn't have anything to do with dpi awareness?


  10. Hi Folks,

     

    I have a strange bug when a VCL styled application is maximized in a dual monitor configuration.

     

    Steps to reproduce:

    1. Set your windows task bar position to "top"

    2. Create a minimal application and activate a VCL style (add a main menu if you like)

    3. Run the application and:

       * maximize it on the primary monitor (fine)

       * maximize it on the secondary monitor (The top part of the application, probably the height of the windows task bar, becomes transparent)

     

    image.png.e31a4c7c4e2f5ab4ff4584e2749209cd.pngimage.png.cfbf9f86cad7acdccfeb4ddee2ac9cb1.png

     

    left: maximized on primary monitor

    right: maximized on secondary monitor

     

    Additional Info:

    * My two monitors have different resolutions and they have a vertical offset

    * This bug doesn't seem to affect many people (no customer has reported it so far ;-))

    * This is not a new bug. I've seen for years (three to four) it in several Delphi versions, but I can't put a date on it

     

    Today I tried to find out if it is a problem with our main form's settings, but since it also happens with a minimal application, it probably isn't.

    Has anybody encountered this as well?

    Does anyone know how to fix it?

    Do I have to wait for Emba to fix it?

     

    Cheers & thanks

    Lübbe

     


  11. Thanks for the pointers. In the end I solved it by searching and copy/pasting the code snippets that I needed to compare into a diff tool.
    You're right Uwe, but I didn't need working code. I just needed something which is easy to compare :)


  12. Hi Folks,

     

    I am trying to compare two huge .pas files created by the xml data binding wizard from two different xsd files. Each xsd file represents a different version of the same standard. Now I'd like to spot the differences in the created .pas files. Unfortunately the order in which the classes are created are so different, that I see 99% diffs.

    So I thought: MMX Code Explorer has some sort functions. I'll sort the interface and implementation parts of both files alphabetically and compare the result. Up to now I only managed to sort inside classes.

    I set the two options in "Default class sorting" to "Unsorted and in "Default Mode procedure sorting" to "Name". Then I tried my luck with "Default sort classes and module" from the MMX window, but it had no visible effect on the sources. I can sort stuff inside the classes by changing the options in "Default class sorting", but that's not what I want.

    How can I sort a .pas file alphabetically in the interface by class name and in the implementation section by class name and method name?

     

    MMX version 15.0.38.2440

×