Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to pass a property of an object as ref?

$
0
0

Hello,

i have created an object like so:

	$global:user = new-object -typename psobject
	Add-Member -InputObject $global:user -Name new -value "0" -membertype noteproperty
	add-member -inputobject $global:user -name name -value "" -membertype noteproperty	

In order to edit the object i created a gui with some textboxes.

I wrote a function to create those textboxes. To make live easier i would like to add the property of the object to that function.

In that case i could easily add an onTextChanged-function to the textbox.

The function should look kinda like this:

function newedit([string]$text, [int]$x, [int]$y, [int]$width, [int]$height, [ref]objectproperty){
	$e = New-Object System.Windows.Forms.TextBox
	$e.Text = $objectproperty
	$e.Location = New-Object System.Drawing.Point($x, $y)
	$e.Size = New-Object System.Drawing.Size($width, $height)
	$e.add_textchanged({ $objectproperty = $e.Text })
	return $e
}

the function would be called like

$edit = newedit $user.name 10 10 100 20 $user.name

This way i wont have to care about updating the object.

If this is not possible, is there a way to reference the object-property by string?

Thanks in advance.



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>