MouseMove over Image - problem

DaveW

Active Member
Licensed User
Longtime User
Hi,

I am a Newbie to Basic4PPC so sorry if this is a dumb question!!

I have modified the BigImage program I found elsewhere on the forum to add some more functionality. I hav added zooming to it and wanted to add a readout of mouse position over the image. However I have been unable to make this work. I have followed all the examples I can find on the forum and elsewhere but get an error:

"Object Reference not set to an instance of an object."

The relevant code is:

Sub App_Start
......
img1obj.New1(False)
img1obj.FromControl("Image1")
img1mve.New1(img1obj.Value,"MouseMove")
.......

Sub img1mve_NewEvent
x = img1obj.GetProperty("X") '<error here!
y = img1obj.GetProperty("Y")
label1.Text = x
label2.Text = y
End Sub

Can anyone help get me on the right track?

David.
 

Attachments

  • BigImage-v2.sbp
    3.2 KB · Views: 220

agraham

Expert
Licensed User
Longtime User
You need to assign the eventargs of the event to an object before you try to access them

B4X:
Sub img1mve_NewEvent
  [COLOR="Red"]img1obj.Value = img1mve.Data[/COLOR]
  x = img1obj.GetProperty("X")
  y = img1obj.GetProperty("Y")
  label1.Text = x
  label2.Text = y
End Sub
I also note that you are using dzImage.dll on the desktop, it should be dzImageDesktop.dll. Make sure you have got the latest version from post #30 here http://www.b4x.com/forum/additional-libraries/1403-dzimage-library-3.html.

You should also assign a filter to the OpenDialog to define the files types you want to open.
B4X:
OpenDialog1.Filter = "Picture Files|*.bmp;*.jpg|Text Files|*.txt|All Files|*.*"
 

DaveW

Active Member
Licensed User
Longtime User
Thanks, that fixed it! I still need to get my head round the "why" part - but that will come with practise I hope :)
 

agraham

Expert
Licensed User
Longtime User
I still need to get my head round the "why" part -
In your code img1obj contains a reference to your Image1 control. img1mve is an event object, owned by img1obj, that calls NewEvent when the mouse moves over the image.

Each event has an eventargs object assoicated with it that contains none, one or more details of the event depending upon the event type. In this case X and Y are properties of the eventargs belonging to the img1mve event. You cannot access these properties through img1obj, you must get them from the eventargs of the img1mve event and for this reason these are exposed to you by the Data property of the img1mve event object.

The Door library is not intended for routine use by "normal" programmers. To use it, other than by example, needs reasonably in-depth knowledge of the underlying .NET Common Language Runtime and its objects, and knowledge of how to access its documentation and understand it once you have found it. The library is provided so that features of objects that are desired to be used when they are not exposed by Basic4ppc or its libraries can be accessed without having to implement them in a library upgrade. The major "users" of this library are probably Erel and myself on behalf of other users.
 

DaveW

Active Member
Licensed User
Longtime User
Thanks for the excellent explanation of the 'why' !

I realise that Door was not really intended for the likes of me - but someone opened Pandora's Box and now we (i.e. you ;) ) have to live with it :D

Having got the Desktop version of the posted code working, I made the Setup and Install files using the SetupBuilder program, I put the dlls (dzEventsMagic, Door, dzImage, ImageLib) and exe in the installer and installed the app on my PDA. However I get a NullReferenceException when I try to open an image. If I say continue the image appears but the ScrollBars do not. This seems to indicate that the errors is in the 'door' bit still.

I know that bugfixing idiot's code is not your job, but I would be very impressed if you (or anyone) could offer more help!
 

agraham

Expert
Licensed User
Longtime User
Its always as well to post the actual code that is failing. Try running the app in the IDE on the device, this should give you the line number that is failing and therefore a better idea of what is wrong.

EDIT :- You did compile the exe for the device didn't you?
 

DaveW

Active Member
Licensed User
Longtime User
I would like to have posted the actual code that is failing but that was all I saw. I have been trying to run the app in the PDA IDE but without success. I just get an error message "An error occured. No error message can be given because an optional source files cannot be found." (or something like that - I have a Dutch language PDA!)

The app is identical to the one the posted at teh start of this thread with the one fix you suggested: img1obj.Value = img1mve.Data

And yes, I have compiled the app - though I confess I did miss that the first couple of times! :D
 

agraham

Expert
Licensed User
Longtime User

DaveW

Active Member
Licensed User
Longtime User
Thanks for the excellent help!

It turned out that the problems were a combination of newbie stuff - mainly missing DLLs on the PDA and some overly complex code. Once I got the DLLs copied over and removed all the stuff about getting the Scrollbar position and Maximum, the whole thing works fine :)
 
Top