Beginners of Delphi, to their own hand-made procedures, functions, the name of the process will not be too concerned. But be aware that your casual name can sometimes cause unexpected problems. For example: Create a new form, add a EDIT1, clear its contents, plus a LABEL1 and BUTTON1.
The BUTTON1 button code is
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.caption:=inttostr(sqr(strtoint(edit1.text)));//注意函数SQR
end;
Execute, enter a number in edit, the label shows its square value, all normal. Well, save for Sqr.pas and SS. DPR. Again, there will be an error message out
[Error] Sqr.pas (30):. Expected but (found)
"[Fatal Error] SS.DPR (5): Could not compile used unit Sqr.pas"
The original program in the execution of SQR, did not call the function Sqr, but found the Sqr.pas. Save the program as a Notsqr.pas and rerun it, then return to normal. So programs, functions, procedures do not duplicate the name, especially in the program. Also note that the custom function priority is greater than the reserved function, and in the example above, a function called Sqr is customized.
function sqr(input:integer):integer;
begin
sqr:=input+1;
end;
If you enter 2 in edit, press the button and the label displays 3 instead of 4.