Difference between revisions of "Typecast"
From Lazarus wiki
Jump to navigationJump to search (→Type conversion: Function -> Method) |
(→Type conversion: enumerated type -> string) |
||
Line 19: | Line 19: | ||
<td>Real</td> | <td>Real</td> | ||
<td>implicit</td> | <td>implicit</td> | ||
− | <td></td> | + | <td>assignment statement</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
Line 62: | Line 62: | ||
<td>String</td> | <td>String</td> | ||
<td>implicit</td> | <td>implicit</td> | ||
− | <td></td> | + | <td>assignment statement</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
Line 75: | Line 75: | ||
<td>explicit</td> | <td>explicit</td> | ||
<td>Chr<br/>AnsiChar(byte-value)</td> | <td>Chr<br/>AnsiChar(byte-value)</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>Enumerated type</td> | ||
+ | <td>String</td> | ||
+ | <td>explicit</td> | ||
+ | <td>WriteStr(string-var,enum-var)</td> | ||
</tr> | </tr> | ||
</table> | </table> | ||
Line 124: | Line 130: | ||
<td>Longword</td> | <td>Longword</td> | ||
<td>Cardinal</td> | <td>Cardinal</td> | ||
− | <td>implicit | + | <td>implicit</td> |
− | <td></td> | + | <td>assignment statement</td> |
</tr> | </tr> | ||
<tr> | <tr> |
Revision as of 12:03, 12 June 2016
│
Deutsch (de) │
English (en) │
français (fr) │
русский (ru) │
Converting values from variables with a lower value range data type to variables with higher value range data type is done automatically (implicit).
A value is converted by a variable of higher-value data type into a variable with a data type of lower values via a cast or function call, and if the value does not fit into the variable of the target data type then data will be lost.
Type conversion
Source data type | Target data type | Type of type conversion | Method |
Integer | Real | implicit | assignment statement |
Real | Integer | explicit: Cut off the fractional part Round fractional part |
Trunc Round |
Integer | String | explicit | IntToStr |
Real | String | explicit | FloatToStr FloatToStrF |
String | Integer | explicit | StrToInt |
String | Real | explicit | StrToFloat |
String | Char | explicit | String[index] |
Char | String | implicit | assignment statement |
Char/AnsiChar | Byte | explicit | Ord Byte(char-value) |
Byte | Char/AnsiChar | explicit | Chr AnsiChar(byte-value) |
Enumerated type | String | explicit | WriteStr(string-var,enum-var) |
Source data type | Target data type | Type of type conversion | Method |
QWord | Byte | explicit | Byte(QWord) |
QWord | Word | explicit | Word(QWord) |
QWord | Cardinal | explicit | Cardinal(QWord) |
QWord | Longword | explicit | Longword(QWord) |
Longword | Byte | explicit | Byte(Longword) |
Longword | Word | explicit | Word(Longword) |
Longword | Cardinal | implicit | assignment statement |
Int64 | Byte | explicit | Byte(Int64) |
Int64 | Shortint | explicit | Shortint(Int64) |
Comp | Byte | explicit | Byte(Comp) |
Comp | Shortint | explicit | Shortint(Comp) |
Comp | Real | explicit | Real(Comp) |