PocketMatrix forums

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

OOP Question

PointOfLight · 06 Dec 2004, 19:33 UTC
Where do I need to place a #object... statement within a form-based application in order for the object to be recognised throughout the project? I've tried in the initialization section and in the Control Code section for the main form, and in both cases when it hits a reference to the object it indicates that there is no definition for the function or procedure referenced by the object. I can take the same object class and define an instance of it in a simple formless app and it works just fine.

[Edit] My bad. what I meant was that I put code in the Form Creation and Control Code sections. But to be fair I went back and tried adding the #object line to the initialization code as well. That didn't help either. Here's what my current code base looks like from the top down if I do a "view source":

Code:

#include "common.ppl"

#define FORM100 100
#define cboTables 101
#define tabTabs 104
#define lstMessages 103
#define lblDatabase 105
#define lvwStructure 106
#define edtQuery 108
#define lvwData 111

#code {Main.frm#}
#import "\\windows\\adoce31.dll"

#include "combobox_lib.ppl"
#include "treeview_lib.ppl"
#include "listview_lib.ppl"
#include "listbox_lib.ppl"
#include "tabctl_lib.ppl"
#include "sql.ppl"
#include "sqlclass.ppl"

#object SQLiteObject records$


Even with the #object declaration before any reference to the object, it acts like records$ is not an object when I try to actually use it.
PointOfLight · 06 Dec 2004, 21:10 UTC
Okay, OOP just doesn't seem to get along with forms (or I'm doing something completely wrong). Since I couldn't seem to get a "global" object in a form, I decided to create the object local to one procedure to see if it would work. When I do that, I get an error that there is "no body" defined for any function except the first one called.
If #object is put outside of a proc/func the code will only be recognized by the compiler and won't be executed at runtime. In a lot of situations you will need to typecase the call.

Ex:

Code:
#class myclass
public (x$);

public proc myproc
ShowMessage(x$);
end;

#endclass

proc test
MyClass(c$);
c.x$ = 20;
c.MyProc;
end;

proc main
Global(c$);
#object myclass c$
c.x$ = 10;
c.MyProc;
test;
end;
PointOfLight · 07 Dec 2004, 20:57 UTC
I downloaded the latest version of PPL, and suddenly everything is magical. Well, maybe not "magical", but at least my problems with my class not working have gone away.
I have still one little thing to fix with the typecasting. If you are typecasting a variable that is not already an object of the same class, PPL will automatically create a new object and call the create() function of the object. However right now, it always call the create() function even though the object is already created. This will be fixed in the next release.