Recent

Author Topic: editbox colors  (Read 1884 times)

Todor

  • Newbie
  • Posts: 5
editbox colors
« on: June 12, 2018, 12:32:11 am »
I need to remake this,so when the text is same in both edits 1 and 2 , text in both edits should be at first red and then edits should be invisible,or when text is not same text in both edits should be red and then white.Please help me


procedure TForm1.Edit1Click(Sender: TObject);

begin
  edit1.Font.Color:=clred;
  if ((edit2.font.color=clred) and (edit1.text = edit2.text)) then
  begin
   edit2.visible:=false;
   edit1.visible:=false;
  end ;
  if ((edit2.font.color =clred) and (edit1.text <> edit2.text))  then
    begin

      edit1.font.color:=clwhite;
      edit2.font.color:=clwhite;

    end;


end;

procedure TForm1.Edit2Click(Sender: TObject);
begin
  edit2.Font.Color:=clred;
   if ((edit1.font.color=clred) and (edit1.text = edit2.text)) then
  begin

   edit1.visible:=false;
   edit2.visible:=false;
 end;
   if ((edit1.font.color =clred) and (edit1.text <> edit2.text)) then
     begin
 
       edit2.font.color:=clwhite;
       edit1.font.color:=clwhite;

     end;

end;
end.

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: editbox colors
« Reply #1 on: June 12, 2018, 07:59:55 am »
Not sure why you want to do that. But in this case, I think it will be easier to use a TTimer.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, Forms, Controls, Graphics, StdCtrls, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Edit1: TEdit;
  16.     Edit2: TEdit;
  17.     Timer1: TTimer;
  18.     procedure Edit1Click(Sender: TObject);
  19.     procedure Edit2Click(Sender: TObject);
  20.     procedure Timer1Timer(Sender: TObject);
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.Edit1Click(Sender: TObject);
  33. begin
  34.   Edit1.Font.Color := clRed;
  35.   Timer1.Enabled := True;
  36. end;
  37.  
  38. procedure TForm1.Edit2Click(Sender: TObject);
  39. begin
  40.   Edit2.Font.Color := clRed;
  41.   Timer1.Enabled := True;
  42. end;
  43.  
  44. procedure TForm1.Timer1Timer(Sender: TObject);
  45. begin
  46.   if (Edit1.Text = Edit2.Text) then
  47.   begin
  48.     Edit1.Visible := False;
  49.     Edit2.Visible := False;
  50.   end
  51.   else begin
  52.     Edit1.Font.Color := clWhite;
  53.     Edit2.Font.Color := clWhite;
  54.   end;
  55.   Timer1.Enabled := False;
  56. end;
  57.  
  58. end.

You can get the source in the file test.zip below.
« Last Edit: June 12, 2018, 08:02:28 am by Handoko »

Todor

  • Newbie
  • Posts: 5
Re: editbox colors
« Reply #2 on: June 12, 2018, 09:31:12 am »
Thank you very much  :D

 

TinyPortal © 2005-2018