Search code examples
delphijvcl

Accessing an individual digit in a JVSegmentedLEDDisplay control in Delphi


I have a TJVSegmentedLEDDisplay control (from the JVCL) that I want to use as a timer. Accordingly, it has five places, two for hours, two for the minutes, and a colon between the two numbers (i.e. 12:34). After hours of experimenting and searching, I still cannot figure out how to access each individual digit programmatically. It seems to me that it should be something like:

LEDControl.Digits[Index].Text

...but, obviously, it's not.

Any thoughts ?


Solution

  • The TJvCustomSegmentedLEDDigit.Text property, which you have tried to access is protected by a mistake I'd say, since then except direct modifying of the Text property, which is not much comfortable for this I couldn't find a way how to change the individual segment values. However, you can workaround this protected access e.g. by an interposer class:

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, JvExControls, JvSegmentedLEDDisplay;
    
    type
      TLEDDigit = class(JvSegmentedLEDDisplay.TJvCustomSegmentedLEDDigit);
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        JvSegmentedLEDDisplay1: TJvSegmentedLEDDisplay;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      TLEDDigit(JvSegmentedLEDDisplay1.Digits[0]).Text := '1';
      TLEDDigit(JvSegmentedLEDDisplay1.Digits[1]).Text := '2';
    end;
    
    end.