here it's some basic thing in delphi i judge the beginer must now
//////////messagebox multiline
procedure TForm1.Button1Click(Sender: TObject);
begin
MessageBox(handle, 'First line'+#10+#13+'Second line'+#10+#13+'Third line', 'Multiline MessageBox', MB_OK);
end;
/////////////////////end messagebox multiline
////////////loop for
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
for i := 0 to 3 do
begin
showmessage('test...' + IntToStr(i));
end;
end;
//////////////////end loop for
///////loop while
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
i :=0;
while i < 4 do
begin
showmessage('test' + IntToStr(i));
i := i + 1;
end;
end;
///////////end loop while
///////////////////array declaration
procedure TForm1.Button1Click(Sender: TObject);
const Digits: array[0..9] of Char = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
var
i : Integer;
begin
for i:=0 to High(Digits) do
showmessage(Digits[i]);
end;
///////////end array declaration
////////////dynamic array test
procedure TForm1.Button1Click(Sender: TObject);
var
A : array of Integer;
begin
SetLength(A, 1);
A[0] :=10;
showmessage(IntToStr(A[0]));
end;
//////////end dynamic array test
//function make string
function MakeStr(const Args: array of const): string;
const
BoolChars: array[Boolean] of Char = ('F', 'T');
var
I: Integer;
begin
Result := '';
for I := 0 to High(Args) do
with Args[I] do
case VType of
vtInteger: Result := Result + IntToStr(VInteger);
vtBoolean: Result := Result + BoolChars[VBoolean];
vtChar: Result := Result + VChar;
vtExtended: Result := Result + FloatToStr(VExtended^);
vtString: Result := Result + VString^;
vtPChar: Result := Result + VPChar;
vtObject: Result := Result + VObject.ClassName;
vtClass: Result := Result + VClass.ClassName;
vtAnsiString: Result := Result + string(VAnsiString);
vtCurrency: Result := Result + CurrToStr(VCurrency^);
vtVariant: Result := Result + string(VVariant^);
vtInt64: Result := Result + IntToStr(VInt64^);
end;
end;
//end function make string
//use this function like bellow procedure
procedure TForm1.Button1Click(Sender: TObject);
var
mystr: string;
begin
mystr := MakeStr(['test', 100, ' ', True, 3.14159, TForm]);
showmessage(mystr);
end;
////////////function declaration
function Calc(X, Y: Integer): Integer;
begin
Calc := X + Y;
end;
type TFunction = function(X, Y: Integer): Integer;
const MyFunction: TFunction = Calc;
///////end function declaration
//test this function
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(IntToStr(MyFunction(5, 7)));
end;
//or
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(IntToStr(Calc(5, 7)));
end;
///////////end test this function
///////out parameter procedure
procedure GetInfo(out Info: string);
begin
Info := 'my value to be return';
end;
/////////end out parameter procedure
procedure TForm1.Button1Click(Sender: TObject);
var
mystr: string;
begin
GetInfo(mystr);
showmessage(mystr);
end;
////////////read text file
procedure TForm1.Button1Click(Sender: TObject);
var
myFile : TextFile;
text : string;
begin
AssignFile(myFile, 'Test.txt');
// Reopen the file for reading
Reset(myFile);
// Display the file contents
while not Eof(myFile) do
begin
ReadLn(myFile, text);
ShowMessage(text);
end;
// Close the file for the last time
CloseFile(myFile);
end;
//////////end read text file
//////write text file
procedure TForm1.Button1Click(Sender: TObject);
var
myFile : TextFile;
text : string;
begin
// Try to open the Test.txt file for writing to
AssignFile(myFile, 'Test.txt');
ReWrite(myFile);
// Write a couple of well known words to this file
WriteLn(myFile, 'Hello');
WriteLn(myFile, 'World');
// Close the file
CloseFile(myFile);
// Reopen the file for reading
Reset(myFile);
// Display the file contents
while not Eof(myFile) do
begin
ReadLn(myFile, text);
ShowMessage(text);
end;
// Close the file for the last time
CloseFile(myFile);
end;
//////////end write text file
///////write append text file
procedure TForm1.Button3Click(Sender: TObject);
var
myFile : TextFile;
text : string;
begin
AssignFile(myFile, 'Test.txt');
Append(myFile);
WriteLn(myFile, 'my append string');
WriteLn(myFile, 'my other append string');
CloseFile(myFile);
end;
//////////end write append text file
/////////write binary file
procedure writebf();
type
TCustomer = Record
name : string[20];
age : Integer;
male : Boolean;
end;
var
myFile : File of TCustomer; // A file of customer records
customer : TCustomer; // A customer record variable
begin
// Try to open the Test.cus binary file for writing to
AssignFile(myFile, 'Test.cus');
ReWrite(myFile);
// Write a couple of customer records to the file
customer.name := 'Fred Bloggs';
customer.age := 21;
customer.male := true;
Write(myFile, customer);
customer.name := 'Jane Turner';
customer.age := 45;
customer.male := false;
Write(myFile, customer);
// Close the file
CloseFile(myFile);
// Reopen the file in read only mode
FileMode := fmOpenRead;
Reset(myFile);
// Display the file contents
while not Eof(myFile) do
begin
Read(myFile, customer);
if customer.male
then ShowMessage('Man with name '+customer.name+
' is '+IntToStr(customer.age))
else ShowMessage('Lady with name '+customer.name+
' is '+IntToStr(customer.age));
end;
// Close the file for the last time
CloseFile(myFile);
end;
//////////end write binary file
////////readwriteblock binary file
procedure readwriteblockbf();
var
myFile : File;
byteArray : array[1..8] of byte;
oneByte : byte;
i, count : Integer;
begin
// Try to open the Test.byt file for writing to
AssignFile(myFile, 'Test.byt');
ReWrite(myFile, 4); // Define a single 'record' as 4 bytes
// Fill out the data array
for i := 1 to 8 do
byteArray[i] := i;
// Write the data array to the file
BlockWrite(myFile, byteArray, 2); // Write 2 'records' of 4 bytes
// Fill out the data array with different data
for i := 1 to 4 do
byteArray[i] := i*i; // Value : 1, 4, 9, 16
// Write only the first 4 items from the data array to the file
BlockWrite(myFile, byteArray, 1); // Write 1 record of 4 bytes
// Close the file
CloseFile(myFile);
// Reopen the file for reading only
FileMode := fmOpenRead;
Reset(myFile, 1); // Now we define one record as 1 byte
// Display the file contents
// Start with a read of the first 6 bytes. 'count' is set to the
// actual number read
ShowMessage('Reading first set of bytes :');
BlockRead(myFile, byteArray, 6, count);
// Display the byte values read
for i := 1 to count do
ShowMessage(IntToStr(byteArray[i]));
// Now read one byte at a time to the end of the file
ShowMessage('Reading remaining bytes :');
while not Eof(myFile) do
begin
BlockRead(myFile, oneByte, 1); // Read and display one byte at a time
ShowMessage(IntToStr(oneByte));
end;
// Close the file for the last time
CloseFile(myFile);
end;
/////////end readwriteblock binary
//////////reverse text file
procedure reversetextfile();
var
fileData : TStringList;
saveLine : String;
lines, i : Integer;
begin
fileData := TStringList.Create; // Create the TSTringList object
fileData.LoadFromFile('Test.txt'); // Load from Testing.txt file
// Reverse the sequence of lines in the file
lines := fileData.Count;
for i := lines-1 downto (lines div 2) do
begin
saveLine := fileData[lines-i-1];
fileData[lines-i-1] := fileData[i];
fileData[i] := saveLine;
end;
// Now display the file
for i := 0 to lines-1 do
ShowMessage(fileData[i]);
fileData.SaveToFile('Test.txt'); // Save the reverse sequence file
end;
////////end reverse text file
next time i'll attack ado and socket
if you have any trick about that, i'm happy to learn