Your extracted procedure is not quite right. You pass a rect that you don't use. You pass rw
and j
as var parameters, but it looks like a single by value parameter really. So I'd have it like this:
procedure Highlight(Edit1, Edit5: TEdit; StringGrid: TStringGrid; rw: Integer);
begin
Edit5.Text := IntToStr(rw);
StringGrid.Selection := Rect(0, rw, 5, rw);
Edit1.SetFocus;
end;
Call it like this:
Highlight(Edit1, Edit5, StringGrid1, j);
Now, this assumes that you sometimes need to pass different controls to the procedure. If you always pass the same controls, then make the procedure be a method of your class:
procedure TMyForm.Highlight(rw: Integer);
begin
Edit5.Text := IntToStr(rw);
StringGrid.Selection := Rect(0, rw, 5, rw);
Edit1.SetFocus;
end;
And call it like this:
Highlight(j);
I'm assuming here that the value you pass as j
can vary. So it should be a parameter. That's the sort of reasoning that you need to use when deciding whether something should be a parameter, or use a field. Ask yourself if you will always pass the same value when calling the method?
Finally, you are making life hard by not naming your variables. How can a reader of the code know what is so special about Edit5
and why it is treated differently from Edit1
. Give names to your variables.