Jump to content

Anders Melander

Members
  • Content Count

    2946
  • Joined

  • Last visited

  • Days Won

    166

Everything posted by Anders Melander

  1. The manifest of Delphi 10 and 11+ are probably different so Delphi 10 gets the XP window style, while 11+ gets the current window style. I don't have Delphi 10 installed anymore but if you can post its manifest then we can verify. Apart from that, if you rely on Form.Width/Height this will not only be a problem in the IDE but also at run-time where your application will use whatever windows style the host OS dictate. Use Form.ClientWidth/ClientHeight instead; Then you don't have to worry about the border width.
  2. Anders Melander

    [Resolved] Window State and position saver

    Wasn't rxLib abandoned in the nineties and merged into JEDI?
  3. Anders Melander

    Is it possible to use translucent png in Image List?

    AFAIR this is a bug in TPNGImage. I believe it's already been reported but I could be wrong. What happens (and I'm doing this from memory), when you add a PNG to an imagelist (which as Remy pointed out "supports only BMP and ICO" (more on that later)), is that Delphi load the PNG into a TPNGImage, converts it to a 32-bit TBitmap and then adds that bitmap to the imagelist. The bug is that the bitmap TPNGImage produces is premultiplied (all pixel colors have been multiplied with their alpha; pRGB = RGB * A / 255) while the imagelist expects the bitmap to be not-premultiplied, so to say. The result is that you get a semi-transparent 32-bit RGBA bitmap which is too dark. I believe the premultiply problem can be worked around, in code, but I'm too busy to find the solution right now. With regard to imagelist only supporting BMP and ICO: That doesn't really matter in this case. First, let's forget about the ICO support since that is only relevant if you need icons' ability to contain multiple versions (size/color depth/etc) of the same image. That leaves BMP: The imagelist doesn't really contain BMPs which is a file format. It contains DIBs and in the case of a 32-bit imagelist it contains 32-bit DIBs in RGBA format. It doesn't matter if you add a BMP, PNG, JPEG or PCX to the imagelist. Internally it will just store a DIB representation of the image.
  4. Anders Melander

    Saving files as UTF-8 with BOM

    ...and AFAIR there's a registry option to use UTF-8 without BOM if one wants to make life "more interesting".
  5. Anders Melander

    Is it possible to use translucent png in Image List?

    You've most like setup your imagelist to use masked transparency (which is probably what your icons are using). I think they've done their part with regard to this. Now you just need to do your part and read the documentation: https://docwiki.embarcadero.com/Libraries/Sydney/en/API:Vcl.Controls.TImageList.ColorDepth https://docwiki.embarcadero.com/Libraries/Sydney/en/Vcl.ImgList.TDrawingStyle
  6. Maybe not in this case but when you have lists or arrays of records it is most often much more efficient to pass a pointer around than to copy the records back and forth. I just showed you exactly how it's done. If this is performance sensitive, there are a lot of entries in the list and the records are large, then an alternative is to have the data in one list and an index into the list in another list TList<integer> or array TArray<integer>. Then you use the record list to hold the data and when you need to sort the data you just sort the index list/array. To access the data in sort order you must then use the sorted index list to get the index of the data in the record list. It's very easy but a bit hard to explain without a whiteboard. Anyway, forget about that for now. If you just want to sort the list on different record fields you can do so by passing a custom comparer to the Sort method, as Peter mentioned: type TMyRecord = record Foo: integer; Bar: string; end; TMyList = TList<TMyRecord>; TMyField = (mfFoo, mfBar); procedure SortList(List: TMyList; Field: TMyField); begin var Comparer: IComparer<TMyRecord>; case Field of mfFoo: Comparer := TComparer<TMyRecord>.Construct( function(const A, B: TMyRecord): integer begin Result := (A.Foo - B.Foo); end); mfBar: Comparer := TComparer<TMyRecord>.Construct( function(const A, B: TMyRecord): integer begin Result := CompareText(A.Bar, B.Bar); end); else exit; end; List.Sort(Comparer); end; and to use the above: begin var MyList := TList<TMyRecord>.Create; ...populate the list... // Sort the list on the "Foo" field. SortList(MyList, mfFoo); // Sort the list on the "Bar" field. SortList(MyList, mfBar); ...etc... end;
  7. Works for me, Did you get it from this post: Otherwise, here's the original articles about it (OMG, I really need to get that old site updated): http://melander.dk/articles/alphasplash http://melander.dk/articles/alphasplash2/ and the source for that is here: http://melander.dk/download/ That source was written for Delphi 2007 so it probably won't work as-is in modern Delphi versions.
  8. It's not clear to me what exactly you are doing but you can use TList<T>.List to get access to the internal dynamic array of TList<T>. From there you can create a pointer to the individual elements in the array: type TMyRecord = record Foo: integer; Bar: string; end; PMyRecord = ^TMyRecord; begin var MyList := TList<TMyRecord>.Create; ... // Get a reference to the internal dynamic array. // Note that this reference, and any pointers to the elements in // it, are only valid as long as the list size remains static; // Once you clear the list or add items to it, the references are // stale becuase the internal array can be reallocated. var Items := MyList.List; // Get a pointer to an element in the array var SomeItem: PMyRecord := @Items[0]; // Clear the element SomeItem^ := Default(TMyRecord); // Modify the element SomeItem.Foo := 42; SomeItem.Bar := 'Hello world'; end; I assume your bubble sort is just an example. Otherwise, use TList<T>.Sort to sort the list.
  9. Interesting but... TLDR; the "50x faster" only applies if: You are using the C++17 std::filesystem now. You are using GetFileAttributesEx now to get the attributes. In IOUtils the TFile.GetSize function is the only one using GetFileAttributes* directly. Unfortunately IOUtils defers to SysUtils for many of its function and there's widespread use of GetFileAttributes* in there. Interestingly SysUtils contains an internal GetFileAttributesExEmulated function that is implemented using FindFirstFile but unfortunately that is only used from the FileAge functions and only in case of a sharing violation.
  10. Anders Melander

    What picture formats are supported by TImage ?

    Works for me; The GIFs load and display without problems. It's probably a problem in your code (have you remembered to reset the stream position before load?) but you don't have to pursue it for my sake. I was just curios.
  11. Anders Melander

    What picture formats are supported by TImage ?

    Okay but do you remember what the exception was? - or if you have one of the GIFs I can try for myself. I'm just curious because AFAIK there no known bugs in the GIF reader (and I wrote the original TGIFImage code back in... 1997).
  12. Anders Melander

    What picture formats are supported by TImage ?

    How so?
  13. Anders Melander

    Delphi 12.3 is available

    https://docwiki.embarcadero.com/RADStudio/Athens/en/12_Athens_-_Release_3#Delphi_Debugger I guess I could try it out and see if it could be worked around but since there isn't anything for us in this release I have better things to do.
  14. Anders Melander

    Delphi 12.3 is available

    Wow. It's been while since they released a version with zero improvements that I had, or could find, a need for. It's basically bug fixes + a technology preview IDE that I can't use because it can't debug the VCL. Oh well.
  15. Anders Melander

    [BUG] Mouse wheel no longer scrolls when highlighting

    I use the same finger for LMB and scrolling so it's pretty awkward to do both at the same time. Using the middle finger to scroll totally loses the required motor precision. My mouse do have two scroll-wheels, a regular one and one at the thumb position, but I've only ever used the thumb scroll in games.
  16. Anders Melander

    [Resolved] Window State and position saver

    "that's it" meaning "implicitly include the 347 other units it depends on".
  17. Anders Melander

    [BUG] Mouse wheel no longer scrolls when highlighting

    QP is the only place. These fora are just read by regular mortals like you and me. But... ask yourself if you really want them to use their resources on this issue and if it's likely to be implemented.
  18. Anders Melander

    ElevateDB / ElevateSoft website down and support not reachable

    The site seems to be down https://www.elevatesoft.com/ and Tim has no traffic (for years) on any of the sites I could find where he has an account. No obituary matches on his name/age/location though, so at least there's that. Timothy James Young, 55, New York, FWIW.
  19. Anders Melander

    What picture formats are supported by TImage ?

    > Is this not implied if I use TImage ? TImage is just a control that displays the data of a TPicture (TImage contains a TPicure object), so forget about TImage itself. None of the image formats, except maybe bmp/TBitmap, are "implied" by design. It has just gotten so that using the Graphics unit implicitly pulls in support for a lot of different image formats. But it's not because someone sat down and had deep thoughts about what image formats to support by default and how to do it. It just happened to end up that way because, I guess, there's nobody left at Embarcadero who gives a damn about these things. Not that I think there has ever been anyone there that understood graphics or cared about imaging.
  20. Anders Melander

    [Resolved] Window State and position saver

    This works for me: uses Math; procedure TFormMain.ApplyWindowState(const Bounds: TRect; State: TWindowState); var Monitor: TMonitor; WorkareaRect: TRect; NewTop, NewLeft, NewWidth, NewHeight: integer; begin ASSERT(Position= poDesigned); // Find the monitor containing the top/left corner. // If the point is outside available monitors then the nearest monitor is used. Monitor := Screen.MonitorFromPoint(Bounds.TopLeft); WorkareaRect := Monitor.WorkareaRect; NewHeight := Min(Bounds.Bottom-Bounds.Top, WorkareaRect.Bottom-WorkareaRect.Top); NewWidth := Min(Bounds.Right-Bounds.Left, WorkareaRect.Right-WorkareaRect.Left); if (PtInRect(WorkareaRect, Bounds.TopLeft)) then begin NewTop := Bounds.Top; NewLeft := Bounds.Left; end else begin // Center on monitor if top/left is outside screen (e.g. if a monitor has been // removed) NewTop := WorkareaRect.Top + ((WorkareaRect.Bottom-WorkareaRect.Top) - NewHeight) div 2; NewLeft := WorkareaRect.Left + ((WorkareaRect.Right-WorkareaRect.Left) - NewWidth) div 2; end; SetBounds(NewLeft, NewTop, NewWidth, NewHeight); if (State in [wsNormal, wsMaximized]) then WindowState := State; end; ... procedure TFormMain.FormCreate(Sender: TObject); begin ApplyWindowState(Rect(100, 100, 400, 400), wsMaximized); end;
  21. Anders Melander

    What picture formats are supported by TImage ?

    I should mention that instead of relying on WIC, which is a library external to Delphi and thus outside your control, it would be better if you explicitly included/declared the image formats you want supported. For example, include the pngimage unit for PNG support, the jpeg unit for JPEG support, etc. I would also unregister the TWICImage class (see UnregisterFileFormat) as support for all the formats it support might not be a good thing. All the formats will just confuse your users.
  22. Anders Melander

    What picture formats are supported by TImage ?

    The image formats that are missing on your "older OS" are the ones supplied by WIC (via the TWICImage class). TImage, or more precise TPicture, relies on different TGraphic implementations for image format support. The image formats you get by default, whether you like them or not, are the ones registered in the Graphics unit. Image formats are registered with TPicture.RegisterFileFormat and can be unregistered with TPicture.UnregisterFileFormat. The list of registered image formats is internal (private in the Graphics unit) and Embarcadero, in their infinite wisdom, has not provided us with any means of accessing or enumerating the list so the only info you can get about registered image formats are filename masks. See the TGraphic and TPicture documentation for more info.
  23. OP: Unambiguous question about the behavior of X A: Here's some code that does something similar but doesn't answer your question. OP: Okay but what about my question about the behavior of X A: Here's some data that also doesn't answer the question. OP: Thanks but... B: Have you tried <something else> instead? OP: *flips desk* 🙂 Apart from that, https://www.scientificamerican.com/article/time-s-passage-is-probably-an-illusion/ But seriously, ignore the help. It's obviously not up to date. The behavior of Now is never going to change to match the help because that would break a lot of code and nobody needs it to have 1 second resolution. Even in Delphi 1 (which implemented Now as Date (and Time via the DOS INT 21h, function 2Ch (which had 10 mS resolution))) the resolution was better than 1 second. I too would go for TStopWatch - even if you don't need the precision.
  24. Anders Melander

    [BUG] Mouse wheel no longer scrolls when highlighting

    It's not like I never use the mouse when coding (Ctrl+Click) but I find it much more efficient to use the keyboard as much as possible instead of switching back and forth. Selection is probably one of the things I would very rarely use the mouse for. I guess I would do word selection using Ctrl+arrow to move, Ctrl+Shift+arrow to select. etc. Place the caret using normal arrow navigation. Shift+up/down for selection, etc. It's not really something I think about but the fact that I didn't know that mouse-scroll.selection didn't work tells me that it isn't something that I have tried or something that I need. Anyway, we each have our own usage patterns. There's no right or wrong.
×