Goto line and char procedure for richedit

virus05
virus05 used Ask the Experts™
on
This is a double question. I have this code which goes to the line number that I enter in (SForm.SEdit3.Text). My problem now is that I also want the caret to go to the charline in that line number. The charline is entered through (SForm.SEdit4.Text).
My second problem is that I want to check if the entered data for both line and charline is an integer. Because I get an error if the user inputs a char :



procedure TSForm.SBtn3Click(Sender: TObject);
var
  tmpcount, tmpline : word;
begin
  tmpline := strtoint(SForm.SEdit3.Text);
  if tmpline = 0 then begin
     Showmessage('Invalid line number');
     exit;
  end;
  tmpcount := MForm.MMemo.Perform(EM_GETLINECOUNT, 0, 0);
  if tmpline > tmpcount then
     tmpline := tmpcount;
  MForm.MMemo.SelStart := MForm.MMemo.Perform(EM_LINEINDEX, tmpline, 0);
  MForm.MMemo.Perform(EM_SCROLLCARET, 0, 0);
end;


I hope you can all help me... I will give points to the person who can give solutions to both problems... I need a small code if posible...


Thnx in advance... :D
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004
Commented:
first

Procedure RicheditGoTo(ARichedit : TRichedit; ALine, ACharPos : Integer);
begin
  ARichedit.CaretPos := Point(ACharPos-1,ALine-1); //Caret Stands before ACharPos
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEditGoTo(Richedit1,2,7);
end;

second follows

meikl ;-)
Top Expert 2004

Commented:
you can use the OnExitt-event like

procedure TForm1.Edit1Exit(Sender: TObject);
var
  err : Integer;
  dummy : Integer;
begin
  val(edit1.Text,dummy,err);
  if err <> 0 then
  begin
    edit1.SetFocus;
    raise Exception.Create('Not a Valid Value');
  end;
end;


meikl ;-)
:) Or use TSpinEdit instead of TEdit
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

hello virus05, it's not to difficult to prevent the non-numeric charaters form going into an Edit. Get the Edit's OnKeyPress event -

procedure TForm1.EditKeyPress(Sender: TObject; var Key: Char);
begin
if (Key = '-') or
(Ord(Key) = 8) then Exit;
if (Ord(Key) < 48) or (Ord(Key) > 57) then
Key := #0;
end;

Author

Commented:
Ok... I'll try it all first...

Author

Commented:
It works... And its a small code... Heheheh... Thanks...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial