Home > Back-end >  Clever programmers with DELPHI
Clever programmers with DELPHI

Time:10-21

Clever programmers use DELPHI which is an ancient word, passed from generation to generation, the programmers and the school of DELPHI convenience and cohesion of the operating system is perfect, I enumerate several DELPHI into below tips to share! Hope that readers have good skills, please don't mention it, take it out to share! Welcome comments!
1, checks if a string is contained in another method of a string
For example: if pos (' ab ', 'abcd') & lt;> 0 then
Messagedlg (' ab is contained in the abcd, mtConfirmation, [mbYes mbNo], 0).
Pos (obj, target) in the target string obj find out first in the first character of a place, if can't find, returns 0.

2, how to make full screen window, similar to the game, and not maximizing the window!
(1) the BorderStyle to bsNone
(2) the Windowstate for wsMaximized
(3) exit can add a button or something, write down the close to quit,

3, the digital formatting output
Format (' % 8.2 f, [123.456]), and return a string '123.46',

4, play a wav file
Use mmsystem;
SndPlaySound (' hello. Wav, SND_FILENAME or SND_SYNC);

5, InputBox, InputQuery and the power of the ShowMessage function
USES dialogs.
Var s, s1: string;
B: Boolean;
The begin
S:=trim (Inputbox (' NewPassword 'and' Password ', 'masterkey'));
B:=s<> "';
S1:=s;
If b, then b:=InputQuery (' Confirm Password 'and' Password ', s1);
If not the or b (s1 & lt;> S) then ShowMessage (' Password Failed);
end;

6, the process of several concerning the operation of the subdirectories
The MkDir (STR); The ChDir (STR); GetDir (DriveID, STR); SetCurrentDir (STR);
IOResult - above a few procedure call successful namely return value 0

7, a visual control into graphic type
Such as a LABEL with the background becomes a TIMAGE picture type, can do it:
Image1. Width:=label1. Width;
Image1. Height:=label1. Height;
Label1. Perform (WM_PAINT, image1. Canvas. Handle, 0).


8, how to get the characters in the ASCII value
Get the ASCII value of the characters, you can use the following statement:
Var: a: integer;
String1: string;
The begin
String1:='ABC';
A:=byte (string [1]). {now gained the ASCII value of the 'A'}
end;

The color of 9, dynamic update DBGrid
For example, if the population of a city is more than 2 million, we let it show as blue, used for DBGrid controls events. OnDrawColumeCell:
Procedure TForm1. DBGrid1DrawColumnCell (Sender: TObject; Const the Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
The begin
If Table1. FieldByName (' Population ') AsInteger & gt; 20000000 then DBGrid1. Canvas. The Font Color:=clBlue;
DBGrid1. DefaultDrawColumnCell (the Rect, DataCol, the Column, the State); end;

10 for command line parameter
1. Get the number of command line parameters: ParamCount function
2. Call ParamStr (0), back to the executable file of the file name (including path)
3. Call ParamStr (n), back to the first n parameters of the contents of the
Example:
Procedure TForm1. FormCreate (Sender: TObject);
Var
Ix: integer;
The begin
Memo1. Lines. The Clear;
If ParamCount=0 then
Memo1. Lines. The Add (' no parameters')
The else
The begin
Memo1. Lines. The Add (' file name: + ParamStr (0));
For ix:=1 to ParamCount do
Memo1. Lines. The Add (ParamStr (ix));
end;
end;

CodePudding user response:

You are too smart, support sharing

CodePudding user response:

Did anyone see!

CodePudding user response:

Sofa was robbed!

CodePudding user response:

Article 6 at least won't compile,

CodePudding user response:

Why???????????

CodePudding user response:

reference 5 floor sailxia reply:
won't be compiled through, article 6
how do you know, you compile?

CodePudding user response:

reference 1st floor tjianliang response:
you're so smart, support sharing

You are too smart

CodePudding user response:

refer to 7th floor KKKKZZZZJJJJ response:
reference 5 floor sailxia reply:
Article 6 at least won't compile,
How do you know ah, you compiled?

oh

CodePudding user response:

Clever not code, but has the ability to use a very simple way to solve practical problems,

CodePudding user response:

Var
A: integer;
String1: string;
The begin
String1:='ABC';
A:=byte (string1 [1]). {now gained the ASCII value of the 'A'}//less 1
end;

CodePudding user response:

Var: a: integer;//& lt; -- -- -- -- -- -- -- can determine this statement?

CodePudding user response:

Clever programmers use DELPHI which is an ancient word, passed from generation to generation the programmers and the school
-- -- -- -- -- -- -- --
The seduced not light, led directly to the have wages have risen in recent years:)

CodePudding user response:

refer to 12 floor sailxia reply:
var: a: integer;//& lt; -- -- -- -- -- -- -- can determine this statement?

That little problem a see will know that, don't dig in, I also changed in the code

CodePudding user response:

Top of the building

CodePudding user response:

Stupidly took points

CodePudding user response:

refer to the original poster KKKKZZZZJJJJ response:
smart programmers use DELPHI which is an ancient word, the programmers and the school passed from generation to generation, the convenience of DELPHI and cohesion of the operating system is perfect, I list a few below DELPHI into a tip to share! Hope that readers have good skills, please don't mention it, take it out to share! Welcome comments!
1, checks if a string is contained in another method of a string
For example: if pos (' ab ', 'abcd') & lt;> 0 then
Messagedlg (...


Correction, about according to judge the problem of color change, the original poster statement, there is a small mistake in the correct code is as follows:
 
Procedure TForm2. DBGrid1DrawColumnCell (Sender: TObject; Const the Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
The begin
If ADOQuery1. FieldByName (' amount ') AsInteger> Then 5000
//DBGrid1. Canvas. Brush. Color:=clRed;//modify row background color
//DBGrid1. Canvas. The Font Color:=clBlue;//modify line font color
DBGrid1. DefaultDrawDataCell (the Rect, the Column Field, the State);

end;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related