change object class

2023-09-17 Thread Vitaliy Fadeev via Digitalmars-d-learn
Hi! I want to change a method ```Draw``` on a custom object when the ```MouseIn``` event occurs. This is known as "Change State" of the object: ```Init``` -> ```Hovered```. I want to change the state of an object by changing its class, like this: ```d this.__vptr = typeid(CLS).vtbl.ptr;

dlang custom keyword for struct/class

2023-09-17 Thread Vitaliy Fadeev via Digitalmars-d-learn
Is it possible to write like this in D? ```d struct Message { ulong timestamp; } Message LongMessage { ubyte[255] s; } // // it mean // // struct LongMessage // { // Message _super; // alias _super this; // ubyte[255] s; // } // // or // // struct LongMessage // { //

Re: dlang custom keyword for struct/class

2023-09-17 Thread FeepingCreature via Digitalmars-d-learn
On Sunday, 17 September 2023 at 15:55:37 UTC, Vitaliy Fadeev wrote: Is it possible to write like this in D? ```d struct Message { ulong timestamp; } Message LongMessage { ubyte[255] s; } // // it mean // // struct LongMessage // { // Message _super; // alias _super this; //

Re: change object class

2023-09-17 Thread Vitaliy Fadeev via Digitalmars-d-learn
On Sunday, 17 September 2023 at 15:05:59 UTC, Vitaliy Fadeev wrote: ... Playground: https://run.dlang.io/is/hjcLCk

Re: change object class

2023-09-17 Thread evilrat via Digitalmars-d-learn
On Sunday, 17 September 2023 at 15:05:59 UTC, Vitaliy Fadeev wrote: It works! But I want to ask how to make this 100% the best of the best? What should I consider before changing ```__vptr``` ? If that works for you with that constraint of having exact memory layout then it should be ok.

Dinamyc arrays

2023-09-17 Thread Timofey via Digitalmars-d-learn
I`ve just started learning d and have a question. What should I write to set dinamyc rectangular array length in both dimentions? For example, I have declareted an array: ``` int[][] matrix;``` and want set it as n*n matrix. Thanks

Re: change object class

2023-09-17 Thread Johan via Digitalmars-d-learn
On Sunday, 17 September 2023 at 17:10:16 UTC, evilrat wrote: On Sunday, 17 September 2023 at 15:05:59 UTC, Vitaliy Fadeev wrote: It works! But I want to ask how to make this 100% the best of the best? What should I consider before changing ```__vptr``` ? If that works for you with that

Re: Dinamyc arrays

2023-09-17 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 17 September 2023 at 17:15:34 UTC, Timofey wrote: I`ve just started learning d and have a question. What should I write to set dinamyc rectangular array length in both dimentions? For example, I have declareted an array: ``` int[][] matrix;``` and want set it as n*n matrix. Thanks

Re: Help on array pointers

2023-09-17 Thread Joe--- via Digitalmars-d-learn
On Friday, 15 September 2023 at 16:55:34 UTC, Vino wrote: On Friday, 15 September 2023 at 15:27:00 UTC, Vino wrote: On Friday, 15 September 2023 at 02:25:09 UTC, Joe wrote: On Thursday, 14 September 2023 at 14:21:09 UTC, Vino wrote: [...] A pointer is a type that points to something. It's

Re: Dinamyc arrays

2023-09-17 Thread user1234 via Digitalmars-d-learn
On Sunday, 17 September 2023 at 17:15:34 UTC, Timofey wrote: I`ve just started learning d and have a question. What should I write to set dinamyc rectangular array length in both dimentions? For example, I have declareted an array: ```d int[][] matrix; ``` and want set it as n*n matrix.

Re: Help on array pointers

2023-09-17 Thread vino via Digitalmars-d-learn
On Sunday, 17 September 2023 at 18:28:36 UTC, Joe wrote: On Friday, 15 September 2023 at 16:55:34 UTC, Vino wrote: [...] [...] char[] invalid = (cast(char*)malloc(char.sizeof * len))[0..len]; This is not the way to go about it. You are mixing "pointer arrays" with "arrays". [...]