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;