PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Problems with COM

I am trying to access the Fields property and it works like a charm. But then, I try to access the Item property to get the value of a field.

I do this:

value$ = GetProperty (Fields$, "Item", index$);

But I get an error, Invalid number of parameters. The Fields property is 1 parameter right? The index of the field no?

Anybody can help?
PointOfLight · 22 Aug 2004, 02:27 UTC
I assume you're talking about ADO here, and sadly it's been several months since I've done anything ADO, but Fields should be a collection, not a single item.
I thought I might try converting a simple "ADOCE database test program" I wrote in NS Basic. It simply allows you to specify a "cdb file" - it adds a list of all the tables to a combobox. If you select a table from the dropdown list it then shows all the fields of the selected table in a second combobox and also displays each record in the table (a line per record) in a memo control. (its not original - its based on an NS Basic demo for non cdb databases).

As usual my approach is a few lines of code at a time.

From my "limited" understanding of ADOCE there are six (6) "adoce.connection.3.1" properties that should be displayable - hence the code example below.

Code:

#IMPORT "\\windows\\adoce31.dll"

ado$ = CreateObject("adoce.connection.3.1");

ShowMessage(GetProperty(ado$, "Version"));
ShowMessage(GetProperty(ado$, "Provider"));
ShowMessage(GetProperty(ado$, "State"));
ShowMessage(GetProperty(ado$, "Mode"));
ShowMessage(GetProperty(ado$, "ConnectionString")); // fails with "access violation"
ShowMessage(GetProperty(ado$, "DefaultDatabase")); // fails with "access violation"

DeleteObject(ado$);


I note that if you attempt to perform a GetProperty on a property name that doesn't exist (or you purposely mispell) this also generates an "accesss violation".

The two that fail are pretty fundamental to making an initial connection to an existing database. (eg: they'll need to be set (using SetProperty) before executing the "Open" method.

Any suggestions as to why these two "fail".

I note, (but it maybe irrelevent) that length of the property names that fail are all greater than 8 characters. This was a problem you fixed with procedure calls in the past.

regards
Hi,

Merv: I still have a lot of work to do on the COM functions. I will give your sample a try. Would it be possible for you to convert more lines after that so that I can get a real-life example to work with? Lets do this piece-by-piece, I fix this code, I give you PPL pre-release, you give me another piece of code, and so on... How does that sound to you?


PointOfLight: Fields is an IDispatch property and then I can access Fields.Item() but the Item function is not working. It sees the Item function no problem but when I invoke() it, I get an invalid number of parameters even though the internal suggest that 1 is the number of parameters. I will try out some more tomorrow.
Btw, Item() should return a IDispatch to a Field type structure. Then I can play with Value() from there.
PointOfLight · 22 Aug 2004, 21:15 UTC
I felt like I was missing all the fun with this COM stuff, so I thought I'd give it a shot. I can do a CreateObject just fine (on both connection and recordset objects). I can do a GetProperty just fine on the connection (don't know any recordset properties to test without having a recordset open). If I try and do an Invoke on either the recordset or connection objects, however, I get an Access Violation at address 0x255fc.
PointOfLight

Looks like you are experiencing the same results as me.

Kornalius

Thanks for the comments. Happy to assist in whatever way best suits you.

I have attached my NSBasic source (both as "nsb" and "txt" file format). The database I use by default is a custom access database I converted to "cdb" using activesync, but the program should work for any "cdb" database. PointOfLight might have some better experience and base sample.


regards
Attachments:
adoce_sample.zip (3 KB)
Kornalius,

There appears to be a problem with string concatenation in V0.8. My GetArgStr(aString$,index$) stopped working. On closer investigation it appears that string concatenation is behaving differently from previous versions. If I fall back a version all works as expected.

Code:

test1$ = "1";
test2$ = "2";
test1$ = str(test1$) + str(test2$);
showmessage("test1$+test2$="+test1$);


results in test1$ = "3" NOT "12"

regards
Hi Merv,

Yep, the operators +, -, * and / have been enhanced a whole lot in v0.8. I will do some more testing tomorrow. Strange, it should still work like before. Probably a bug with my IsValidInt() internal function to test if a string can be converted to int correctly. I will get back to you shortly.
PointOfLight · 23 Aug 2004, 03:12 UTC
Any updates on COM progress? This is my experience so far:

CreateObject, DeleteObject work great
GetProperty / SetProperty work intermittently
Invoke blows chunks on anything with parameters

By the way: there was a question (possibly in the other thread) as to why CreateObject(ADOCE) didn't work? I'm still not sure, but I did find out that CreateObject("adoce.3.1") {with no specific object type defined} does work. Not sure if that helps you any, kornalius, but I thought I'd offer it.
I am still working hard on the COM implementation, learning a lot as I am going through. I might have find out how to access Collection properties also. Reading some technical article on it right now.

Don't forget the COM implementation is very rough stage right now and is going through some major work and some re-write. I will get back here with a pre-release version for you guys in the next day or so. This way when 0.8 comes out, it will be fully-working (hopefully). I am getting there, slowly...
Btw, thanks for all your inputs, I see I am getting there.
PointOfLight · 23 Aug 2004, 05:35 UTC
Hope I'm not sounding too pushy about this. I just think it's going to be a neat thing when it's finshed, and I want to help you get it figured out in any way I can. Keep up the excellent work, and v1.0 should be one of the best scripted PPC languages out there :D
Finally I got it to work. This piece of code here works like a charm.

I will now work on COM events. Anybody know how they work?

Code:
#IMPORT "\\windows\\adoce31.dll"

DeleteFile("\\ado.cdb");

com$ = CreateObject("ADOCE.RecordSet.3.1");
Invoke(com$, "Open", "create database '\\ado.cdb'");
if (not IsNull(ComError%))
ShowMessage(ComError%);
end;

Invoke(com$, "Open", "create table t1 (c1 integer, c2 varchar(200))", "\\ado.cdb");
if (not IsNull(ComError%))
ShowMessage(ComError%);
end;

Invoke(com$, "Open", "insert into t1 (c1, c2) values (10, 'Alain')", "\\ado.cdb");
Invoke(com$, "Open", "insert into t1 (c1, c2) values (11, 'Deschenes')", "\\ado.cdb");
if (not IsNull(ComError%))
ShowMessage(ComError%);
end;

Invoke(com$, "Open", "t1", "\\ado.cdb");
if (not IsNull(ComError%))
ShowMessage(ComError%);
end;

ShowMessage("RecordCount:"+GetProperty(com$, "RecordCount"));

f$ = GetProperty(com$, "Fields");
ShowMessage("Fields:"+GetProperty(f$, "Count")); // 2

item$ = GetProperty(f$, "Item", 1);
ShowMessage(GetProperty(item$, "Name")+"="+GetProperty(item$, "Value")); // c2=Alain
Invoke(com$, "MoveNext");
item$ = GetProperty(f$, "Item", "c2");
ShowMessage(GetProperty(item$, "Name")+"="+GetProperty(item$, "Value")); // c2=Deschenes

Invoke(f$, "Release");
Invoke(com$, "Close");
Invoke(com$, "Release");
deleteobject(com$);
Here is the new version of PPL 0.8 pre-release for those interested in trying out the COM technology inside PPL.
Attachments:
ppl.zip (121 KB)
Btw Merv,

This code:

Code:
test1$ = "1";
test2$ = "2";
test1$ = str(test1$) + str(test2$);
showmessage("test1$+test2$="+test1$);


Is not really compatible with v0.8 anymore. Because the operators +, -, * and / check to see if the parameters are string type, if so, it checks to see if they are valid int, if so, it converts them to int and do the math.

However, PPL v0.8 comes with an handy concat() function that you can use like this:

Code:
test1$ = "1";
test2$ = "2";
test1$ = concat(test1$, test2$);
showmessage("test1$+test2$="+test1$);


In version 0.8:

Code:
"10" + "10" = 20
"A" + "10" = "A10"
"A" + "A" = "AA"
Concat("10", "10", "20") = "101020"
PointOfLight · 23 Aug 2004, 18:23 UTC
The COM stuff is working great. However, I don't seem to be able to debug again. I could last night, but now when I try to debug an app it doesn't break, even though I know the code that has my breakpoint is being called.
Are you still using the PIDE v0.8? I don't just checking. Debug works here.

Do you get any error message?

Try using Clear Breakpoints in the Run menu of PIDE first, then set your breakpoints again.
PointOfLight · 23 Aug 2004, 19:46 UTC
I am still working with .8. I had shut down PIDE, so when I started back up there weren't any breakpoints to clear. I set one breakpoint, ran the app via debug, and launched the code with the breakpoint. I know the code worked, because my combo was populated as expected, but the PIDE never stopped at the breakpoint. I'm using the latest PPL .8 compile that you submitted on this forum, but the PIDE is one that you sent me a couple of days ago. Could something not be matching up between the two?
Strange, I have the same version of the PIDE as you except a few minor bug fixes here and there. Did you set your breakpoint on the first line by any chance? If so, there was a bug that I fixed today when a breakpoint was set on the first line of code to execute.
Eric, do you use events with COM objects? Because I am thinking about not implementing it right now.

And, I am thinking about changing the default behavior for Collection properties to call the default property index (Item() that is) just like in basic or c++.

Example:

Instead of having:

Code:
fields$ = GetProperty(com$, "Fields");
item$ = GetProperty(fields$, "Item", 1);


have this:

Code:
item$ = GetProperty(com$, "Fields", 1);


PPL would call the Item() property right away if you pass an index to a collection property. Although the following would still be possible.

Code:
fields$ = GetProperty(com$, "Fields");
PointOfLight · 23 Aug 2004, 23:32 UTC
I will verify the debug issue when I get around to working with PPL later tonight. As for the "events with COM" question, it really depends on the COM object. With ADOCE, probably not. I know there are some, but I don't think I've ever even used events with regular ADO. The only other COM object I've played with on the PocketPC right now is ASpriteCE, which really doesn't have much use if I use the built in GameAPI. So I guess the answer right now is no, I don't use events. (The whole thought of events came because I was going to play around with the AspriteCE control, but the GameAPI is much nicer).
I hope you didn't want to use AspriteCE instead the super GameAPI PPL provides? :wink: I hope it was just to test the COM implementation. :lol:
PointOfLight · 24 Aug 2004, 03:18 UTC
Actually, it really was just for testing purposes :roll: It actually wouldn't make much sense to write the game in PPL and use a COM object based on VBScript!
Firstly my apologies for being inactive over the last 24 hours. I have been reconciling where I am at (eg: what works, what doesn't work and whats broken)

Kornalius,

thanks for the "Concat" hint above. I have modified the critical routine and it now performs as designed. I will go away and modify my support libraries over the next 24 hrs.

Current Status:
--------------

I am pleased that using V0.8(a) I now have a completed working "GPS/Moving Map" program fully functional. The program reads NEMA GPS data from a bluetooth connected GPS receiver and displays the location on a "bmp" map that moves in the background as user position moves. Maps change automatically as required, choosing the highest resolution map for any display location. The program also (optionally) reports location to an Internet Server using UDP and the APRS protocol (over GPRS).

Issues:
------

I still believe I am having a problem with "goto". The above program is functioning with the "mygoto" work around I wrote. BUT I WILL RUN SOME FURTHER TESTS AND CONFIRM THIS IN THE NEXT 24 HRS AND ADVISE OF THE RESULTS.

All other issues (except the ADOCE comments I made) have been resolved.

Next Steps:
----------

I can now give some time to helping with the COM (ADOCE) testing, though you guys appear to have got well and truly on top of it. I'll re-read your recent posts in regard to COM/ADOCE and see what I can do.
Hey Merv,

Wow it looks like a really cool program you have done. I am very happy to see it works and makes me more confident PPL is usefull somehow.

I will be more than happy to try to resolve the Goto() problem with you. Maybe it is only happening in some strange cases.
Kornalius,

Still a few problems to be sorted out .. but we're progressing.

The program "leaks" memory which causes it to terminate after about half an hour. While attempting to find the "leak" I tried this simple piece of code.

Code:

local (lString$);

lString$ = "";
while (1)
lString$ = concat(lString$," ");
lString$ = "";
end;


The code block above is instead of calling my main program loop. The forms and a system timer have been initialized. The time is udsed to display "Free Memory" every 60 secs.

Interestingly the above loop appears to "leak" memory. To put some credence on the "test environment" I find that if I comment out the line

lString$ = concat(lString$," ");

then the MemStatus report shows no "leak".

Does anyone want to shed some light on what these results are really saying?

It's 1:00am here and I'm off to bed ...

regards
Problem is that the garbage collector only clean it's data at the end of a procedure or the end of the program. So PPL would work like this in this example:

1. concat(), add string to garbage collector. (+mem)
2. free string in variable. (-mem)
3. = operator copies the string to variable. (+mem)
4. free string in variable. (-mem)
5. Copy new string "" to variable. (+mem)
6. loop to 1

In the next revision (I just fixed it :) ), it will work like this:

1. concat(), add string to garbage collector (+mem)
2. free string in variable. (-mem)
3. free string from garbage collector if applicable. (-mem)
4. = operator, copies the string to variable (+mem)
5. free string from variable. (-mem)
6. free string from garbage collector (-mem)
7. Copy new string "" to variable (+mem)
8. loop to 1

This way the = operator will remove the garbage collection information as it assigns the new value to a variable.

I will make a new version available later today with the modified COM implementation, maybe you can rerun the test and see how it goes. I ran it here and it was alright.
Here is the new version of PPL 0.8 pre-release.

In this version, memory leaks have been fixed and the garbage collector is more accurate.

Also, the COM interface has been tweaked to allow to access default interface properties automatically.

Ex:

Code:
item$ = QueryInterface(com$, "Fields", 1);
name$ = GetProperty(item$, "Name");

fields$ = QueryInterface(com$, "Fields");
item$ = GetProperty(fields$, "Item", 1);
Attachments:
pideppl.zip (119 KB)
Kornalius,

The ADOCE stuff is looking good!

I can open my cdb database (converted access file) and view the tables/contents and access the system tables to read a list of tables and field (coloumn) names for each of the tables..

Your "create" code also works fine.

I haven't tried any SQL "query" or "update" yet, but think its time for sleep (10:00PM here)

cheers
Great to here this. I think it's time for me to get back to the Visual Form Builder now. Still a long way to go...
PointOfLight · 30 Aug 2004, 17:55 UTC
I think there might still be some issues with the COM functionality (or maybe I'm not doing something right). Normally, if I wanted to do something like a simple insert, I'd do (pseudo-code):

Code:

connection = createobject("adoce.connection.3.1");
connection.open("database_path");
connection.Execute("insert statement", rows_affected);


I have been messing with this last night and this morning in PPL, and this type of logic gives me basically the ADO equivalent of a "type mismatch" error every time I run it. In PPL, the only way I can accomplish such functionality right now is:

Code:

recordset = createobject("adoce.recordset.3.1");
recordset.open("insert statement", "database_path");


I don't necessarily mind using this syntax, but I don't believe this will give me the number of rows that were affected, which is necessary in writing a generic SQL launcher routine so that the end user knows if their SQL did anything or not.
I will take a look tomorrow and either fix it or show you how to do it. I need to look at the Invoke command.
PointOfLight · 31 Aug 2004, 05:31 UTC
Well, hopefully you can show me the errors of my ways, because now using the recordset syntax to run an insert or delete command doesn't work (which I would think it shouldn't, but it was before) :(