نمایش نتایج 1 تا 2 از 2

نام تاپیک: Functionهای یونیت System (*دلفی*)

  1. #1
    کاربر دائمی
    تاریخ عضویت
    بهمن 1381
    پست
    854

    Functionهای یونیت System (*دلفی*)

    تابع قدر مطلق
     function Abs ( Number : Numeric type ) : Numeric type;

    مثال
    var
    float, bigFloat : single;
    int : Integer;
    varVar : Variant;

    begin
    float := -1.5; // Small negative floating point number
    bigFloat := -4.56E100; // Infinite negative floating point number
    int := -7; // Negative integer
    varVar := '-98'; // Variants are converted to floating point!

    ShowMessage('Abs(float) = '+FloatToStr(Abs(float)));
    ShowMessage('Abs(bigFloat) = '+FloatToStr(Abs(bigFloat)));
    ShowMessage('Abs(int) = '+FloatToStr(Abs(int)));

    // Variants are converted into Extended floating types
    float := Abs(varVar);
    ShowMessage('Abs(varVar) = '+FloatToStr(float));
    end;

    تابع Addr
    1  function Addr ( Variable name ) : Pointer; 
    2 function Addr ( Function name ) : Pointer;
    3 function Addr ( Procedure name ) : Pointer;

    مثال
    var
    myString : string;
    ptrString : PString;
    begin
    // Set up variable values
    myString := 'Hello there';

    ptrString := Addr(myString);
    ShowMessage('myString : '+ptrString^);
    end;

    تابع Arctan
     function ArcTan ( const Number : Extended ) : Extended;

    مثال
    var
    float : single;
    begin
    // The ArcTan of PI/2 should give 1.0
    float := ArcTan(PI/2);
    ShowMessage('ArcTan of PI/2 = '+FloatToStr(float));
    end;

    تابع Assigned
    1  function Assigned ( PointerName : Pointer ) : Boolean; 
    2 function Assigned ( ObjectName : TObject ) : Boolean;
    3 function Assigned ( MethodName : Method ) : Boolean;

    مثال
    var
    myPtr : PChar;

    begin
    // Pointer variables are not set to nil by default
    if Assigned(myPtr)
    then ShowMessage('myPtr is not nil')
    else ShowMessage('myPtr is nil');

    // So we must set them to nil to be sure that they are undefined
    myPtr := Nil;
    if Assigned(myPtr)
    then ShowMessage('myPtr is still not nil')
    else ShowMessage('myPtr is nil');
    end;

    تابع BeginThread
    function BeginThread ( SecurityAttr : Pointer; StackSize : LongWord; ThreadFunc : TThreadFunc; Param : Pointer; CreateFlags : LongWord; var ThreadId : LongWord ) : Integer;

    مثال
    تمام یونیت
    unit Unit1;

    interface

    uses
    Forms, Dialogs, Windows, SysUtils;

    type
    TMsgRecord = record
    thread : Integer;
    msg : string[30];
    end;
    TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    end;

    var
    Form1: TForm1;

    Implementation
    {$R *.dfm} // Include form definitions

    ThreadVar // We must allow each thread its own instances
    // of the passed record variable
    msgPtr : ^TMsgRecord;

    // Private thread procedure to show a string
    function ShowMsg(Parameter : Pointer) : Integer;
    begin
    // Set up a 0 return value
    Result := 0;

    // Map the pointer to the passed data
    // Note that each thread has a separate copy of msgPtr
    msgPtr := Parameter;

    // Display this message
    ShowMessagePos('Thread '+IntToStr(msgPtr.thread)+' '+msgPtr.msg,
    200*msgPtr.thread, 100);

    // End the thread
    EndThread(0);
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    var
    id1, id2 : LongWord;
    thread1, thread2 : Integer;
    msg1, msg2 : TMsgRecord;

    begin
    // set up our display messages
    msg1.thread := 1;
    msg1.msg := 'Hello World';
    msg2.thread := 2;
    msg2.msg := 'Goodbye World';

    // Start the first thread running asking for users first name
    thread1 := BeginThread(nil,
    0,
    Addr(ShowMsg),
    Addr(msg1),
    0,
    id1);

    // And also ask for the surname
    thread2 := BeginThread(nil,
    0,
    Addr(ShowMsg),
    Addr(msg2),
    0,
    id2);

    // Ensure that the threads are only closed when all done
    ShowMessagePos('Press this when other dialogs finished.', 200, 300);

    // Finally, tidy up by closing the threads
    CloseHandle(thread1);
    CloseHandle(thread2);
    end;

    end.

    تابع Chr
    1  function Chr ( IntValue : Integer ) : AnsiChar; 
    2 function Chr ( IntValue : Integer ) : WideChar;

    مثال
    var
    tab : char;
    crlf : string;
    begin
    // Show the use of Chr
    tab := Chr(9);
    crlf := Chr(13)+Chr(10);
    ShowMessage('Hello'+tab+'World');
    ShowMessage('');
    ShowMessage('Hello'+crlf+'World');
    ShowMessage('');

    // Show the equivalent use of ^
    tab := ^I; // I = 9th capital of the alphabet
    crlf := ^M^J; // M = 13th, J = 10th letters
    ShowMessage('Hello'+tab+'World');
    ShowMessage('');
    ShowMessage('Hello'+crlf+'World');
    end;

    تابع Copy
    1  function Copy ( Source : string; StartChar, Count : Integer ) : string; 
    2 function Copy ( Source : array; StartIndex, Count : Integer ) : array;

    مثال String copy
    var
    Source, Target : string;

    begin
    Source := '12345678';
    Target := Copy(Source, 3, 4);
    ShowMessage('Target : '+Target);
    end;

    مثال Array copy
    var 
    i : Integer;
    Source, Target : array of Integer;

    begin
    SetLength(Source, 8);

    for i := 1 to 8 do // Build the dynamic source array
    Source[i-1] := i; // Remember that arrays start at index 0

    Target := Copy(Source, 3, 4);

    for i := 0 to Length(Target) -1 do // Display the created array
    ShowMessage('Target['+IntToStr(i)+ '] : '+IntToStr(Target[i]));
    end;

    تابع Cos
     function Cos ( const Number : Extended ) : Extended;

    مثال
    var
    float : single;
    begin
    // The Sine of 60 degrees = 0.5
    float := Cos(PI/3); // = 180/3 = 60 degrees
    ShowMessage('Cos(PI/3) = '+FloatToStr(float));
    end;

    تابع Eof
     function Eof ( var FileHandle : TextFile ) ;

    مثال
    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 in read only mode
    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;

    تابع Eoln
     function Eoln ( var FileHandle : TextFile ) : Boolean;

    مثال
    var
    myFile : TextFile;
    letter : char;
    text : string;

    begin
    // Try to open the Test.txt file for writing to
    AssignFile(myFile, 'Test.txt');
    ReWrite(myFile);

    // Write lines of text to the file
    WriteLn(myFile, 'Hello');
    WriteLn(myFile, 'To you');

    // Close the file
    CloseFile(myFile);

    // Reopen the file for reading
    Reset(myFile);

    // Display the file contents
    while not Eof(myFile) do
    begin
    // Proces one line at a time
    ShowMessage('Start of a new line :');
    while not Eoln(myFile) do
    begin
    Read(myFile, letter); // Read and display one letter at a time
    ShowMessage(letter);
    end;
    ReadLn(myFile, text);
    end;

    // Close the file for the last time
    CloseFile(myFile);
    end;

    تابع Exp
     function Exp ( Number : Extended ) : Extended;

    مثال
    var
    float : Double;
    begin
    // Get the natural logarithm of 2
    float := Ln(2);

    // Show this value
    ShowMessage('Ln(2) = '+FloatToStr(float));

    // Get the exponent of this value - reverses the Ln operation
    float := Exp(float);

    // Show this value
    ShowMessage('Exp(Ln(2)) = '+FloatToStr(float));
    end;

    تابع FilePos
    1  function FilePos ( var FileHandle : File; ) : LongInt; 
    2 function FilePos ( car FileHandle : TextFile; ) ;

    مثال
    var
    myWord, myWord1, myWord2, myWord3 : Word;
    myFile : File of Word;

    begin
    // Try to open the Test.cus binary file in write only mode
    AssignFile(myFile, 'Test.cus');
    ReWrite(myFile);

    // Write a few lines of Word data to the file
    myWord1 := 123;
    myWord2 := 456;
    myWord3 := 789;
    Write(myFile, myWord1, myWord2, myWord3);

    // 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, myWord);
    // Note - FilePos shows the after read position
    ShowMessage('Record '+
    IntToStr(FilePos(myFile))+' = '+
    IntToStr(myWord));
    end;

    // Close the file for the last time
    CloseFile(myFile);
    end;

    تابع FileSize
     function FileSize ( var FileHandle : File; ) : Integer;

    مثال
    var
    myWord, myWord1, myWord2, myWord3 : Word;
    myFile : File of Word;

    begin
    // Try to open the Test.cus binary file in write only mode
    AssignFile(myFile, 'Test.cus');
    ReWrite(myFile);

    // Before writing to the file, show the file size
    ShowMessage('File size = '+IntToStr(FileSize(myFile)));

    // Write a few lines of Word data to the file
    myWord1 := 123;
    myWord2 := 456;
    myWord3 := 789;
    Write(myFile, myWord1, myWord2, myWord3);

    // Before closing the file, show the new file size
    ShowMessage('File size now = '+IntToStr(FileSize(myFile)));

    // Close the file
    CloseFile(myFile);
    end;

    تابع Frac
     function Frac ( const Number : Extended ) : Extended;

    مثال
    begin
    ShowMessage('Round(12.75) = '+IntToStr(Round(12.75)));
    ShowMessage('Trunc(12.75) = '+IntToStr(Trunc(12.75)));
    ShowMessage(' Int(12.75) = '+FloatToStr(Int(12.75)));
    ShowMessage(' Frac(12.75) = '+FloatToStr(Frac(12.75)));
    end;

    تابع GetLastError
     function GetLastError : Integer;

    مثال
    begin
    if DeleteFile('CanDeletMe.txt')
    then ShowMessage('File deleted OK')
    else ShowMessage('File not deleted, error code = '+
    IntToStr(GetLastError));
    end;

    تابع GetMem
    function GetMem ( var StoragePointer : Pointer; StorageSize : Integer ) ;

    مثال
    type
    TRecord = Record
    name : string[10];
    age : Byte;
    end;

    var
    recPointer : ^TRecord;

    begin
    // Allocate storage for three records
    // Note : It is better to use New for this
    // It is used here for illustration purposes only
    GetMem(recPointer, 3 * SizeOf(TRecord));

    // Fill out these 3 records with values
    recPointer.name := 'Brian';
    recPointer.age := 23;

    Inc(recPointer);
    recPointer.name := 'Jim';
    recPointer.age := 55;

    Inc(recPointer);
    recPointer.name := 'Sally';
    recPointer.age := 38;

    // Now display these values
    Dec(recPointer, 2);
    ShowMessageFmt('%s is %d',[recPointer.name, recPointer.age]);
    Inc(recPointer);
    ShowMessageFmt('%s is %d',[recPointer.name, recPointer.age]);
    Inc(recPointer);
    ShowMessageFmt('%s is %d',[recPointer.name, recPointer.age]);
    end;

    تابع Hi
     function Hi ( IntValue : Integer ) : Byte;

    مثال
    var
    i : Integer;

    begin
    i := $2345; // $2345 hex : $23 hi byte, $45 lo byte
    ShowMessage(Format('Integer = $%x', [i]));
    ShowMessage(Format('Hi byte = $%x', [Hi(i)]));
    ShowMessage(Format('Lo byte = $%x', [Lo(i)]));
    end;

    تابع High
     function High ( type or variable ) : Ordinal type;

    مثال
    type
    // Declare character, array and enumerated data types
    TChar = char;
    TArray = array [3..7] of Integer;
    TEnum = (Mon=5, Tue, Wed, Thu, Fri, Sat, Sun);
    TShort = shortstring;

    var
    // Declare variables of the above data types
    myChar : TChar;
    myArray : TArray;
    myEnum : TEnum;
    myShort : TShort;

    begin
    // Show the high values of the types and variables
    ShowMessage('High(TChar) = '+IntToStr(Ord(High(TChar))&#4 1;);
    ShowMessage('High(myChar) = '+IntToStr(Ord(High(myChar))&# 41;);
    ShowMessage('High(TArray) = '+IntToStr(High(TArray)));
    ShowMessage('High(myArray) = '+IntToStr(High(myArray)));
    ShowMessage('High(TEnum) = '+IntToStr(Ord(High(TEnum))&#4 1;);
    ShowMessage('High(myEnum) = '+IntToStr(Ord(High(myEnum))&# 41;);
    ShowMessage('High(TShort) = '+IntToStr(Ord(High(TShort))&# 41;);
    ShowMessage('High(myShort) = '+IntToStr(Ord(High(myShort))& #41;);
    end;

    تابع Int
    function Int ( const Number : Extended ) : Extended;

    مثال
    begin
    ShowMessage('Round(12.75) = '+IntToStr(Round(12.75)));
    ShowMessage('Trunc(12.75) = '+IntToStr(Trunc(12.75)));
    ShowMessage(' Int(12.75) = '+FloatToStr(Int(12.75)));
    ShowMessage(' Frac(12.75) = '+FloatToStr(Frac(12.75)));
    end;

    تابع IOResult
    function IOResult : Integer;

    مثال
    var
    error : Integer;

    begin
    // Try to create a new subdirectory in the current directory
    // Switch off I/O error checking
    {$IOChecks off}
    MkDir('TempDirectory');

    // Did the directory get created OK?
    error := IOResult;
    if error = 0
    then ShowMessage('Directory created OK')
    else ShowMessageFmt('Directory creation failed with error %d',[error]);

    // Try to create the directory again - this will fail!
    MkDir('TempDirectory');
    error := IOResult; // Save the return code
    if error = 0
    then ShowMessage('Directory created OK again')
    else ShowMessageFmt('Repeat creation failed with error %d',[error]);

    // Delete the directory to tidy up
    RmDir('TempDirectory');

    // Switch IO checking back on
    {$IOChecks on}
    end;

    تابع IsMultiThread
    function IsMultiThread : Boolean;

    مثال یونیت کامل
    unit Unit1;

    interface

    uses
    Forms, Dialogs, Windows, SysUtils;

    type
    TMsgRecord = record
    msg : string[30];
    end;
    TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    end;

    var
    Form1: TForm1;

    Implementation
    {$R *.dfm} // Include form definitions

    ThreadVar // We must allow each thread its own instances
    // of the passed record variable
    msgPtr : ^TMsgRecord;

    // Private thread procedure to show a string
    function ShowMsg(Parameter : Pointer) : Integer;
    begin
    // Set up a 0 return value
    Result := 0;

    // Map the pointer to the passed data
    // Note that each thread has a separate copy of msgPtr
    msgPtr := Parameter;

    // Display this message
    ShowMessagePos('Thread message : '+msgPtr.msg, 200, 100);

    // End the thread
    EndThread(0);
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    var
    id1 : LongWord;
    thread1 : Integer;
    msg1 : TMsgRecord;
    showMsgFunc : TThreadFunc;

    begin
    // Set up the thread function
    showMsgFunc := Addr(ShowMsg);

    // Set up our display messages
    msg1.msg := 'Hello World';

    // Inidicate that we are not running a thread
    if IsMultiThread
    then ShowMessage('Multi-threaded')
    else ShowMessage('Single threaded');

    // Start the first thread running asking for users first name
    thread1 := BeginThread(nil,
    0,
    showMsgFunc,
    Addr(msg1),
    0,
    id1);

    // Inidicate that we are running a thread
    if IsMultiThread
    then ShowMessage('Multi-threaded')
    else ShowMessage('Single threaded');

    // Ensure that the thread is only closed when all done
    ShowMessagePos('Press this when thread dialog finished.', 200, 300);

    // Finally, tidy up by closing the threads
    CloseHandle(thread1);
    end;

    end.

    تابع Length
    1  function Length ( const SourceString : string ) : Integer; 
    2 function Length ( const SourceArray : array ) : Integer;

    مثال
    var
    openArray : array of char;
    fixedArray : array[2..4] of Integer;
    multiArray : array[2..4, 1..9] of Integer;
    shortStr : shortstring;
    longStr : string;
    i : Integer;

    begin
    // Define the length of the open array
    SetLength(openArray, 17);

    // Show the length of the arrays
    ShowMessage('Length of openArray = '+IntToStr(Length(openArray))) ;
    ShowMessage('Length of fixedArray = '+IntToStr(Length(fixedArray))&#41 ;;
    ShowMessage('Length of multiArray = '+IntToStr(Length(multiArray))&#41 ;;

    // Assign to the strings
    shortStr := 'ABCDEFGH';
    longStr := '12345678901234567890';
    ShowMessage('Length of shortStr = '+IntToStr(Length(shortStr)));
    ShowMessage('Length of longStr = '+IntToStr(Length(longStr)));

    // Display one letter at a time from the short string
    for i := 1 to Length(shortStr) do
    ShowMessage('Letter '+IntToStr(i)+' = '+shortStr[i]);
    end;

    تابع Ln
    function Ln ( Number : Extended ) : Extended;

    مثال
    var
    float : Double;
    begin
    // Get the natural logarithm of 2
    float := Ln(2);

    // Show this value
    ShowMessage('Ln(2) = '+FloatToStr(float));

    // Get the exponent of this value - reverses the Ln operation
    float := Exp(float);

    // Show this value
    ShowMessage('Exp(Ln(2)) = '+FloatToStr(float));
    end;

    تابع Lo
    [code] function Lo ( IntValue : Integer ) : Byte;[/code]
    مثال
    var
    i : Integer;

    begin
    i := $2345; // $2345 hex : $23 hi byte, $45 lo byte
    ShowMessage(Format('Integer = $%x', [i]));
    ShowMessage(Format('Hi byte = $%x', [Hi(i)]));
    ShowMessage(Format('Lo byte = $%x', [Lo(i)]));
    end;

    تابع
    function Low ( type or variable ) : Ordinal type; 

    مثال
    type
    // Declare character, array and enumerated data types
    TChar = char;
    TArray = array [3..7] of Integer;
    TEnum = (Mon=5, Tue, Wed, Thu, Fri, Sat, Sun);
    TShort = shortstring;

    var
    // Declare variables of the above data types
    myChar : TChar;
    myArray : TArray;
    myEnum : TEnum;
    myShort : TShort;

    begin
    // Show the low values of the types and variables
    ShowMessage('Low(TChar) = '+IntToStr(Ord(Low(TChar))&#41 ;);
    ShowMessage('Low(myChar) = '+IntToStr(Ord(Low(myChar))&#4 1;);

    ShowMessage('Low(TArray) = '+IntToStr(Low(TArray)));
    ShowMessage('Low(myArray) = '+IntToStr(Low(myArray)));
    ShowMessage('High(myArray) = '+IntToStr(High(myArray)));

    ShowMessage('Low(TEnum) = '+IntToStr(Ord(Low(TEnum))&#41 ;);
    ShowMessage('Low(myEnum) = '+IntToStr(Ord(Low(myEnum))&#4 1;);
    ShowMessage('High(myEnum) = '+IntToStr(Ord(High(myEnum))&# 41;);

    ShowMessage('Low(TShort) = '+IntToStr(Ord(Low(TShort))&#4 1;);
    ShowMessage('Low(myShort) = '+IntToStr(Ord(Low(myShort))&# 41;);
    end;

    تابع Odd
    function Odd ( Number : Integer | Int64 ) : Boolean; 

    مثال
    var
    i : Integer;

    begin
    // Display all odd numbers in the range 1 to 9
    for i := 1 to 9 do
    if Odd(i) then ShowMessageFmt('%d is odd',[i]);
    end;

    تابع Ord
    1  function Ord ( Arg : AnsiChar | Char | WideChar | Enumeration | Integer ) : Integer; 
    2 function Ord ( Arg : Int64 ) : Int64

    مثال
    var
    A : AnsiChar;
    C : Char;
    W : WideChar;
    E : Boolean;
    I : Integer;
    I64 : Int64;

    begin
    // Set the ordinal type values
    A := 'A';
    C := 'C';
    W := 'W';
    E := True;
    I := 22;
    I64 := 64;

    // And show the value of each
    ShowMessage('A = '+IntToStr(Ord(A)));
    ShowMessage('C = '+IntToStr(Ord(C)));
    ShowMessage('W = '+IntToStr(Ord(W)));
    ShowMessage('E = '+IntToStr(Ord(E)));
    ShowMessage('I = '+IntToStr(Ord(I)));
    ShowMessage('I64 = '+IntToStr(Ord(I64)));
    end;

    تابع ParamCount
     function ParamCount : Integer;

    مثال
    var
    cmd : string;
    i : Integer;

    begin
    // Before running this code, use the Run/parameters menu option
    // to set the following command line parameters : -parm1 -parm2
    cmd := CmdLine;
    ShowMessage(cmd); // Show the execution command + parameters

    // How many parameters were passed?
    ShowMessage('There are '+IntToStr(ParamCount)+' parameters');

    // Show these parameters - note that the 0th parameter is the
    // execution command on Windows
    for i := 0 to ParamCount do
    ShowMessage('Parameter '+IntToStr(i)+' = '+ParamStr(i));
    end;

    تابع ParamStr
    function ParamStr ( ParmIndex : Integer ) : string;

    مثال
    var
    cmd : string;
    i : Integer;

    begin
    // Before running this code, use the Run/parameters menu option
    // to set the following command line parameters : -parm1 -parm2

    // Show these parameters - note that the 0th parameter is the
    // execution command on Windows
    for i := 0 to ParamCount do
    ShowMessage('Parameter '+IntToStr(i)+' = '+ParamStr(i));
    end;

    تابع Pi
     function Pi : Extended;

    مثال
    var
    myPi : Extended;
    diam : Integer;
    begin
    diam := 10;

    // Show circumference and the area of a circle
    // with diameter - 10 cm
    ShowMessage(' Diameter = '+IntToStr(diam));
    ShowMessage('Circumference = '+FloatToStr(Pi*diam));
    ShowMessage(' Area = '+FloatToStr(Pi*(diam/2)*(diam/2)));
    end;

    تابع Pos
     function Pos ( const Needle, HayStack : string ) : Integer;

    تابع Pred
    function Pred ( const Ordinal Value ) : Ordinal type;

    مثال
    type
    TSuit = (Hearts, Clubs, Diamonds, Spades);

    var
    Character : char;
    Number : Integer;
    Card : TSuit;

    begin
    // We can decrement characters
    Character := 'B';

    ShowMessage('Character : '+Character);
    Character := Pred(Character);
    ShowMessage('Character-1 : '+Character);

    // We can decrement numbers
    Number := 23;

    ShowMessage('Number : '+IntToStr(Number));
    Number := Pred(Number);
    ShowMessage('Number-1 : '+IntToStr(Number));

    // We can decrement enumerations
    Card := Clubs;

    ShowMessage('Card starts at Clubs');
    Card := Pred(Card);
    if Card = Hearts then ShowMessage('Card is now Hearts');
    if Card = Clubs then ShowMessage('Card is now Clubs');
    if Card = Diamonds then ShowMessage('Card is now Diamonds');
    if Card = Spades then ShowMessage('Card is now Spades');
    end;

    تابع Random
    1  function Random : Extended; 
    2 function Random ( LimitPlusOne : Integer ) : Integer;

    مثال
    var
    float : single;
    int : Integer;
    i : Integer;

    begin
    // Get floating point random numbers in the range 0 <= Number < 1.0
    for i := 1 to 5 do
    begin
    float := Random;
    ShowMessage('float = '+FloatToStr(float));
    end;

    ShowMessage('');

    // Get an integer random number in the range 1..100
    for i := 1 to 5 do
    begin
    int := 1 + Random(100); // The 100 value gives a range 0..99
    ShowMessage('int = '+IntToStr(int));
    end;
    end;

    تابع Round
     function Round ( const Number : Extended ) : Int64;

    مثال
    begin
    ShowMessage('Round(12.75) = '+IntToStr(Round(12.75)));
    ShowMessage('Trunc(12.75) = '+IntToStr(Trunc(12.75)));
    ShowMessage(' Int(12.75) = '+FloatToStr(Int(12.75)));
    ShowMessage(' Frac(12.75) = '+FloatToStr(Frac(12.75)));
    end;

    تابع SeekEof
    function SeekEof ( {var FileHandle : File} ) : Boolean;

    مثال
    var
    myFile : TextFile;
    number : Integer;

    begin
    // Try to open the Test.txt file for writing to
    AssignFile(myFile, 'Test.txt');
    ReWrite(myFile);

    // Write numbers in a string
    WriteLn(myFile, '1 2 3 4 '); // White space at the end

    // Write numbers as separate parameters
    WriteLn(myFile, 5, ' ', 6, ' ', 7, ' '); // Results in '5 6 7 ' text

    // Close the file
    CloseFile(myFile);

    // Reopen the file for reading
    Reset(myFile);

    // Display the file contents
    while not SeekEof(myFile) do
    begin
    // Read numbers one at a time
    ShowMessage('Start of a new line');
    while not SeekEoln(myFile) do
    begin
    Read(myFile, number);
    ShowMessage(IntToStr(number));
    end;

    // Now move to the next line
    ReadLn(myFile);
    end;

    // Close the file for the last time
    CloseFile(myFile);
    end;

    تابع SeekEoln
    function SeekEoln ( {var FileHandle : File} ) : Boolean;

    مثال
    var
    myFile : TextFile;
    number : Integer;

    begin
    // Try to open the Test.txt file for writing to
    AssignFile(myFile, 'Test.txt');
    ReWrite(myFile);

    // Write numbers in a string
    WriteLn(myFile, '1 2 3 4 '); // White space at the end

    // Write numbers as separate parameters
    WriteLn(myFile, 5, ' ', 6, ' ', 7, ' '); // Results in '5 6 7 ' text

    // Close the file
    CloseFile(myFile);

    // Reopen the file for reading
    Reset(myFile);

    // Display the file contents
    while not SeekEof(myFile) do
    begin
    // Read numbers one at a time
    ShowMessage('Start of a new line');
    while not SeekEoln(myFile) do
    begin
    Read(myFile, number);
    ShowMessage(IntToStr(number));
    end;

    // Now move to the next line
    ReadLn(myFile);
    end;

    // Close the file for the last time
    CloseFile(myFile);
    end;

    تابع Sin
    function Sin ( const Number : Extended ) : Extended;

    مثال
    var
    float : single;
    begin
    // The Sine of 30 degrees = 0.5
    float := Sin(PI/6); // = 180/6 = 30 degrees
    ShowMessage('Sin(PI/6) = '+FloatToStr(float));
    end;

    تابع SizeOf
    1  function SizeOf ( Variable : Any type ) : Integer; 
    2 function SizeOf ( Type ) : Integer;

    مثال
    var
    intNumber : Integer;
    extNumber : Extended;
    sentence : string;

    begin
    // Display the sizes of a number of data types
    ShowMessageFmt(' SizeOf(Integer) = %d',[SizeOf(Integer)]);
    ShowMessageFmt('SizeOf(intNumber) = %d',[SizeOf(intNumber)]);
    ShowMessageFmt(' SizeOf(Extended) = %d',[SizeOf(Extended)]);
    ShowMessageFmt('SizeOf(extNumber) = %d',[SizeOf(extNumber)]);

    // String types and variables are pointers to the actual strings
    sentence := 'A long sentence, certainly longer than 4';
    ShowMessageFmt(' SizeOf(string) = %d',[SizeOf(string)]);
    ShowMessageFmt(' SizeOf(sentence) = %d',[SizeOf(sentence)]);
    end;

    تابع Slice
    function Slice ( SourceArray : array; Count : Integer ) : array;

    مثال
    var
    i : Integer;
    Source : array[0..4] of Integer;

    begin
    // Create the source array with 0..4 values for elements 0..4
    for i := 0 to 4 do
    Source[i] := i;

    // Use the Slice command to pass just the first 3 elements of Source as
    // an open array to the ShowSlice procedure below.
    ShowSlice(Slice(Source, 3));
    end;

    // Show an array of unknown size - it is passed as an 'Open' array
    procedure TForm1.ShowSlice(SubArray : array of Integer);
    var
    i : Integer;

    begin
    // Show every element of this array
    for i := 0 to Length(SubArray)-1 do
    ShowMessage('SubArray['+IntToStr(i&#41 ;+'] : '+ IntToStr(SubArray[i]));
    end;

    تابع Sqr
    1  function Sqr ( Number :  Integer ) : Integer; 
    2 function Sqr ( Number : Int64 ) : Int64;
    3 function Sqr ( Number : Extended ) : Extended;

    مثال
    var
    number, squared : Byte;
    float : Extended;

    begin
    // The square of 15 = 225
    number := 15;
    squared := Sqr(number);
    ShowMessageFmt('%d squared = %d',[number, squared]);

    // The square of 17 = 289
    // But result exceeds byte size, so result = 289 MOD 256 = 33
    number := 17;
    squared := Sqr(number);
    ShowMessageFmt('%d squared = %d (see code above)',[number, squared]);

    // The square of infinity is still infinity
    float := Infinity;
    float := Sqr(float);
    ShowMessageFmt('Infinity squared = %f',[float]);
    end;

    تابع Sqrt
    function Sqrt ( Number :  Extended ) : Extended;

    مثال
    var
    number, squareRoot : Extended;

    begin
    // The square root of 225 = 15
    number := 225;
    squareRoot := Sqrt(number);
    ShowMessageFmt('Square root of %f = %f',[number, squareRoot]);

    // The square root of 3.456 = 1.859...
    number := 3.456;
    squareRoot := Sqrt(number);
    ShowMessageFmt('Square root of %7.3f = %12.12f',[number, squareRoot]);

    // The square root of infinity is still infinity
    number := Infinity;
    number := Sqrt(number);
    ShowMessageFmt('Square root of Infinity = %f',[number]);
    end;

    تابع StringOfChar ( Re
    function StringOfChar ( RepeatCharacter : Char; RepeatCount : Integer ) : string;

    مثال
    var
    text, line : string;

    begin
    // Write a heading with -'s as underline characters
    text := '1.An introduction to life as we know it';
    line := StringOfChar('-', Length(text));

    // Display our underlined heading
    ShowMessage(text);
    ShowMessage(line);
    end;

    تابع StringToWideChar
    function StringToWideChar ( const SourceString : string; TargetBuffer : PWideChar; TargetSize : Integer ) : PWideChar;

    مثال
    var
    wideChars : array[0..11] of WideChar;
    myString : String;

    begin
    // Set up our string
    myString := 'Hello World';

    // Copy to a WideChar format in our array
    StringToWideChar(myString, wideChars, 12);

    // Show what the copy gave
    ShowMessage(WideCharToString(wideChars&#41 ;);
    end;

    تابع Succ
     function Succ ( const Ordinal Value ) : Ordinal type;

    مثال
    type
    TSuit = (Hearts, Clubs, Diamonds, Spades);

    var
    Character : char;
    Number : Integer;
    Card : TSuit;

    begin
    // We can increment characters
    Character := 'A';

    ShowMessage('Character : '+Character);
    Character := Succ(Character);
    ShowMessage('Character+1 : '+Character);

    // We can increment numbers
    Number := 23;

    ShowMessage('Number : '+IntToStr(Number));
    Number := Succ(Number);
    ShowMessage('Number+1 : '+IntToStr(Number));

    // We can increment enumerations
    Card := Clubs;

    ShowMessage('Card starts at Clubs');
    Card := Succ(Card);
    if Card = Hearts then ShowMessage('Card is now Hearts');
    if Card = Clubs then ShowMessage('Card is now Clubs');
    if Card = Diamonds then ShowMessage('Card is now Diamonds');
    if Card = Spades then ShowMessage('Card is now Spades');
    end;

    تابع Trunc
     function Trunc ( const Number : Extended ) : Integer;

    مثال
    begin
    ShowMessage('Round(12.75) = '+IntToStr(Round(12.75)));
    ShowMessage('Trunc(12.75) = '+IntToStr(Trunc(12.75)));
    ShowMessage(' Int(12.75) = '+FloatToStr(Int(12.75)));
    ShowMessage(' Frac(12.75) = '+FloatToStr(Frac(12.75)));
    end;

    تابع UpCase
     function UpCase ( Letter : Char ) : Char;

    مثال
    var
    lower, upper : char;

    begin
    // Convert a lower case letter to upper case
    lower := 'g';
    upper := UpCase(lower);

    // Display these letters
    ShowMessage('lower = '+lower+' upper = '+upper);
    end;

    تابع WideCharToString
     function WideCharToString ( Source : PWideChar; ) : string;

    مثال
    var
    wideCharArray : array[0..5] of WideChar;
    myString : String;

    begin
    // Set up our WideChar array
    wideCharArray[0] := 'H';
    wideCharArray[1] := 'e';
    wideCharArray[2] := 'l';
    wideCharArray[3] := 'l';
    wideCharArray[4] := 'o';
    wideCharArray[5] := #0; // Terminates WideChar strings

    // Copy to a normal string
    myString := WideCharToString(wideCharArray);

    // Show what the copy gave
    ShowMessage(myString);
    end;

    توضیحات فارسی هر Function رو اگه اساتید کمک کنند همین جا پست می کنم

  2. #2
    UNIX is simple. It just takes a genius to understand its simplicity
    -- Dennis Ritchie

تاپیک های مشابه

  1. سوالاتی درباره SP و Functionها
    نوشته شده توسط In_Chan_Nafar در بخش SQL Server
    پاسخ: 1
    آخرین پست: چهارشنبه 03 مرداد 1386, 23:01 عصر
  2. درج دستور system در c تحت ویندوز
    نوشته شده توسط نوشین بشیری در بخش برنامه نویسی با زبان C و ++C
    پاسخ: 0
    آخرین پست: چهارشنبه 30 خرداد 1386, 10:27 صبح
  3. چگونه از رویدادهای System.net استفاده کنم؟
    نوشته شده توسط javad2000 در بخش VB.NET
    پاسخ: 11
    آخرین پست: دوشنبه 14 خرداد 1386, 08:22 صبح
  4. منبع فرسی برای توضیح کامل System. ...
    نوشته شده توسط eyes_shut_number1 در بخش VB.NET
    پاسخ: 4
    آخرین پست: چهارشنبه 09 خرداد 1386, 10:42 صبح
  5. System.io
    نوشته شده توسط Ehsan Rafsanjani در بخش VB.NET
    پاسخ: 0
    آخرین پست: یک شنبه 22 آبان 1384, 13:13 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •