Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Dec 13, 2019 11:41 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Load image based on query return
PostPosted: Mon Apr 05, 2010 3:35 pm 
Offline

Joined: Fri Sep 14, 2007 5:00 pm
Posts: 408
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Load image based on query return
PostPosted: Mon Apr 05, 2010 3:44 pm 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
is recset nil?

what is the value of recSet.IdxField(10).StringValue at the point you use it to get a folder item?

"Pics/Help Images/" will not exist at debug time, if you expect it to be local to your application.

try creating the pics folder on your desktop.
Then use

fldMeter = Specialfolder.desktop.child("Pics").child("Help Images").Child(recSet.IdxField(10).StringValue)

_________________
Still RB2009 R5.1
Mac 10.6 + Windows 7/XP + Ubuntu Linux in Vmware
on a Macbook 2.16


Top
 Profile  
Reply with quote  
 Post subject: Re: Load image based on query return
PostPosted: Mon Apr 05, 2010 4:23 pm 
Offline

Joined: Fri Sep 14, 2007 5:00 pm
Posts: 408
recSet is not Nil

recSet.IdxField(10).StringValue = "MeterDetail01.jpg"

I have the Pics/Help Images folders contained in the CurrentWorkingDirectory.

So I changed the code a bit to this

fldMeter = SpecialFolder.CurrentWorkingDirectory.Child("Pics").Child("Help Images").Child(recSet.IdxField(10).StringValue)


When the application errors out the message at the bottom of the IDE window is NilObjectException.

The Variables have the following:

Globals
factor = 0.
fldMeter = Nil
g = Graphics [random chars]
maxHeight = 416
maxWidth = 801
me = Canvas [random chars]
picHelpImg = Nil
recSet = RecordSet [random chars]
self = frmHelp.frmHelp [random chars]


Top
 Profile  
Reply with quote  
 Post subject: Re: Load image based on query return
PostPosted: Mon Apr 05, 2010 5:25 pm 
Offline

Joined: Fri Sep 14, 2007 5:00 pm
Posts: 408
Okay some progress has been made...

// 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(picHelpImg) <> 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

mthLoadPopHelp

Exit


This is working... sort of again. There seems to be an issue with how I have this designed.

I have a TabPanel with two tabs.

TabPanel.Name = pnlHelp
Panel 1 has an EditField.Name = txtHelpDetail
Panel 2 has the Canvas.Name = cnvImage

When I click on Panel two the image now appears. But if I try to go back to Panel 1 the NilObjectException gets thrown again.


Top
 Profile  
Reply with quote  
 Post subject: Re: Load image based on query return
PostPosted: Mon Apr 05, 2010 6:16 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Quote:
factor = Min(maxWidth / picHelpImg.Width, maxHeight / picHelpImg.Height)

Put this line (and the one following it) inside your "if picHelpImg <> nil" test.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group