Các hàm chuyển đổi kiểu:

Một phần của tài liệu tai lieu lap trinh delphipascal (Trang 38 - 40)

- trừ hai số nguyên

3.5các hàm chuyển đổi kiểu:

Tham khảo thêm các hàm toán học sau:

3.5các hàm chuyển đổi kiểu:

StrToInt(xâu) chuyển nội dung của biến xâu thành số nguyên. FloatToStr(BiếnSốThực) chuyển giá trị của BiếnSốThực thành xâu.

DateToStr(const DateTime: TDateTime): string; chuyển nội dung ngày thành xâu.

function TimeToStr(const DateTime: TDateTime): string; chuyển nội dung thời gian thành xâu.

Vài ví dụ: Vd1:

Bạn hãy tạo một form mới chứa các đối tượng: 1 label, 1 button.

Hoạt động: khi người dùng nháy chuột vào nút lệnh thì ngày hiện tại của máy sẽ xuất hiện trong label, ngày được định dạng theo mẫu: m/d/yyyy

Viết lệnh cho nút lệnh:

procedure TForm1.Button1Click(Sender: TObject); begin

DateSeparator := '-';

ShortDateFormat := 'm/d/yyyy'; Label1.Caption := DateToStr(Date); end;

với date là một hàm trả về ngày hiện tại của máy, cú pháp như sau: function Date: TDateTime;

Giới thiệu về hàm EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;

Hàm này điền các giá trị hour, min, sec, msec vào đối tượng thuộc kiểu TdateTime.

Với phạm vi của các tham số như sau: Hour từ 0 đến 23.

Min và Sec từ 0 đến 59. MSec từ 0 đến 999.

chuyển kiểu xâu thành các kiểu khác:

Routine With Def. Value Exception-less variant Description

Data.FmtBcd.StrToBcd Data.FmtBcd.TryStrToBcd Converts a string to the corresponding binary-coded decimal (BCD) value.

System.SysUtils.StrToBool System.SysUtils.StrToBoolDef System.SysUtils.TryStrToBool Converts a string to a Boolean value.

System.ConvUtils.StrToConvUnit System.ConvUtils.TryStrToConvUnit Parses a string into a value and conversion type.

System.SysUtils.StrToCurr System.SysUtils.StrToCurrDef System.SysUtils.TryStrToCurr Converts a string to a Currency value.

System.SysUtils.StrToDate System.SysUtils.StrToDateDef System.SysUtils.TryStrToDate Converts a string to a System.TDate

value.

System.SysUtils.StrToDateTime System.SysUtils.StrToDateTimeDef System.SysUtils.TryStrToDateTime Converts a string to a

System.TDateTime value.

System.SysUtils.StrToFloat System.SysUtils.StrToFloatDef System.SysUtils.TryStrToFloat Converts a given string to a floating- point value.

System.SysUtils.StrToInt System.SysUtils.StrToIntDef System.SysUtils.TryStrToInt Converts a string that represents an integer (decimal or hex notation) to a number.

System.SysUtils.StrToInt64 System.SysUtils.StrToInt64Def System.SysUtils.TryStrToInt64 Converts a string that represents an integer (decimal or hex notation) to a number.

System.SysUtils.StrToTime System.SysUtils.StrToTimeDef System.SysUtils.TryStrToTime Converts a string to a

System.TDateTime value.

Data.SqlTimSt.StrToSQLTimeStamp Converts a string to a (adsbygoogle = window.adsbygoogle || []).push({});

Data.SqlTimSt.TSQLTimeStamp

value.

System.Val Converts a string to a numeric

Một phần của tài liệu tai lieu lap trinh delphipascal (Trang 38 - 40)