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_GET LINECOUNT, 0, 0);
if tmpline > tmpcount then
tmpline := tmpcount;
MForm.MMemo.SelStart := MForm.MMemo.Perform(EM_LIN EINDEX, tmpline, 0);
MForm.MMemo.Perform(EM_SCR OLLCARET, 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
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_GET
if tmpline > tmpcount then
tmpline := tmpcount;
MForm.MMemo.SelStart := MForm.MMemo.Perform(EM_LIN
MForm.MMemo.Perform(EM_SCR
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:) 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;
procedure TForm1.EditKeyPress(Sender
begin
if (Key = '-') or
(Ord(Key) = 8) then Exit;
if (Ord(Key) < 48) or (Ord(Key) > 57) then
Key := #0;
end;
ASKER
Ok... I'll try it all first...
ASKER
It works... And its a small code... Heheheh... Thanks...
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 ;-)