Delphi's naming rules should be noted

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.