Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-03

Is there aTDBLabel?

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Frans

Hi

I use Lazarus 1.6 on Windows 7.
I've used lazdatadesktop to change the Displaylabel of the DB fields. In a DBGrid that new names popup as the column names. But in a form with TDBEdit fields I can't use a TDBLabel that automatically takes the name from the associated Control as the caption. Instead, I placed TLabel components and made the following method:

procedure TMyForm.FormShow(Sender: TObject);
var
   l: TLabel;
begin
   for TComponent(l) in Self do
   begin
     if (l is TLabel) and (l.FocusControl is TDBEdit) then
       l.Caption := TDBEdit(l.FocusControl).Field.DisplayLabel;
     if (l is TLabel) and (l.FocusControl is TDBLookupComboBox) then
       l.Caption := TDBLookupComboBox(l.FocusControl).Field.DisplayLabel;
   end;
end;

It works. But still I wonder, is there a another way? I've tried TDBText but that shows th field value, not the DisplayLabel.

mvg Frans van Leeuwen M 06-51695390

Reply by email

Michael Van Canneyt
to Frans
Frans wrote 24 lines
Hi I use Lazarus 1.6 on Windows 7. I've used lazdatadesktop to change the Displaylabel of the DB fields. In a DBGrid that new names popup as the column names. But in a form with TDBEdit fields I can't use a TDBLabel that automatically takes the name from the associated Control as the caption. Instead, I placed TLabel components and made the following method: procedure TMyForm.FormShow(Sender: TObject); var l: TLabel; begin for TComponent(l) in Self do begin if (l is TLabel) and (l.FocusControl is TDBEdit) then l.Caption := TDBEdit(l.FocusControl).Field.DisplayLabel; if (l is TLabel) and (l.FocusControl is TDBLookupComboBox) then l.Caption := TDBLookupComboBox(l.FocusControl).Field.DisplayLabel; end; end; It works. But still I wonder, is there a another way? I've tried TDBText but that shows th field value, not the DisplayLabel.

There is no standard control for it. But it should in fact be easy to add to the LCL.

I have a very large application in which I do the same, but I had to develop my own TLabel subclass for this. (It also switches color when the field is required etc.)

Michael.

Reply by email

Frans
to Michael Van Canneyt

Thanks Michael, I will do the same. And the use of colors is very nice.

mvg
Frans van Leeuwen
M 06-51695390

Op 09-03-2016 om 20:59 schreef Michael Van Canneyt:

Show quoted text 43 lines
On Wed, 9 Mar 2016, Frans wrote: > Hi > > I use Lazarus 1.6 on Windows 7. > I've used lazdatadesktop to change the Displaylabel of the DB fields. In a DBGrid that new names > popup as the column names. But in a form with TDBEdit fields I can't use a TDBLabel that > automatically takes the name from the associated Control as the caption. Instead, I placed TLabel > components and made the following method: > > procedure TMyForm.FormShow(Sender: TObject); > var > l: TLabel; > begin > for TComponent(l) in Self do > begin > if (l is TLabel) and (l.FocusControl is TDBEdit) then > l.Caption := TDBEdit(l.FocusControl).Field.DisplayLabel; > if (l is TLabel) and (l.FocusControl is TDBLookupComboBox) then > l.Caption := TDBLookupComboBox(l.FocusControl).Field.DisplayLabel; > end; > end; > > It works. But still I wonder, is there a another way? I've tried TDBText but that shows th field > value, not the DisplayLabel. There is no standard control for it. But it should in fact be easy to add to the LCL. I have a very large application in which I do the same, but I had to develop my own TLabel subclass for this. (It also switches color when the field is required etc.) Michael. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

LacaK
to Michael Van Canneyt: There is no standard control for it. But it should in fact be easy to add to the LCL. I…
Show quoted text 8 lines
> > It works. But still I wonder, is there a another way? I've tried > TDBText but that shows th field value, not the DisplayLabel. There is no standard control for it. But it should in fact be easy to add to the LCL.

I have used DB-aware version of TLabeledEdit.
It is often the case that you use Label + Edit together. May be that having it in LCL will be also useful.

-Laco.

Reply by email

Michael Van Canneyt
to LacaK
LacaK wrote 13 lines
>> >> It works. But still I wonder, is there a another way? I've tried TDBText >> but that shows th field value, not the DisplayLabel. > > There is no standard control for it. But it should in fact be easy to add > to > the LCL. > I have used DB-aware version of TLabeledEdit. It is often the case that you use Label + Edit together. May be that having it in LCL will be also useful.

The advantage of a separate label is that you can use it for any control: dbcombobox etc.

But the TDBLabeledEdit is obviously also useful, both approaches should be used :)

Michael.

Reply by email