I am trying to get a Canvas object to display an image based on a name that is returned from a query.
Right now this code is located in popHelpTopic.Text
// Variable declarations...
Dim recSet As RecordSet = mthGetHelpTopic(popHelpTopic.Text)
// Function(s)...
txtHelpDetail.Text = recSet.IdxField(3).StringValue
lblRelated01.Caption = recSet.IdxField(4).StringValue
lblRelated02.Caption = recSet.IdxField(5).StringValue
lblRelated03.Caption = recSet.IdxField(6).StringValue
lblRelated04.Caption = recSet.IdxField(7).StringValue
lblRelated05.Caption = recSet.IdxField(8).StringValue
lblRelated06.Caption = recSet.IdxField(9).StringValue
mthLoadPopHelp
Properties:
Private pic As Picture
And this code is located in cnvImage.Paint
// Variable declarations...
Dim recSet As RecordSet = mthGetHelpTopic(popHelpTopic.Text)
Dim fldMeter As FolderItem
Dim picHelpImg As Picture
Dim maxWidth, maxHeight As Integer
Dim factor As Double
// Function(s)...
maxWidth = cnvImage.Width
maxHeight = cnvImage.Height
fldMeter = GetFolderItem("Pics/Help Images/").Child(recSet.IdxField(10).StringValue)
If(fldMeter) <> Nil Then
picHelpImg = fldMeter.OpenAsPicture
End If
factor = Min(maxWidth / picHelpImg.Width, maxHeight / picHelpImg.Height)
factor = Min(factor, 1.0) ' If it's too small then do not scale the image...
If(pic) <> Nil Then
' pic = NewPicture(picHelpImg.Width * factor, picHelpImg.Height * factor, 32)
' pic.Graphics.DrawPicture picHelpImg, 0, 0, pic.Width, pic.Height, 0, 0, picHelpImg.Width, picHelpImg.Height
g.DrawPicture pic, 0, 0
End If
cnvImage.Refresh
'cnvImage.Backdrop = fldMeter.OpenAsPicture
How this works is or is supposed to work is the user selects an item from a PopUp Menu which will call a Query. A recordset is returned and that is used to populate various elements. The last field in the query contains a name for an image.
I have a canvas object defined (it's called cnvImage) and based on the name in the query I want to display the appropriate image. I found a spot in the help manual (you can see I have been using it to try and get the results I want) and have had no luck getting the image to paint.
I am stumped and really don't know how to get around this one.
One issue that is coming up now is with the factor segment:
factor = Min(maxWidth / picHelpImg.Width, maxHeight / picHelpImg.Height)
factor = Min(factor, 1.0) ' If it's too small then do not scale the image...
I am getting a Nil Object Exception, from what I can tell in debug is that picHelpImg is the Nil object, but I am not sure why or how to correct it.