Creating a new component by combining two controls (TEdit and TTrackBar) in Delphi VCL

I am developing a Delphi 10.1 VCL application for Windows.

To enter integer or float, I need a number input field, which is associated with the slider. When the user changes the number in the input field, the position of the slider changes accordingly. When the user changes the position of the slider, the number in the number field is updated.

I can solve this with TEdit and TTrackBar and add the necessary update functions to my OnChange event handlers.

enter image description here

The problem is that I need a lot of such inputs for different forms. Therefore, I would like to create a new component that combines the two TEdit and TTrackBar controls in one component.

  • Is creating a new component the best strategy for reusing such input slider?

  • What is the best way to create such a new component?

+6
source share
3 answers

Is creating a new component a better strategy for reusing such contributions from the slider?

Not necessarily true all the time. (at least by my standards).

What is the best way to create such a new component?

I know three ways to solve your problem.

Way number 1:

create a master component via the new components, where you dynamically create subcomponents Teditand Ttrackbarin a stream Tgroupbox.

as follows I will do it.

unit Combindedittrack;

interface

uses
  System.SysUtils, System.Classes, Vcl.Controls, Vcl.comctrls ,Vcl.StdCtrls;

type
  TCombindedittrack = class(Tgroupbox)
  private
    { Private declarations }
    Fedit:tedit;
    Ftrackbar: TTrackBar;
    procedure editonchangeproc(Sender: TObject);
    procedure trackbaroOnchange(Sender: TObject);
  protected
    { Protected declarations }

  public
    { Public declarations }
    constructor Create(owner:tcomponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TCombindedittrack]);
end;

constructor TCombindedittrack.Create(owner:tcomponent);
begin
inherited Create(owner);
SetBounds(0, 0, 250, 50);
Fedit:=tedit.Create(self);
with Fedit do
  begin
  text := '';  //<-- you control the appearence here
  top := 10;
  left := 10;
  height := 27;
  width := 50;
  parent:=self;
  Onchange:=editonchangeproc; // your Onchange event handler for the Tedit
  end;

Ftrackbar:=ttrackbar.Create(self);
with Ftrackbar do
  begin
  top := 10;  //<-- you control the appearence here
  left := 60;
  height := 30;
  width := 50;
  parent:=self;
  Onchange:=trackbaronchangeproc;  // your Onchange event handler for the Ttrackbar
  end;
end;

destructor TCombindedittrack.Destroy;
begin
Ftrackbar.Free;
Fedit.Free;
inherited;
end;

procedure TCombindedittrack.trackbaroOnchange(Sender: TObject);
begin
// <-- track bar onchange handling here.
end;

procedure TCombindedittrack.editonchangeproc(Sender: TObject);
begin
// <-- edit onchange handling here.
end;

end.

Way number 2:

Use these frames (I'm on a 10 seattle dolphin).

1) → → → ( delphi).

2) Onchange.

3) .

4) ( ) .

5) .

, .

№ 3:

( delphi 10 )

1) Tedit Ttrackbar.

2) "" " ".

3) OK.

4) Template, .

, () .

, delphi IDE, , , , .


:. , , . , .

,

1. (), ( ).

2. , ( ,    ).

3. .

4. .

, .

№ 1:

C1 ( № 1): , / . 3.

C2: , 5 , , delphi. , - , , (. C1)

C3: (-) , , (, Tedit ).

C4: , , , Flatstyle Indy. - , , .

№ 2:

C1: 1, , . , .

Onchange

procedure TForm1.Frame2Edit1Change(Sender: TObject);
begin
  Frame2.Edit1Change(Sender); //<-- this is the original onchange event you setup at the beginning 
  //<-- you can extra handling here if you want one of the replicas to behave differently than the original  
end;

C2: , , , 1.

C3: , , 1.

C4:, 1, , A B. , A.

3:.

1: , repleca/macro , . , .

C2: , , , 1.

C3: , , ( , ).

C4: , A B. , A, B (. c1) , B ( , ).

: , . . 1 , . .

, 1 , , . , , , ( , Tedit , , , ).

, , 1, .

+7

, , , . ccpack .

https://sourceforge.net/projects/ccpack/

Custom Containers Pack (CCPack) - - ( "" ) (, ). ActiveForm Frame create, VCL. .

+4

, . , ( Nasreddine number 1). .

Here is a question that shows how to register a frame: How to improve the use of Delphi frames

0
source

All Articles