Autor Beitrag
DelphiUser123
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Mo 19.05.08 14:58 
I need to port some sourcecode from Visual Basic .NET to Delphi.

How do I port a CType to Delphi?

This is my Visual Basic code:

Zitat:

Dim resource As Resource
Dim iter As System.Collections.IEnumerator = allResources.GetEnumerator()

While iter.MoveNext() = True
resource = CType((iter.Current), Resource)
....


This is the same code in C#

Zitat:

IEnumerator iter = allResources.GetEnumerator();
Resource resource;

while (iter.MoveNext())
{
resource = (Resource) (iter.Current);
...
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mo 19.05.08 15:07 
CType casts a variable to a specific type, Resource in this example. Exactly the same as the ()-Operator in the C# code.

In Delphi, typecasting is done this way: TType(variable).
Applied to your code that would be:
ausblenden Delphi-Quelltext
1:
Resource(iter.Current);					


I would recommend to name the Resource datatype according to the standard, TResource.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
DelphiUser123 Threadstarter
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Mo 19.05.08 15:34 
Thank you very much, Martok. That keeps me going on...