Possible Bug lazarus / 31-LCL ---------------------------------------------------------------------- egsuh · 2019-09-19 04:26 I think this may be a bug.  In the file attached, there is a form which has two TEdit fields and three Buttons. If Button3 is pressed, the two TEdit fiels must be filled with random numbers. Please put cursor within the Edit2, and press Button3. It will do ShowMessage, but two edit fields are not filled with random numbers. Now, comment out the Showmessage command, put cursor within the Edit2, and press Button3. Then the two edit fields will be filled with random numbers. I found this while checking the calls to EditingDone event. This event is called when the focus moves away from the control (Edit2 in this case). But when the control is within a frame, not form, this is not called reliably. I'll test this again. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit fcontrollink; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls; type  TMyClass = class  public     Field1,     Field2 : string;  end;   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    Button3: TButton;    Edit1: TEdit;    Edit2: TEdit;    Memo1: TMemo;  Panel1: TPanel;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure Button3Click(Sender: TObject);    procedure Edit1EditingDone(Sender: TObject);    procedure Edit2EditingDone(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);  private     FMyClass : TMyClass;      function getF1: string;     function getF2: string;     procedure setF1(s: string);   procedure setF2(s: string);     procedure setMyClass(mc: TMyClass);   public     property MyClass: TMyClass read FMyClass write setMyClass;     property F1: string read getF1 write setF1;     property F2: string read getF2 write setF2;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);beginend; procedure TForm1.Button2Click(Sender: TObject);begin   if MyClass <> nil then with memo1.lines do   begin    Add('Field1 is ' + MyClass.Field1) ;      Add('Field2 is ' + MyClass.Field2) ;   end;end; procedure TForm1.Edit1EditingDone(Sender: TObject);begin   F1 := trim(Edit1.Text);end; procedure TForm1.Edit2EditingDone(Sender: TObject);begin   F2 := trim(Edit2.Text);   ShowMessage('edit2editingdone called');  // comment out this and press Button3. end; procedure TForm1.Button3Click(Sender: TObject);begin   Randomize;   F1 := IntToStr(Trunc(Random(1000000)));   F2 := IntToStr(Trunc(Random(1000000)));end;  procedure TForm1.FormCreate(Sender: TObject);var   anmc : TMyClass;begin   anmc := TMyClass.Create;    anmc.Field1 := 'string field 1';   anmc.Field2 := 'string field 2';    MyClass := anmc;end; procedure TForm1.FormDestroy(Sender: TObject);begin  MyClass.Free;end; function TForm1.getF1: string;begin   if FMyClass <> nil then Result := FMyClass.Field1 else Result := '';end; function TForm1.getF2: string;begin   if FMyClass <> nil then Result := FMyClass.Field2 else Result := '';end; procedure TForm1.setF1(s: string);begin   if MyClass <> nil then MyClass.Field1:= s;   Edit1.Text := s;end; procedure TForm1.setF2(s: string);begin   if MyClass <> nil then MyClass.Field2:=  s;   Edit2.Text := s;end; procedure TForm1.setMyClass(mc: TMyClass);begin   if mc <> nil then begin     FMyClass := mc;     Edit1.Enabled := True;     Edit2.Enabled := True;     Edit1.Text := FMyClass.Field1;     Edit2.Text := FMyClass.Field2;   end   else begin      Edit1.Enabled := False;      Edit2.Enabled := False;   end;end; end. ---------------------------------------------------------------------- Thaddy · 2019-09-19 05:03 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    F1 := IntToStr(Trunc(Random(1000000)));    F2 := IntToStr(Trunc(Random(1000000)));Why trunc on an integer value? That makes no sense at all... (Not the cause, but one of the things that are wrong with your code) What is really wrong is that TMyClass is declared as class and never instantiated. Did you mean record ? Try that and report back... ---------------------------------------------------------------------- egsuh · 2019-09-19 05:15 Sorry. Trunc is not necessary here.  Random returns number between 0 and 1, so I was confused. TMyClass is instantiated at the FormCreate.   MyClass := anmc;  does it.  I did not call FMyClass := TMyClass.Create;  because I wanted to  call setMyClass. ---------------------------------------------------------------------- Thaddy · 2019-09-19 06:48 Quote from: egsuh on September 19, 2019, 07:15:38 am MyClass := anmc;  does it.  I did not call FMyClass := TMyClass.Create;  because I wanted to  call setMyClass. I told you so. Listening is an art. ---------------------------------------------------------------------- PascalDragon · 2019-09-19 07:05 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button3Click(Sender: TObject);begin   Randomize;   F1 := IntToStr(Trunc(Random(1000000)));   F2 := IntToStr(Trunc(Random(1000000)));end;Aside from that you already found the solution: you should call Randomize only once at program start and not every time you press a button. ---------------------------------------------------------------------- egsuh · 2019-09-19 07:21 QuoteI told you so. Listening is an art. What do you mean by this?  I instantiated TMyClass. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i anmc := TMyClass.Create;.....MyClass := anmc; Quoteyou should call Randomize only once at program start and not every time you press a button.That's not the point. ---------------------------------------------------------------------- Bart · 2019-09-19 08:03 In the scenario described I see TForm1.Edit2EditingDone being executed allways, however if the ShowMessage is called in TForm1.Edit2EditingDone then TForm1.Button3Click is not called when you click on Button3. Bart ---------------------------------------------------------------------- Thaddy · 2019-09-19 08:11 Quote from: egsuh on September 19, 2019, 09:21:43 amThat's not the point. Well, look again. Bart pointed you to the same issue. ---------------------------------------------------------------------- egsuh · 2019-09-19 08:22 QuoteShowMessage is called in TForm1.Edit2EditingDone then TForm1.Button3Click is not called when you click on Button3. Yes. That's my point. When I press Button3, Edit2EditingDone should be executed because the focus leaves Edit2, and it must be followed by execution of Button3Click. But why ShowMessage blocks the execution of Button3Click? If Showmessage is not called within Edit2EditingDone, Button3Click is executed.   Randomizing again is irrelevant here. ---------------------------------------------------------------------- Bart · 2019-09-19 20:17 The behaviour is the same as in Delphi (7). If I put a ShowMessage inside an OnExit event, then the OnClickEvent of the button is not fired. In fact this happens if you show a modal form in the OnExit handler. It seems that showing a modal form  blockt/clears the event queue. Bart ---------------------------------------------------------------------- egsuh · 2019-09-20 03:49 @Bart Yes, you are right. I tested it with Delphi DX 10.1 Berlin.  (Why do I not use Delphi? This is free starter version^^). But this behavior is related with TButton. I tested with following codes. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Edit1Exit(Sender: TObject);begin   ShowMessage(Edit1.Text);end; procedure TForm1.Button2Click(Sender: TObject);begin   Edit1.Text := 'Text from button 2';end; procedure TForm1.Edit2Enter(Sender: TObject);begin   Edit1.Text := Edit2.Text;end; procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);begin  Edit1.Text := node.text;end; procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;  Selected: Boolean);begin  if Selected then Edit1.Text := item.Caption;end;  Followings occur when I press each control while Edit1 is focused.  1.  When I press Button2,  Edit1.Text is showmessaged, and when I close, there are no change in the Edit1.  And if I press Button2 again, the content of Edit1 is changed (this is very natural becuase Edit1Exit is not called). 2.  When I enter Edit2, everything goes as expected. 3.  When I select any tree node, everything goes as expected. 4.  When I select any listview item, Edit1.Text is modified first, and then the modified message is shown (i.e.  selected node.text).   But, in Delphi, everything goes as expected here too. My conclusions are : 1.  TButton's behavior is a bug both in Delphi and Lazarus. 2.  The order in which  events occur when a listview item is selected in Lazarus is wrong. This is a bug (or many bugs).  There is a logical order of events happening. In our case, the focus must 1) move away from TEdit,  2) Enter TListView, and then 3) listview item is selected. A person cannot enter a new room before leaving current room. 3.  Aside from that,  TTreeview should use treenode about to lose focus (or selection) as parameter of  OnChanging event handler.