Link to home
Start Free TrialLog in
Avatar of virus05
virus05

asked on

Goto line and char procedure for richedit

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
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ;-)
Avatar of stepashka
stepashka

:) Or use TSpinEdit instead of TEdit
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;
Avatar of virus05

ASKER

Ok... I'll try it all first...
Avatar of virus05

ASKER

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