No more changes in TEdit after activate TButton lazarus / 61-Beginners ---------------------------------------------------------------------- ThomasK1201 · 2015-03-06 12:10 Hi guys I want to a TEdit to change from ReadOnly = False to ReadOnly = True if a button is activated. How can I make this happen? I think it should be something like this: Code: [Select]If Button = Activated then Edit.ReadOnly := True; But I dont know exactly how to do this and I cant find it by using Google.. Thomas. ---------------------------------------------------------------------- Zoran · 2015-03-06 12:54 Put a ToggleBox component on the form and put this in its OnChange event: Code: [Select]procedure TForm1.ToggleBox1Change(Sender: TObject); begin   Edit1.Enabled := not ToggleBox1.Checked; // Better use Edit1.Enabled than Edit1.ReadOnly, because of visual appearance // or Edit1.ReadOnly := ToggleBox1.Checked; end; ---------------------------------------------------------------------- ThomasK1201 · 2015-03-06 19:48 Well, the problem is that the users of the form shouldnt be able to change from enabled to disabled. For school I make a program that students of lower classes can use to practice ciphering (Im not sure if this is the right translation, my English isnt perfect at all). And after putting the answers in de Edits and confirming them, they shouldnt be able to change the values they entered. And a togglebox can be enabled and disabled. So when students disable the togglebox they can change their entered values. ---------------------------------------------------------------------- ThomasK1201 · 2015-03-06 19:52 And I have a second question: I made a calculator for the program in Lazarus. I placed Buttons for every number and for characters like + - =, etc. and a Edit. How can I make those buttons add a number instead of replacing the previous number. So when I first click on 1, the Edit shows 1. But after that I click 2, and the 1 is gone and Edit only shows 2. How can I make happen that Edit shows 12? ---------------------------------------------------------------------- ChrisF · 2015-03-06 19:58 Apparently, by 'activate TButton' you probably mean 'Button clicked' (i.e. when the user click the pushbutton with mouse or keyboard). In this case, use the 'OnClick' event of your pushbutton to insert your code. Or just double-click on the concerned pushbutton in the Lazarus IDE: the concerned event/procedure will be proposed to you automatically (it's the "by-default" event for a pushbutton). For instance, for a form (Form1) with a edit control (Edit1) and a pushbutton (Button1), this gives: Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     Edit1: TEdit;     procedure Button1Click(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin   Edit1.Enabled := False;; end; end. ---------------------------------------------------------------------- ChrisF · 2015-03-06 19:58 Quote from: ThomasK1201 on March 06, 2015, 08:52:09 pmAnd I have a second question: I made a calculator for the program in Lazarus. I placed Buttons for every number and for characters like + - =, etc. and a Edit. How can I make those buttons add a number instead of replacing the previous number. So when I first click on 1, the Edit shows 1. But after that I click 2, and the 1 is gone and Edit only shows 2. How can I make happen that Edit shows 12? Edit1.Text := Edit1.Text + 'your_new_number'; ---------------------------------------------------------------------- howardpc · 2015-03-06 20:20 This gives you an example of one way in which a confirmation button (which can only be clicked once) can be enabled when entries are completed, which then prevents further editing. Generate an OnCreate event for a new blank form Lazarus project and complete it as follows: Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Forms, Controls, StdCtrls, ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)     LabeledEdit1: TLabeledEdit;     procedure FormCreate(Sender: TObject);   private     EEntry1, EEntry2: TLabeledEdit;     BEntriesCompleted: TButton;     procedure BEntriesCompletedClick(Sender: TObject);     procedure EEntryEditingDone(Sender: TObject);   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);   function NewEdit(const aCaption: string; aLeft, aTop: integer): TLabeledEdit;   begin     Result:=TLabeledEdit.Create(Self);     Result.LabelPosition:=lpLeft;     Result.EditLabel.Caption:=aCaption;     Result.Left:=aLeft + Result.LabelSpacing + Canvas.TextWidth(aCaption);     Result.Top:=aTop;     Result.OnEditingDone:=@EEntryEditingDone;     Result.Parent:=Self;   end; begin   EEntry1:=NewEdit('Enter cipher 1:',10,10);   EEntry2:=NewEdit('Enter cipher 2:',10,40);   BEntriesCompleted:=TButton.Create(Self);   BEntriesCompleted.Caption:='Click when entries are complete';   BEntriesCompleted.Align:=alBottom;   BEntriesCompleted.BorderSpacing.Around:=20;   BEntriesCompleted.OnClick:=@BEntriesCompletedClick;   BEntriesCompleted.Enabled:=False;   BEntriesCompleted.Parent:=Self; end; procedure TForm1.BEntriesCompletedClick(Sender: TObject); begin   EEntry1.Enabled:=False;   EEntry2.Enabled:=False;   BEntriesCompleted.Enabled:=False; end; procedure TForm1.EEntryEditingDone(Sender: TObject); begin   if not (Sender is TLabeledEdit) then Exit;   TLabeledEdit(Sender).Tag:=1;   if (EEntry1.Tag + EEntry2.Tag >= 2) then     BEntriesCompleted.Enabled:=True; end; end. ---------------------------------------------------------------------- ThomasK1201 · 2015-03-06 20:35 And then one more simple question: How can I change the color of the letters and numbers in Edits? ---------------------------------------------------------------------- Blaazen · 2015-03-06 21:12 TEdit.Font.Color (you can change it in OI or in code). ---------------------------------------------------------------------- ThomasK1201 · 2015-03-09 12:41 Thanks a lot guys!