Why can't the parameter of "LV_GetText" be "Clipboard"?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Why can't the parameter of "LV_GetText" be "Clipboard"?

18 Jan 2019, 05:21

Hello,
I tried to use "Clipboard" as the OutputVar of "LV_GetText", but it doesn't work. Why?

Thanks.

Code: Select all

LV_GetText(Clipboard, 1)
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Why can't the parameter of "LV_GetText" be "Clipboard"?

18 Jan 2019, 08:07

byref is trash thats why.
There are tons of things you can assign to but byref doesn't work on.
(LV_GetText essentially outputs the data using byref)
Recommends AHK Studio
eelrod
Posts: 65
Joined: 10 Apr 2018, 11:17

Re: Why can't the parameter of "LV_GetText" be "Clipboard"?

18 Jan 2019, 10:57

While that doesn't work, here's a workaround:

Code: Select all

LV_GetText( vInfo , 1)
Clipboard := vInfo
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Why can't the parameter of "LV_GetText" be "Clipboard"?

18 Jan 2019, 12:04

It's an inconsistency within byref.
While you can assign to variables, objects and special variables like Clipboard you cannot pass all of them byref.
See:

Code: Select all

var := ""
obj := []
Clipboard := ""
;These are all valid targets for assignments:
;var, obj.1 or Clipboard

;yet only var can be passed as output parameter:
setToHelloWorld(var)
Msgbox % var ;var now should be Hello World
setToHelloWorld(obj.1)
Msgbox % obj.1 ;should now be Hello World
setToHelloWorld(Clipboard)
Msgbox % Clipboard ;should now be Hello World

;The last 2 messages will not contain Hello World despite the fact that they should.

setToHelloWorld(byref outputParameter) {
	outputParameter := "Hello World"
}
LV_GetText uses byref internally to output to a variable and byref is fundamentally inconsistent and very limited and in general should be avoided unless absolutely needed.
Recommends AHK Studio
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Why can't the parameter of "LV_GetText" be "Clipboard"?

18 Jan 2019, 12:31

Byref (udf) has this limitation documented, Outputvar has not, as far as I know. If no one can point to anything in the docs suggesting this is a known limitation, this should be in bug reports.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 102 guests