Strictly speaking, StringReplace is a Function and should be called via a variable ... procedure TForm1.Button1Click(Sender: TObject); var msg:string; begin msg:=Edit1.text; msg := StringReplace(msg, 'hai', 'hello', [rfReplaceAll]); showmessage(msg); end; ... the above example works perfectly.