# What am I able to cast to ^Void?

**URL:** https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567
**Category:** Oxygene
**Tags:** visual-studio, oxygene
**Created:** [March 28, 2017, 2:36pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567 "2017-03-28T14:36:36Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 28, 2017, 2:36pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/1 "2017-03-28T14:36:37Z")

</div>

Hey guys,

when i want to cast a tuple of (Tkey, TValue) to ^Void, it tells me, that it cant cast this.

Why??

---

<div class="post-metadata">

### Author: ![FredyFerrari](https://talk.remobjects.com/user_avatar/talk.remobjects.com/fredyferrari/32/2038_2.png) [@FredyFerrari](https://talk.remobjects.com/u/FredyFerrari)
#### Post date: [March 28, 2017, 2:43pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/2 "2017-03-28T14:43:36Z")

</div>

I’d say, In contrary to C++, void is not just an untyped type under .NET.

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 28, 2017, 4:31pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/3 "2017-03-28T16:31:30Z")

</div>

That means, that im not able to get a empty pointer to a record/class?

Thats by Definition pure crap!

---

<div class="post-metadata">

### Author: ![FredyFerrari](https://talk.remobjects.com/user_avatar/talk.remobjects.com/fredyferrari/32/2038_2.png) [@FredyFerrari](https://talk.remobjects.com/u/FredyFerrari)
#### Post date: [March 28, 2017, 4:44pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/4 "2017-03-28T16:44:02Z")

</div>

How about null for nullable types? Sorry, meant nil in terms of Oxygene.

No, that’s not crap, it’s part of the .NET CLR. And this makes sense as Oxygene started as a .NET compiler. In fact, under .NET you cannot cast anything to void. There is a type void but it’s used by reflection.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [March 28, 2017, 4:56pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/5 "2017-03-28T16:56:50Z")

</div>

What platform? On .NET or Java, says no, you can’t just get the address of something. I wouldn’t call that “pure crap”.

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 28, 2017, 8:19pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/6 "2017-03-28T20:19:48Z")

</div>

Ahh sry, Platform is: Island ^^

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [March 28, 2017, 8:27pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/7 "2017-03-28T20:27:19Z")

</div>

What would you do with a pointer to a tuple?

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 28, 2017, 8:29pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/8 "2017-03-28T20:29:54Z")

</div>

the Island - MemoryStream wants it and i Need to write some data in Memory

What my soluion was, calls memstr.Write(…) 2 times with item1 and item2

```
 f_buffer.Write(^Void(pair.item1), sizeOf(pair.item1) * 1);
 f_buffer.Write(^Void(pair.item2), sizeOf(pair.item2) * 1);

```

But i still want to know, does this work on Island or not?

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [March 29, 2017, 5:44am UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/9 "2017-03-29T05:44:52Z")

</div>

Not like that. It would write a pointer which would be useless, you’d want:

```auto
 f_buffer.Write(@pair.item1, sizeOf(pair.item1) * 1);
 f_buffer.Write(@pair.item2, sizeOf(pair.item2) * 1);

```

---

<div class="post-metadata">

### Author: ![FredyFerrari](https://talk.remobjects.com/user_avatar/talk.remobjects.com/fredyferrari/32/2038_2.png) [@FredyFerrari](https://talk.remobjects.com/u/FredyFerrari)
#### Post date: [March 29, 2017, 6:46am UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/10 "2017-03-29T06:46:59Z")

</div>

Ah, I have overseen the **^** in front of the void.

@shpend_hoti Wouldn’t it be a bit wiser to not call something crap before really understanding the underlying technique?

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 29, 2017, 9:30am UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/11 "2017-03-29T09:30:33Z")

</div>

I tried that, and i get an error:

"Error (E406) No overloaded method “Write” with these parameters on type “MemoryStream”, best matching overload is “method Write(buf: ^Void; Count: Int32): Int32”

Because i want to write a T1 and T2 (generic Arguments)

pair.item1 = typeof(T1)  
pair.item2 = typeof(T2) //-- Just for notice

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 29, 2017, 10:01am UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/12 "2017-03-29T10:01:15Z")

</div>

In General, would you write a Little example, how do i read/write exactly a tuple from/to memorystream, i am pretty confused about that^^

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [March 29, 2017, 10:07am UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/13 "2017-03-29T10:07:36Z")

</div>

When generics are involved it gets a little trickier. a tuple of Int, Int would be fine, but what if it’s a tuple of string, string? You can’t just write a string like that, it would write the pointer, which is useless. Generally to do this you’d use a serializer to a well known format.

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 29, 2017, 11:24am UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/14 "2017-03-29T11:24:58Z")

</div>

where can i get those serializers?

---

<div class="post-metadata">

### Author: ![FredyFerrari](https://talk.remobjects.com/user_avatar/talk.remobjects.com/fredyferrari/32/2038_2.png) [@FredyFerrari](https://talk.remobjects.com/u/FredyFerrari)
#### Post date: [March 29, 2017, 12:21pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/15 "2017-03-29T12:21:00Z")

</div>

> <https://stackoverflow.com/questions/3984476/what-is-serialization-all-about>

  

> <https://stackoverflow.com/questions/5877808/what-is-serializable-and-when-should-i-use-it>

  

> <https://stackoverflow.com/questions/3042665/what-is-the-meaning-of-serialization-concept-in-programming-languages>

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 29, 2017, 1:45pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/16 "2017-03-29T13:45:24Z")

</div>

I know what serialization is about, i was actually asking where i can get some good serializers for  
**[ISLAND: Oxygene]**

But i think, i Need to do this on my own…

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 29, 2017, 3:01pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/17 "2017-03-29T15:01:25Z")

</div>

The Problem is, when i want to read even a normal integer out of the memorystream, it gives me 0 back, instead of the total size ??

What am i doing wrong:

```
f_buffer.Write(@number, sizeof(number) * 1);
var res: int32 := f_buffer.Read(@number, sizeof(number) * 1); //gives always 0 back
```

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [March 29, 2017, 3:06pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/18 "2017-03-29T15:06:55Z")

</div>

Thats because you write, which moves the position by 4, then read from there, which is at the end of the stream.

---

<div class="post-metadata">

### Author: ![shpend\_hoti](https://talk.remobjects.com/user_avatar/talk.remobjects.com/shpend_hoti/32/18171_2.png) [@shpend\_hoti](https://talk.remobjects.com/u/shpend_hoti)
#### Post date: [March 29, 2017, 3:14pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/19 "2017-03-29T15:14:09Z")

</div>

Thanks a lot, carlo, but i am wondering, why am i able to write strings?

see the Code:

```
var data: Somerec;
  data.A := 'Z';
  data.B := 'H';
  data.C := 'C';
  data.D := 2000;
  data.E := 3000;
  data.F := DateTime.Now;
  data.G := 'text';

  var d: MemoryStream := new MemoryStream();
              
  d.Write(@data, sizeOf(data) * 1);

  d.Position := 0;

  var res : Somerec;

  d.Read(@res, sizeOf(data)* 1);
  writeLn(res.A);
  writeLn(res.G); //res.G => string
        
  readLn;
```

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [March 29, 2017, 3:18pm UTC](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567/20 "2017-03-29T15:18:02Z")

</div>

Because you’re in the same address space. It’s writing a pointer (4 or 8 bytes), it just happens that the stuff you’re reading is stil at the same position.

[Next page](https://talk.remobjects.com/t/what-am-i-able-to-cast-to-void/12567.md?page=2)
