• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

A dbrichedit question.

Hi,

I have these procedures and they use the dbrichedit1.
The dbrichedit1 is on the PageControl's tab with align = alClient.

procedure TMainForm.PlayBtnClick(Sender: TObject);
begin
  if not BeenPaused then
    SpVoice1.Speak(DBRichEdit1.Text, SVSFlagsAsync)   <=====
  else
  begin
   SpVoice1.Resume;
    BeenPaused := False
   end
end;

procedure TMainForm.SetTextHilite(FirstChar, Len: Integer);
begin
  DBRichEdit1.SelStart := FirstChar;  <========
  DBRichEdit1.SelLength := Len;       <=========
end;

procedure TMainForm.SetTextStyle(FirstChar, Len: Integer; Styles: TFontStyles);
begin
  with DBRichEdit1 do   <=========
  begin
    Lines.BeginUpdate;
    try
      SelStart := FirstChar;
      SelLength := Len;
      SelLength := 0;
    finally
      Lines.EndUpdate
    end
  end
end;

But know I made a button that creates the tabs of the pagecontrol (and the dbrichedit on it) dynamicly.
What do I have to alter in the code to get the active dbrichedit .

Peter
0
peterkiers
Asked:
peterkiers
  • 3
  • 2
1 Solution
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
If you look in a previews asked question (that one about Renaming Tabs) you can find a piece of code that I wrote just to find the right DbRichedit.
It was in the RenTab procedure.
The piece of code was

for i := PageControl1.ActivePage.ComponentCount - 1 downto 0 do
      if PageControl1.ActivePage.Components[i] is TDBRichEdit then
      begin
        OldName := TDBRichEdit(PageControl1.ActivePage.Components[i]).DataField;
        TDBRichEdit(PageControl1.ActivePage.Components[i]).DataField := NewName;
        break;
      end;

Here instead you can do

var
REdit: TDbRichEdit;
i: Integer;
Begin
for i := PageControl1.ActivePage.ComponentCount - 1 downto 0 do
      if PageControl1.ActivePage.Components[i] is TDBRichEdit then
      begin
        Redit := PageControl1.ActivePage.Components[i];
        break;
      end;
 If Assigned(Redit) then
   begin
      Redit.SelStart := FirstChar;  <========
      Redit.SelLength := Len;       <=========
//and so on
0
 
peterkiersAuthor Commented:
Can you please help me with these procedures:

procedure TMainForm.PlayBtnClick(Sender: TObject);
begin
  if not BeenPaused then
    SpVoice1.Speak(DBRichEdit1.Text, SVSFlagsAsync)   <=====
  else
  begin
   SpVoice1.Resume;
    BeenPaused := False
   end
end;

procedure TMainForm.SetTextStyle(FirstChar, Len: Integer; Styles: TFontStyles);
begin
  with DBRichEdit1 do   <=========
  begin
    Lines.BeginUpdate;
    try
      SelStart := FirstChar;
      SelLength := Len;
      SelLength := 0;
    finally
      Lines.EndUpdate
    end
  end
end;

Peter
0
 
peterkiersAuthor Commented:
and i get incompatible types:  TDBRichedit and TComponent
at line:   Redit := PageControl1.ActivePage.Components[i];

P.
0
 
peterkiersAuthor Commented:
I got it. 500 points are comming to you.

Greetings, Peter Kiers
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Sorry for the delay, I was busy and not on line.
I coded on the fly so there was a typo (missing the typecast TDBRichedit(PageControl1.ActivePage.Components[i])
I'm glad that you solved it the same by you (maybe looking at the prevoius code ;-))
Thanx fo the points and best regards.

Ferruccio
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now