.NET
•  Greatis •  Security •  AppDatabase •  Utilities •  Delphi/CB • Visual Basic •  just4fun
.NET Software
.NET Components for Visual Studio .NET, Delphi 8, Delphi 2005 and Delphi 2006
 .NET     Entire site
More Info
Delphi to C#
Index

.NET
Form Designer .NET

See also
Delphi VCL software
Visual Basic 6 software
Hot Offer

Form Desigber .Net

Delphi to C#
Language
Type conversion

  Delphi  

       To convert just use the new type name as function and apply it to the variable:
var
  C: Char;
  B: Byte;
  ...
  C:='G';
  B:=Byte(C);
In Delphi you can convert only size-compatible types, so you cannot convert, for instance, Double to Integer.

If you convert the class types, you can use as and is operators. is operator checks the class type and return True, if the class of is needed type or derived from the needed type. as makes the same chacking as is operator, then converts type. If the type in as expression is not compatible, exception is generated:

var
  SomeComponent: TComponent;
...
SomeComponent:=TButton.Create(Self);
...
if SomeComponent is TButton then 
  TButton(SomeComponent).ModalResult:=mrNone;
if SomeComponent is TControl then 
  TControl(SomeComponent).Width:=77;
if SomeComponent is TMemo then 
  // the following code will be not executed
  TMemo(SomeComponent).Lines.Text:='Defaul memo text';
(SomeComponent as TButton).ModalResult:=mrOk;
// the following code will be not executed and exception will raise
(SomeComponent as TMemo).WordWrap:=False;
 
 
  C#

Compatible type can be converted by the following code:
TypeA A;
TypeB B;
B = (TypeB)A;
is and as operators work exactly like in Delphi.

Lost features     
Added features
Warnings
Additional information

 
 


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2009 Greatis Software

eXTReMe Tracker