Recent

Author Topic: [SOLVED] Can't pass string to TEdit on a Tframe  (Read 841 times)

lazarusprogrammer

  • New Member
  • *
  • Posts: 12
[SOLVED] Can't pass string to TEdit on a Tframe
« on: April 10, 2026, 02:04:36 pm »
Hi there, i have this frame and everything is working except i can't pass a string to FIND_EDIT : TEdit; Whatever i do TEdit not changing. Tried sending string directly like SRCH.FIND_EDIT.Text:= 'something';. Tried making update procedure in a frame and then calling it from outside. Even tried assigning events like @onchange and other and nothing. TEdit not changing not updating and not saying anything i mean no access violation errors or such. But everything else is working and if i type in text in TEdit it's working and doing stuff it should do. But for some reason i can't pass text to edit from somewhere else. Help please

this is the frame :
Code: Pascal  [Select][+][-]
  1. unit FRAME_SYN_SEARCH;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, StdCtrls, Buttons, ExtCtrls, SynEdit,
  9.   SynEditTypes;
  10.  
  11. type
  12.   TSEARCH_DIRECTION = (stForward, stBackward);
  13. type
  14.  
  15.   { TSYN_SEARCH_FRAME }
  16.  
  17.   TSYN_SEARCH_FRAME = class(TFrame)
  18.  
  19.     CaseSens_CheckBox: TCheckBox;
  20.     REPLACE_ALL_CheckBox: TCheckBox;
  21.     WHOLE_WORD_CheckBox: TCheckBox;
  22.     REPLACE_CHECKBOX: TCheckBox;
  23.     FIND_EDIT: TEdit;
  24.     REPLACE_EDIT: TEdit;
  25.     BTN_FIND: TSpeedButton;
  26.     procedure BTN_CLICK(Sender: TObject);
  27.     procedure REPLACE_CHECKBOX_CHANGE(Sender: TObject);
  28.   private
  29.     procedure DO_SEARCH;
  30.     function GetOptions: TSynSearchOptions;
  31.   public
  32.     SYN : TSynEdit;
  33.     SEARCH_DIRECTION : TSEARCH_DIRECTION;
  34.   end;
  35. implementation
  36.  
  37. {$R *.lfm}
  38.  
  39. function TSYN_SEARCH_FRAME.GetOptions :TSynSearchOptions;
  40. begin
  41.   Result := [ssoFindContinue];
  42.   //if actWholeScope.Checked then Result := [ssoEntireScope];
  43.   //if actSelectOnly.Checked then Result := [ssoSelectedOnly];
  44.  
  45.   if CaseSens_CheckBox.Checked    then Result := Result+[ssoMatchCase];
  46.   if WHOLE_WORD_CheckBox.Checked       then Result := Result+[ssoWholeWord];
  47.   if SEARCH_DIRECTION = stBackward       then Result := Result+[ssoBackwards];
  48.   if REPLACE_CHECKBOX.Checked  then begin
  49.     Result := Result+[ssoReplace];
  50.     if REPLACE_ALL_CheckBox.Checked       then Result := Result+[ssoReplaceAll];
  51.     //if actPromptOnReplace.Checked  then Result := Result+[ssoPrompt];
  52.   end;
  53. end;
  54.  
  55. procedure TSYN_SEARCH_FRAME.DO_SEARCH;
  56. var i : Integer = 0;
  57. begin
  58. if REPLACE_CHECKBOX.Checked then
  59. i := SYN.SearchReplace(FIND_EDIT.Text, REPLACE_EDIT.Text, GetOptions)
  60. else
  61. i := SYN.SearchReplace(FIND_EDIT.Text, '', GetOptions);
  62.  
  63. if i = 0 then begin SYN.CaretY:=0; SYN.CaretX:=0; end;
  64. end;
  65.  
  66. procedure TSYN_SEARCH_FRAME.REPLACE_CHECKBOX_CHANGE(Sender: TObject);
  67. begin
  68. REPLACE_EDIT.Enabled:= REPLACE_CHECKBOX.Checked;
  69. end;
  70.  
  71. procedure TSYN_SEARCH_FRAME.BTN_CLICK(Sender: TObject);
  72. begin
  73. SEARCH_DIRECTION := stForward;
  74. DO_SEARCH;
  75. SYN.SetFocus;
  76. end;
  77.  
  78. end.
  79.  
  80.  
and i am spawnig this frame like that in case it's matter
Code: Pascal  [Select][+][-]
  1. SRCH := TSYN_SEARCH_FRAME.Create(SRCH_PANEL);
  2. SRCH.Parent := SRCH_PANEL;
  3. SRCH.Align:= alClient;
  4. SRCH.Show;
  5. SRCH.syn := SynEdit1;
« Last Edit: April 14, 2026, 06:50:25 pm by lazarusprogrammer »

mas steindorff

  • Hero Member
  • *****
  • Posts: 574
Re: Can't pass string to TEdit on a Tframe
« Reply #1 on: April 13, 2026, 03:45:21 am »
which TEdit are you trying to make public? I only see a sync_edit
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

cdbc

  • Hero Member
  • *****
  • Posts: 2728
    • http://www.cdbc.dk
Re: Can't pass string to TEdit on a Tframe
« Reply #2 on: April 13, 2026, 10:13:44 am »
Hi
The declarations between 'class' & 'private' are in {$M+} by convention considered 'published'...
{$M+} mode is basically everything that descends from 'TPersistent', i.e.: all components.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

lazarusprogrammer

  • New Member
  • *
  • Posts: 12
Re: Can't pass string to TEdit on a Tframe
« Reply #3 on: April 14, 2026, 02:02:02 pm »
which TEdit are you trying to make public? I only see a sync_edit
there is FIND_EDIT : TEdit. I don't know what do you mean by saying "make it public". But i am spawning this frame on a form and then during the work of the program i am passing the string to TEdit but TEdit does not updating, passed string does not appears in TEdit. But it does update on creation. I mean when i am spawning the frame and passing the string at that moment TEdit does updates.

I still don't understand what exactly a problem there but i fixed the problem by adding frame on a form instead of spawning frame from the code. But i am keep getting similar update problems with other frames i am making. And it's rises a question if it's even worth to use frames or i can use forms instead? Why should i use frames?

cdbc

  • Hero Member
  • *****
  • Posts: 2728
    • http://www.cdbc.dk
Re: Can't pass string to TEdit on a Tframe
« Reply #4 on: April 14, 2026, 04:21:55 pm »
Hi
Maybe you could try like this:
Code: Pascal  [Select][+][-]
  1. unit FRAME_SYN_SEARCH;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, StdCtrls, Buttons, ExtCtrls, SynEdit,
  9.   SynEditTypes;
  10.  
  11. type
  12.   TSEARCH_DIRECTION = (stForward, stBackward);
  13. type
  14.  
  15.   { TSYN_SEARCH_FRAME }
  16.  
  17.   TSYN_SEARCH_FRAME = class(TFrame)
  18.  
  19.     CaseSens_CheckBox: TCheckBox;
  20.     REPLACE_ALL_CheckBox: TCheckBox;
  21.     WHOLE_WORD_CheckBox: TCheckBox;
  22.     REPLACE_CHECKBOX: TCheckBox;
  23.     FIND_EDIT: TEdit;
  24.     REPLACE_EDIT: TEdit;
  25.     BTN_FIND: TSpeedButton;
  26.     procedure BTN_CLICK(Sender: TObject);
  27.     procedure REPLACE_CHECKBOX_CHANGE(Sender: TObject);
  28.   private
  29.     procedure DO_SEARCH;
  30.     function GetOptions: TSynSearchOptions;
  31. ///// area 51 /////
  32.     function GetSearchMask: string;
  33.     procedure SetSearchMask(aValue: string);
  34. ///// area 51 /////
  35.   public
  36.     SYN : TSynEdit;
  37.     SEARCH_DIRECTION : TSEARCH_DIRECTION;
  38. ///// area 51 /////
  39.     property SearchMask: string read GetSearchMask write SetSearchMask;
  40. ///// area 51 /////
  41.   end;
  42. implementation
  43.  
  44. {$R *.lfm}
  45.  
  46. function TSYN_SEARCH_FRAME.GetOptions :TSynSearchOptions;
  47. begin
  48.   Result := [ssoFindContinue];
  49.   //if actWholeScope.Checked then Result := [ssoEntireScope];
  50.   //if actSelectOnly.Checked then Result := [ssoSelectedOnly];
  51.  
  52.   if CaseSens_CheckBox.Checked    then Result := Result+[ssoMatchCase];
  53.   if WHOLE_WORD_CheckBox.Checked       then Result := Result+[ssoWholeWord];
  54.   if SEARCH_DIRECTION = stBackward       then Result := Result+[ssoBackwards];
  55.   if REPLACE_CHECKBOX.Checked  then begin
  56.     Result := Result+[ssoReplace];
  57.     if REPLACE_ALL_CheckBox.Checked       then Result := Result+[ssoReplaceAll];
  58.     //if actPromptOnReplace.Checked  then Result := Result+[ssoPrompt];
  59.   end;
  60. end;
  61.  
  62. ///// area 51 /////
  63. function TSYN_SEARCH_FRAME.GetSearchMask: string;
  64. begin
  65.   Result:= FIND_EDIT.Text;
  66. end;
  67.  
  68. procedure SetSearchMask(aValue: string);
  69. begin
  70.   FIND_EDIT.Text:= aValue;
  71. end;
  72. ///// area 51 /////
  73.  
  74. procedure TSYN_SEARCH_FRAME.DO_SEARCH;
  75. var i : Integer = 0;
  76. begin
  77. if REPLACE_CHECKBOX.Checked then
  78. i := SYN.SearchReplace(FIND_EDIT.Text, REPLACE_EDIT.Text, GetOptions)
  79. else
  80. i := SYN.SearchReplace(FIND_EDIT.Text, '', GetOptions);
  81.  
  82. if i = 0 then begin SYN.CaretY:=0; SYN.CaretX:=0; end;
  83. end;
  84.  
  85. procedure TSYN_SEARCH_FRAME.REPLACE_CHECKBOX_CHANGE(Sender: TObject);
  86. begin
  87. REPLACE_EDIT.Enabled:= REPLACE_CHECKBOX.Checked;
  88. end;
  89.  
  90. procedure TSYN_SEARCH_FRAME.BTN_CLICK(Sender: TObject);
  91. begin
  92. SEARCH_DIRECTION := stForward;
  93. DO_SEARCH;
  94. SYN.SetFocus;
  95. end;
  96.  
  97. end.
  98.  
Then
Code: Pascal  [Select][+][-]
  1. SRCH.SearchMask:= 'Fubar';
should work...
Regards Benny

edit: renamed frame ;)
« Last Edit: April 14, 2026, 04:25:42 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

lazarusprogrammer

  • New Member
  • *
  • Posts: 12
Re: Can't pass string to TEdit on a Tframe
« Reply #5 on: April 14, 2026, 06:49:32 pm »
Hi
Maybe you could try like this:
Code: Pascal  [Select][+][-]
  1. unit FRAME_SYN_SEARCH;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, StdCtrls, Buttons, ExtCtrls, SynEdit,
  9.   SynEditTypes;
  10.  
  11. type
  12.   TSEARCH_DIRECTION = (stForward, stBackward);
  13. type
  14.  
  15.   { TSYN_SEARCH_FRAME }
  16.  
  17.   TSYN_SEARCH_FRAME = class(TFrame)
  18.  
  19.     CaseSens_CheckBox: TCheckBox;
  20.     REPLACE_ALL_CheckBox: TCheckBox;
  21.     WHOLE_WORD_CheckBox: TCheckBox;
  22.     REPLACE_CHECKBOX: TCheckBox;
  23.     FIND_EDIT: TEdit;
  24.     REPLACE_EDIT: TEdit;
  25.     BTN_FIND: TSpeedButton;
  26.     procedure BTN_CLICK(Sender: TObject);
  27.     procedure REPLACE_CHECKBOX_CHANGE(Sender: TObject);
  28.   private
  29.     procedure DO_SEARCH;
  30.     function GetOptions: TSynSearchOptions;
  31. ///// area 51 /////
  32.     function GetSearchMask: string;
  33.     procedure SetSearchMask(aValue: string);
  34. ///// area 51 /////
  35.   public
  36.     SYN : TSynEdit;
  37.     SEARCH_DIRECTION : TSEARCH_DIRECTION;
  38. ///// area 51 /////
  39.     property SearchMask: string read GetSearchMask write SetSearchMask;
  40. ///// area 51 /////
  41.   end;
  42. implementation
  43.  
  44. {$R *.lfm}
  45.  
  46. function TSYN_SEARCH_FRAME.GetOptions :TSynSearchOptions;
  47. begin
  48.   Result := [ssoFindContinue];
  49.   //if actWholeScope.Checked then Result := [ssoEntireScope];
  50.   //if actSelectOnly.Checked then Result := [ssoSelectedOnly];
  51.  
  52.   if CaseSens_CheckBox.Checked    then Result := Result+[ssoMatchCase];
  53.   if WHOLE_WORD_CheckBox.Checked       then Result := Result+[ssoWholeWord];
  54.   if SEARCH_DIRECTION = stBackward       then Result := Result+[ssoBackwards];
  55.   if REPLACE_CHECKBOX.Checked  then begin
  56.     Result := Result+[ssoReplace];
  57.     if REPLACE_ALL_CheckBox.Checked       then Result := Result+[ssoReplaceAll];
  58.     //if actPromptOnReplace.Checked  then Result := Result+[ssoPrompt];
  59.   end;
  60. end;
  61.  
  62. ///// area 51 /////
  63. function TSYN_SEARCH_FRAME.GetSearchMask: string;
  64. begin
  65.   Result:= FIND_EDIT.Text;
  66. end;
  67.  
  68. procedure SetSearchMask(aValue: string);
  69. begin
  70.   FIND_EDIT.Text:= aValue;
  71. end;
  72. ///// area 51 /////
  73.  
  74. procedure TSYN_SEARCH_FRAME.DO_SEARCH;
  75. var i : Integer = 0;
  76. begin
  77. if REPLACE_CHECKBOX.Checked then
  78. i := SYN.SearchReplace(FIND_EDIT.Text, REPLACE_EDIT.Text, GetOptions)
  79. else
  80. i := SYN.SearchReplace(FIND_EDIT.Text, '', GetOptions);
  81.  
  82. if i = 0 then begin SYN.CaretY:=0; SYN.CaretX:=0; end;
  83. end;
  84.  
  85. procedure TSYN_SEARCH_FRAME.REPLACE_CHECKBOX_CHANGE(Sender: TObject);
  86. begin
  87. REPLACE_EDIT.Enabled:= REPLACE_CHECKBOX.Checked;
  88. end;
  89.  
  90. procedure TSYN_SEARCH_FRAME.BTN_CLICK(Sender: TObject);
  91. begin
  92. SEARCH_DIRECTION := stForward;
  93. DO_SEARCH;
  94. SYN.SetFocus;
  95. end;
  96.  
  97. end.
  98.  
Then
Code: Pascal  [Select][+][-]
  1. SRCH.SearchMask:= 'Fubar';
should work...
Regards Benny

edit: renamed frame ;)

Yes thanks with property it's working.

I got part of the code from "lazarus\examples\SynEdit\SearchAndReplace\" and there is no such property for TEditor but it's working anyway. But at the same time in lazarus example there is property for editor but my frame works fine without that. And i am actually tried to make property for TEdit but i was making it like "property SearchMask : TEdit read string write string;" and it obviously didn't work. And i stopped even trying making property for TEdit because as i said synedit working without setting up a property... Frames are so weird.

mas steindorff

  • Hero Member
  • *****
  • Posts: 574
Re: Can't pass string to TEdit on a Tframe
« Reply #6 on: April 14, 2026, 08:51:15 pm »
.... And it's rises a question if it's even worth to use frames or i can use forms instead? Why should i use frames?
It’s doable but placing a form on another form is not an easy task, let alone 5 or 6 like I do.  for complex GUI interfaces, another form may be a better approach.
[/obvious statement begin]
You can put all of the classes and frame code in Main but you will end up with a big pas file that will be harder to manage. By breaking code up into modules, this helps to both reduce the main file size and allow code reusability.
[/obvious statement end]
A frame can be though as a visible component that can include several pascal components that work together or as I use them, a visible interface to my Class. For reusability (just like components), the simpler the frame, the more projects it will fit and can be dropped onto.   It also can be used several times in the same project on different forms/tabs when designed correctly. 
As an example, I have a frame that includes 8 check boxes that act as a GUI bits => number convertor. The labels of the check boxes can be set by the client with a CSV string during run time so each frame is custom and the concepts/process of "Bit weighted values" can be hidden from the end user.     

For you, your "search frame" may include case sensitive and whole word options later.  You have the choice to add GUI elements to support these options or just set these “search frame“ parameters from the client.  Either way, the code to handle these new options is self contained in your frame unit and your client can remain untouched.

In my case, I will create a class for a complex hardware subsystem for other team members to use. This class handles the hardware elements and helps to simplify their GUI interface code.  For standard CYA operation mode, I will include a separate debug frame that I can drop on my debug viewer that can monitor how they are using the class and verify it is working as expected and/or I can advise them on something that is not being done correctly on their side as a client.  With the setting of a (frame).debug_mode=true property, this frame displays “set controls” so I can use on the Class with edge case parameters or I can use to test the hardware’s self protection controls itself by bypassing the Class's protection code.

MAS
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

 

TinyPortal © 2005-2018