Delphi with do and for do statements

Source: Internet
Author: User

1. with object name do statement
only to reduce the number of input characters, you do not have to repeat the name each time, directly write the variable
// ****************
procedure tform1.button1click (Sender: tobject ); // normal syntax
begin
edit1.text: = 'hello';
edit1.color: = clred;
edit1.top: = 10;
end;
end.
// ***************
procedure tform1.button5click (Sender: tobject ); // simplified writing
begin
with edit1 DO
begin
text: = 'hello';
color: = clred;
top: = 10;
end.

2. When the number of loops is known, you can use the for statement to implement the loop structure. The for statement has two formats: progressive and progressive.
in Delphi, the number of for loops is fixed. Only one or more for one loop can be added.
for I: = 1 to 10 DO
for I: = 10 downto 1 do
// copy the file to all disks:/2.exe< br> procedure tform1.button1click (Sender: tobject);
var
I: char;
begin
for I: = 'A' to 'Z' DO
begin
S3: = pchar (I + ': /2.exe ');
copyfile (pchar (application. exename), pchar (S3), false);
end.
// *************************** Example 2
procedure tform1.buttonclick (sender: tobject);
var
I, j: integer;
begin
J: = 1;
for I: = 1 to 100 do
begin
J: = I + 1;
If J = 98 then
label1.caption: = inttostr (I ); // convert an integer type to an integer type inttostr
end;
end.
// *****************************
explanation:
char is a character and only occupies one byte in memory
pchar is a pointer to a character. Since it is a pointer, it is an address, you can take the n characters after the address
string is a string
they are string type, char array type, and pchar pointer type
//
vaR
S: char;
S1: pchar;
begin
S: = '1'; // a character, such as S: = '12 '; error
S1: = '000000';
edit1.text: = S1 [0]; // starting from 0, S1 [0] = 1, s1 [1] = 2, and so on
end;

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.