Re: [fpc-pascal] Untyped var params

2017-01-08 Thread Sven Barth
On 08.01.2017 11:36, Ryan Joseph wrote: > >> On Jan 8, 2017, at 5:22 PM, Sven Barth wrote: >> >> 1. Why are you trying to assign something to io when you already did >> that with "obj := …"? > > I used absolute here so I could know the type of io and not type cast

Re: [fpc-pascal] Untyped var params

2017-01-08 Thread Ryan Joseph
> On Jan 8, 2017, at 5:22 PM, Sven Barth wrote: > > 1. Why are you trying to assign something to io when you already did > that with "obj := …"? I used absolute here so I could know the type of io and not type cast within the function. No good? The idea is I want

Re: [fpc-pascal] Untyped var params

2017-01-08 Thread Ryan Joseph
> On Jan 8, 2017, at 5:36 PM, Ryan Joseph wrote: > > Casting TObject(input) := obj; worked but the value of “io” is still not > getting set. Because it’s a var I expected the value to be returned to the > caller. Never mind, I got it working, stupid mistake in my

Re: [fpc-pascal] Untyped var params

2017-01-08 Thread Sven Barth
On 08.01.2017 10:35, Ryan Joseph wrote: > >> On Jan 8, 2017, at 2:37 AM, Andrew Hall wrote: >> >> If you cast your “something” to a typed pointer, the compiler will do the >> work for you in the usual way: >> >> PDouble(something)^ := myDouble; >> PAnsiString(something)^ :=

Re: [fpc-pascal] Untyped var params

2017-01-08 Thread Ryan Joseph
> On Jan 8, 2017, at 2:37 AM, Andrew Hall wrote: > > If you cast your “something” to a typed pointer, the compiler will do the > work for you in the usual way: > > PDouble(something)^ := myDouble; > PAnsiString(something)^ := myAnsiString; > myRecordStructure :=

Re: [fpc-pascal] Untyped var params

2017-01-08 Thread Sven Barth
Am 08.01.2017 04:43 schrieb "Dmitry Boyarintsev" : > > On Sat, Jan 7, 2017 at 6:02 PM, Lars wrote: >> >> Some brave soldiers once tried to reinvent generics using these tricks.. > > > Well, Pascal run-time has been using "hidden" generics forever. > >

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Dmitry Boyarintsev
On Sat, Jan 7, 2017 at 6:02 PM, Lars wrote: > Some brave soldiers once tried to reinvent generics using these tricks.. Well, Pascal run-time has been using "hidden" generics forever. As an example: http://www.freepascal.org/docs-html/rtl/system/val.html Val() declares the

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Dmitry Boyarintsev
On Sat, Jan 7, 2017 at 6:53 PM, Bart wrote: > OK, I can imagine more complex examples where this may come in handy. > > And thanks for the rest of the explanation. And only more complex examples should be used :) There're much better ways to implement var-type variables.

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Bart
On 1/8/17, Dmitry Boyarintsev wrote: > Think about something like a var-type variable, where the actual type of Y > might vary. > > procedure XX(var Y; YType: integer); > begin > case YType of > T_INT: PInteger(@Y)^:= 3; > T_SINGLE: PSingle(@Y)^:=3; >

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Dmitry Boyarintsev
On Sat, Jan 7, 2017 at 5:42 PM, Bart wrote: > > procedure X(var Y); > begin > PInteger(Y)^ := 3; //syntax may be wrong, too lazy to test > end; > > To me this completely defies the purpose of an untyped var parameter, > since in this exmaple you do know, @design time,

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Lars
On Sat, January 7, 2017 2:52 pm, Bart wrote: > On 1/7/17, Andrew Hall wrote: > > >> If you cast your “something” to a typed pointer, the compiler will >> do the work for you in the usual way: >> > > But if you know that at forehand (and you know, since you cast it), > why

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Bart
On 1/7/17, Dmitry Boyarintsev wrote: >> But if you know that at forehand (and you know, since you cast it), >> why then use an untyped var parameter at all? >> > > http://www.freepascal.org/docs-html/rtl/system/fillchar.html ? That does not realy answer my question.

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Dmitry Boyarintsev
On Sat, Jan 7, 2017 at 4:52 PM, Bart wrote: > > But if you know that at forehand (and you know, since you cast it), > why then use an untyped var parameter at all? > http://www.freepascal.org/docs-html/rtl/system/fillchar.html ? thanks, Dmitry

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Bart
On 1/7/17, Andrew Hall wrote: > If you cast your “something” to a typed pointer, the compiler will do the > work for you in the usual way: > But if you know that at forehand (and you know, since you cast it), why then use an untyped var parameter at all? Bart

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Dmitry Boyarintsev
On Sat, Jan 7, 2017 at 2:37 PM, Andrew Hall wrote: > If you cast your “something” to a typed pointer, the compiler will do the > work for you in the usual way: > > PDouble(something)^ := myDouble; > or rather PDouble(@something)^ := myDouble; ? thanks, Dmitry

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Andrew Hall
If you cast your “something” to a typed pointer, the compiler will do the work for you in the usual way: PDouble(something)^ := myDouble; PAnsiString(something)^ := myAnsiString; myRecordStructure := PMyRecordStructure(something)^; Or less elegantly: AnsiString(Pointer(something)^) :=

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Lars
On Sat, January 7, 2017 4:29 am, Ryan Joseph wrote: > >> On Jan 4, 2017, at 11:07 PM, Dmitry Boyarintsev >> wrote: >> >> >> Treat is as a pointer (it's an implicit pointer anyway) >> >> > > So I need to need to use Move to write memory directly to “var >

Re: [fpc-pascal] Untyped var params

2017-01-07 Thread Ryan Joseph
> On Jan 4, 2017, at 11:07 PM, Dmitry Boyarintsev > wrote: > > Treat is as a pointer (it's an implicit pointer anyway) > So I need to need to use Move to write memory directly to “var something”? That makes sense I guess and could be useful is some cases but not

Re: [fpc-pascal] Untyped var params

2017-01-04 Thread Dmitry Boyarintsev
On Wed, Jan 4, 2017 at 10:24 AM, Ryan Joseph wrote: > But how do you assign to “something" then if you don’t know the type? The > param is “var” so shouldn’t I be able to assign to the param and return it > back to the caller? In your example how could I return 5 to

Re: [fpc-pascal] Untyped var params

2017-01-04 Thread Ryan Joseph
> On Jan 4, 2017, at 10:14 PM, Dmitry Boyarintsev > wrote: > > var > i: integer; > begin > i:=5; > GetSometing(i) > But how do you assign to “something" then if you don’t know the type? The param is “var” so shouldn’t I be able to assign to the param and

Re: [fpc-pascal] Untyped var params

2017-01-04 Thread Dmitry Boyarintsev
On Wed, Jan 4, 2017 at 9:29 AM, Ryan Joseph wrote: > I’ve seen functions that use the untyped params like: > > function GetSomething (var something): boolean; > > This seems like something useful I would like to use but how can you > assign to the parameter? I tried