Recent

Author Topic: Class Change Color Edit and MaskEdit is focused  (Read 526 times)

emivaldo

  • New member
  • *
  • Posts: 9
Class Change Color Edit and MaskEdit is focused
« on: September 25, 2023, 04:13:48 pm »
Hello friends.
I created a class that when the TEdit, TLabeledEdit and TMaskEdit ,  is focused, the color changes.
TEdit and TLabeledEdit changes the color. ok.
TMaskedit doesn't change the color.

Quote
unit uChangeColorEdit;

{$mode ObjFPC}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
  LMessages, LCLIntf, EditBtn, MaskEdit, rxcurredit;

type

  { TEdit }

  TEdit = Class(StdCtrls.TEdit)
  private
    FOldColor : TColor;
  protected
    procedure DoEnter; override;
    procedure DoExit; override;
  end;

  { TLabeledEdit }

  TLabeledEdit  = Class(ExtCtrls.TLabeledEdit)
  private
    FOldColor : TColor;
  protected
    procedure DoEnter; override;
    procedure DoExit; override;
  end;

  { TMaskEdit }

  TMaskEdit = Class(MaskEdit.TMaskEdit)
  private
    FOldColor : TColor;
  protected
    procedure DoEnter; override;
    procedure DoExit; override;
  end;

implementation

{ TMaskEdit }

procedure TMaskEdit.DoEnter;
begin
  inherited DoEnter;
  FOldColor := Color;
  Color := clYellow;
end;

procedure TMaskEdit.DoExit;
begin
  inherited DoExit;
  Color := FOldColor;
end;

{ TLabeledEdit }

procedure TLabeledEdit.DoEnter;
begin
  inherited DoEnter;
  FOldColor := Color;
  Color := clYellow;
end;

procedure TLabeledEdit.DoExit;
begin
  inherited DoExit;
  Color := FOldColor;
end;

{ TEdit }

procedure TEdit.DoEnter;
begin
  inherited DoEnter;
  FOldColor := Color;
  Color := clYellow;
end;

procedure TEdit.DoExit;
begin
  inherited DoExit;
  Color := FOldColor;
end;

end.                       

Bart

  • Hero Member
  • *****
  • Posts: 5137
    • Bart en Mariska's Webstek
Re: Class Change Color Edit and MaskEdit is focused
« Reply #1 on: September 25, 2023, 05:24:13 pm »
First: check if the MaskEdit on the form actually is of type uChangeColorEdit.TMaskEdit (and not MaskEdit.TMaskEdit).
Then: check if the overridden DoEnter for TMaskEdit is actually executed (add a showmessage or a debugln/writeln statement in there).

Bart
« Last Edit: September 25, 2023, 05:26:37 pm by Bart »

emivaldo

  • New member
  • *
  • Posts: 9
Re: Class Change Color Edit and MaskEdit is focused
« Reply #2 on: September 25, 2023, 09:17:18 pm »
Friend Bart,
Thank you for your help.
I had declared the ChangeColor unit before the TMaskEdit class units, when I added it later, it worked and even included other classes.

Code: Pascal  [Select][+][-]
  1. unit uViewBase;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
  9.   MaskEdit, BCPanel, BCButton, LMessages, LCLIntf, DBGrids,
  10.   EditBtn, SpinEx, RxDBGrid, rxcurredit, rxspin, [b]uChangeColorEdit[/b],
  11.   //Project
  12.   uFComun_Base, VO
  13.   ;
  14.  
  15. type
  16.  

Thanks.
Strong hug.

Pe3s

  • Hero Member
  • *****
  • Posts: 515
Re: Class Change Color Edit and MaskEdit is focused
« Reply #3 on: September 25, 2023, 09:40:17 pm »
Demo focus

Bart

  • Hero Member
  • *****
  • Posts: 5137
    • Bart en Mariska's Webstek
Re: Class Change Color Edit and MaskEdit is focused
« Reply #4 on: September 25, 2023, 09:43:02 pm »
I had declared the ChangeColor unit before the TMaskEdit class units, when I added it later, it worked and even included other classes.
We've all been there ...

Bart

emivaldo

  • New member
  • *
  • Posts: 9
Re: Class Change Color Edit and MaskEdit is focused
« Reply #5 on: September 26, 2023, 01:18:04 pm »
Demo focus

Thank you Pe3s
His example was excellent.

emivaldo

  • New member
  • *
  • Posts: 9
Re: Class Change Color Edit and MaskEdit is focused
« Reply #6 on: September 26, 2023, 01:19:39 pm »
I had declared the ChangeColor unit before the TMaskEdit class units, when I added it later, it worked and even included other classes.
We've all been there ...

Bart

It's true,  :D :D :D :D
thank you

 

TinyPortal © 2005-2018