Question about TCaption-Ttranslation strings used to ColorListBox and ColorBox lazarus / 31-LCL ---------------------------------------------------------------------- jamie · 2021-07-08 15:46 I am in the process of submitting a patch for the ColorListbox and colorBox to benefit from the recent change to the TColorDialog where as you can now set the Caption display..  I have added a property "DialogTitle" for these controls so if not empty the color dialog for custom colors will use this value instead of the default string in the title bar.  My Question:     Property DialogTitle:TCaption……  I expect this to be a translation type, is this the proper define to use in this case ? ---------------------------------------------------------------------- Bart · 2021-07-08 15:57 I would guess TTranslateString (like the Title property of TColorDialog). Don't forget to initialize it to rsSelectcolorTitle. Bart ---------------------------------------------------------------------- jamie · 2021-07-08 16:10 Ok, I can use the Ttranslation directly but as for the setting of the property I was going to leave that empty so that if not set it would use what the TColorDialog already has which is the rsSelectColorTitle and it does display 'Select Color' that way.  Unless you see something I don't, I don't see a need to set the property for the colorbox and listbox controls?   currently I test for any valid string there, if empty then I just allow the dialog use what it has. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   with TColorDialog.Create(Self) do  begin    if FDialogTitle <> '' Then     Title := fDialogTitle;         This is what I am doing now.. ---------------------------------------------------------------------- lucamar · 2021-07-08 16:20 Quote from: Bart on July 08, 2021, 05:57:28 pmI would guess TTranslateString (like the Title property of TColorDialog). TCaption is derived from TTranslateString so it's the correct type for a "caption" property. Quote from: jamie on July 08, 2021, 06:10:35 pm[...]I was going to leave that empty so that if not set it would use what the TColorDialog already has which is the rsSelectColorTitle and it does display 'Select Color' that way. [...] Yes, IMHO that is the correct way to deal with it. Just remember to set it to the empty string on creation ... as a precaution, if nothing else, even though as a managed type it should be auto-initialized. ---------------------------------------------------------------------- Bart · 2021-07-08 16:21 That should work as well, since TColorDialog.Create initializes the Title anyway. It would however be inconsistent with the behaviour in the IDE (OI) of the Title property of TColorDialog: this is always initialized to it's default value rsSelectcolorTitle. Bart ---------------------------------------------------------------------- jamie · 2021-07-08 16:33 The idea as for the colorbox, colorlistbox is to leave this field empty for optional use.  The colordialog's defines this field already so there is no need, I simply test for existence of a string there. etc.. I am trying to take the simplest approach with minimum overhead.  I've just did a test run and it seems ok.  I am doing this with my local copy atm so haven't yet applied this to the trunk.. ---------------------------------------------------------------------- jamie · 2021-07-08 16:46 I think I have a better solution and its in the naming of the property.. Instead of "DialogTitle" I can call it "AltDialogTitle" ---------------------------------------------------------------------- Bart · 2021-07-08 16:49 I would think that DialogTitle or ColorDialogTitle would be better. Another idea: ColorButton exposes the TColorDialog it uses. Why not the same approch for these 2 controls? Bart ---------------------------------------------------------------------- jamie · 2021-07-08 17:03 Yes. I saw that. and yes it could also be done, too. I can shift my strategy over to that instead. So I guess maybe that would be a better idea, with that one could assign a descendant of a TcolorDialog ---------------------------------------------------------------------- jamie · 2021-07-08 18:00 ok, its completed.. I now have ColorDialog properties in both the ColorBox and ColorListBox and it works like charm, that's with the IDE rebuilt and I tested all other features in the IDE that looks like is using those controls, just a guess with that. I did this with my local copy, the COLORBOX.PAS file.. I need to do this now on the PC that has the trunk on it to create a patch unless someone would like to see this file here ? ---------------------------------------------------------------------- jamie · 2021-07-08 19:54 Quote from: Bart on July 08, 2021, 06:49:26 pmI would think that DialogTitle or ColorDialogTitle would be better. Another idea: ColorButton exposes the TColorDialog it uses. Why not the same approch for these 2 controls? Bart The colorbutton does not actually expose the internal, what it does is allows you to use an external colordialog and does so by testing the field for Nil and if it is nil it will create an internal instance using the same property internally and free's it afterwards. If an external dialog is attached via that property then it simply uses that one instead and does not free it. So it has to be a valid external colordialog.  But this allows you to do just about anything you want with the external dialog and the controls will now use it instead of creating a internal default one.  I haven't got to the patch yet, but getting ready to create it.. ---------------------------------------------------------------------- jamie · 2021-07-08 20:41 Ok 0039189 at the bug site. Patch is in. now it needs to be applied to trunk ---------------------------------------------------------------------- Bart · 2021-07-09 08:31 You posted it in Lazarus-CCR section, I move it to Lazarus  Bart ---------------------------------------------------------------------- wp · 2021-07-09 09:36 A bit off-topic, but related: The external ColorDialog is still a TColorDialog. What if I want to show a completely new colordialog, such as the one with the color hexagon of Office97? Or one of the mbColorLib (https://wiki.lazarus.freepascal.org/mbColorLib)? This is not possible because the type of the external ColorDialog is TColorDialog. I think we should extend the color dialog architecture by a TBasicColorDialog (=class TCommonDialog) which is kind of abstract and provides only the basic properties (or introduce a corresponding interface), and TColorDialog descends from TBasicColorDialog, and the ColorDialog of TColorBox and TColorListbox should be a TBasicColorDialog. I did not think through every detail of this idea, but it would be great to have more flexibility. ---------------------------------------------------------------------- jamie · 2021-07-09 10:46 Quote from: Bart on July 09, 2021, 10:31:54 amYou posted it in Lazarus-CCR section, I move it to Lazarus  Bart Thanks @bart, I slipped up. @Wp.  You're welcome to do this, I love enhancements that have worth !  Btw, the patch I summited went through but please, make changes on that if you wish to allow more flexibility !  P.S.    I got thinking about that, if you place a base structure like that in there then it needs to supply at least the colors property for these controls to function..    The color dialog has features to adjust the display for different options. The LCL fully expands it currently but I don't see much of an issue if you were to design another dialog that is based from the color dialog? ---------------------------------------------------------------------- jamie · 2021-07-09 11:52 Here is an example of redirecting the EXECUTE function to use a different Dialog.. Placed here is just code example of going to the existing dialog but you can see how its possible to direct it to something else and define the color properties of the original dialog box on EXECUTE exit. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ColorBox; type  TMyColorDialog = Class(TColorDialog)    Public    Function  Execute:Boolean override;  End;   { TForm1 }   TForm1 = class(TForm)    ColorListBox1: TColorListBox;    procedure FormCreate(Sender: TObject);  private   public    MyDialog:TMyColorDialog;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  MyDialog := TMyColorDialog.Create(Self); {Note :Enable the custom options in the ColorListBox}  Colorlistbox1.ColorDialog := MyDialog;end; Function TMyColorDialog.Execute:Boolean; Begin   Beep;   Title := 'Eddy Lives';   Result := Inherited; {Call this for now as a demo, other wise call a different dialog box } end;                   {and populate the COLORS property etc..} end.    You need the Trunk of course for color box and listbox . ---------------------------------------------------------------------- jamie · 2021-07-09 17:44 I just made up a simple Color dialog as a concept idea of how to use the TcolorDialog as the base and keep things happy with the rest of the LCL  here I can design the complete color dialog with the OI if I wish and call it anytime anywhere to my liking !..  you will notice I assign it to an existing control that expects a TColorDialog but works just as well.  enjoy..    Make sure you select the CUSTOM color in the ListBox so the dialog will open. ---------------------------------------------------------------------- wp · 2021-07-09 19:09 The problem with deriving from TColorDialog is that you have all the internals of this class on board, e.g. the widgetset architecture ( well- maybe this cannot be avoided), but there are also the CustomColors which are ignored in your special dialog. Inheriting from TColorDialog means that you must implement also the CustomColors although you don't want them for some reason. ---------------------------------------------------------------------- jamie · 2021-07-09 19:34 All of that can be retrieved in that example. Its all there. So if you want to bring the custom colors out on a new form you can.. I just didn't do it.. That was just an example of how to do the basics. Nothing has to be changed this way and its a good thing the  EXECUTE function was a virtual one so that it could be overridden.  Also, this method allows you to have a property to choose if you want the custom dialog or still use the original.  You can even go as far as offering several different dialogs with that method..  I can extend the demo to show the custom colors if you wish.. But I am sure you can do that too.. So I don't think I need to do that.. ---------------------------------------------------------------------- wp · 2021-07-09 21:17 Quote from: Bart on July 09, 2021, 10:50:30 pmIn Jamie's patch: FColorDialog: TCommonDialog? This way you can assign it a TColorDialog, a TColorDialog derivative, or any other custom dialog (derived from TCommonDialog)? No, it inherits from TColorDialog. TCommonDialog is too general, it does not have the Color property needed by the TColorListbox and the TColorBox. My first thought was of an intermediate, abstract class, something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TBasicColordialog = class(TCommonDialog)  protected    function GetColor: TColor; virtual; abstract;    protected SetColor(const AValue: TColor); virtual; abstract;  public    property Color: TColor read GetColor write SetColor;  end;   TColorDialog = class(TBasicColorDialog)  private    FColor: TColor;  ...  protected  function GetColor: TColor; override;                // Result := FColor;    procedure SetColor(const AValue: TColor); override;   // FColor := AValue;    ...  published    property Color;  end;   TColorListbox = class(....)  private    FColorDialog: TBasicColorDialog;    ...  published    property ColorDialog: TBasicColorDialog read FColorDialog write FColorDialog;    ...  end;  That's one possibility. What I don't like is that the color dialog still must derive from TCommonDialog. There is no way to hook in the mbColorLib color dialogs or any other third-party color dialogs without changing their code - the TmbOfficeColorDialog, for example, inherits from TComponent directly. But isn't this what interfaces are good for? Unfortunately I am not very experienced with them. My question to the experienced users here: When the ColorDialog property of, e.g., TColorListbox inherits only from TComponent, is there some trick with interfaces so that it can be used by TColorListbox? ---------------------------------------------------------------------- Bart · 2021-07-09 21:32 Quote from: wp on July 09, 2021, 11:17:41 pmTCommonDialog is too general, it does not have the Color property needed by the TColorListbox and the TColorBox. I realized this almost immediately after I posted it  Since I saw no reply I deleted that post. Obviously you were typing a reply at that moment. Bart ---------------------------------------------------------------------- jamie · 2021-07-10 00:00 QuoteNo, it inherits from TColorDialog. TCommonDialog is too general, it does not have the Color property needed by the TColorListbox and the TColorBox. My first thought was of an intermediate, abstract class, something like this:  You are beating yourself up in trying to reduce that..  The color property is generally the property most software goes for.  Have fun   P.S.   The TCOLORBUTTON on the Misc tab also uses the TColorDialog option, too and that too references the COLOR property.