?
Solved

Static DBRichEdit vs Dynamic DBRichEdit, part2

Posted on 2010-01-12
4
Medium Priority
?
449 Views
Last Modified: 2012-06-27
Dear experts,

The procedures that I have put in the code-section works fine.
These procedures are calling for a static dbrichedit on a Pagecontrol's tab
(with set Align = alClient).

But now I have deleted the tabsheet with its dbrichedit, and made a
procedure to create a pagecontrol's tab and the dbrichedit dynamicly.

Now the procedures in the code-section don't work anymore because
they call for a static dbrichedit, that I don't have anymore. Because I
have allready asked this question I have received solution from multiple
experts. But I made a decision to go for the solution of Geert Gruwez
because he made a function for finding the active dbrichedit, that I can
use in other procedures too. Only their is one problem it doesn't
work! Can someone help me to make it work.

This is the code:

function TMainForm.ActiveDBRichEdit: TDBRichEdit;
var tab: TTabSheet;
  I: Integer;
begin
  Result := nil;
  tab := nil;
  if ActiveControl is TDBRichEdit then
    Result := TDBRichEdit(ActiveControl)
  else
  begin
    if ActiveControl is TPageControl then
      tab := PageControl1.ActivePage
    else if ActiveControl is TTabSheet then
      tab := TTabSheet(ActiveControl);
  end;
  if Assigned(tab) then
    for I := 0 to tab.ControlCount-1 do
      if tab.controls[I] is TDBRichEdit then
      begin
        Result := TDBRichEdit(tab.Controls[I]);
        Break;
      end;
end;

procedure TMainForm.PlayBtnClick(Sender: TObject);
var re: TDBRichEdit;
begin
  re := ActiveDBRichEdit;
  if Assigned(re) then
  begin
    if not BeenPaused then
      SpVoice1.Speak(re.Text, SVSFlagsAsync)
    else
    begin
      SpVoice1.Resume;
      BeenPaused := False
    end;
  end;
end;

procedure TMainForm.SetTextHilite(FirstChar, Len: Integer);
var re: TDBRichEdit;
begin
  re := ActiveDBRichEdit;
  if Assigned(re) then
  begin
  re.SelStart := FirstChar;
  re.SelLength := Len;
  end;
end;
(*---------------------------------------------------*)
procedure TMainForm.SetTextStyle(FirstChar, Len: Integer; Styles: TFontStyles);
var re: TDBRichEdit;
begin
  re := ActiveDBRichEdit;
  if Assigned(re) then
   with re do
  begin
    Lines.BeginUpdate;
    try
      SelStart := FirstChar;
      SelLength := Len;
      SelLength := 0;
    finally
      Lines.EndUpdate
    end
  end;
end;

Greetings, Peter Kiers


(*---------------------------------------------------*)
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;
(*---------------------------------------------------*)
procedure TMainForm.PlayBtnClick(Sender: TObject);
begin
  if not BeenPaused then
    SpVoice1.Speak(DBRichEdit1.Text, SVSFlagsAsync)     <===========
  else
  begin
    SpVoice1.Resume;
    BeenPaused := False
  end
end;

Open in new window

0
Comment
Question by:peterkiers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Hypo
ID: 26294929
What is the problem with Geert's functions, what errors do you get? I assume the problem lies within the ActiveDBRichEdit function, but since I can't see all of your code, it's a bit hard to guess what it is...
0
 
LVL 1

Author Comment

by:peterkiers
ID: 26295001
My little example is an example that when the user puts text into the dbrichedit and press the play-button
the speech-component tells through the computer speakers the text. I have also a combobox to select the
voice and 2 spinedits for adjusting the volume and rate. The procedures in the code-section are a part of
that example and the example works fine. But now I use a dynamic dbrichedit and use the code geert send me.
But I here no voice after pressing the play-button and the text that should be highlighted doensn't do that.
I think its in the function too.

Peter
0
 
LVL 12

Accepted Solution

by:
Hypo earned 2000 total points
ID: 26295037
I think then that the problem is that the function ActiveDBRichEdit only returns the richedit that is focused... when you press the button, then it is the button that retreives focus, and ActiveDBRichEdit returns nil... try to change your button to a TSpeedButton instead, as it does not capture focus... If it works then, It will be quite easy to solve your problem...
0
 
LVL 1

Author Comment

by:peterkiers
ID: 26295083
It works. 500 points are comming to you...

Peter Kiers
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question