PocketMatrix forums

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

Lists and strings and classes

PointOfLight · 05 Dec 2004, 18:11 UTC
I have a class that contains a list as one of it's private members. I'd like to have a function, say class.RetrieveElement(index$), that retrieves an item from this list and returns that element to the user. Or, worst case scenario, I would pass the variable to store the element of the list in as the second variable. So my syntax would either be:

x$ = class.RetrieveElement(1);

or:

class.RetrieveElement(1, &x$);

Now the element will be a string, and I can't seem to get the value out of the class. No matter what I do, x$ always ends up being the address of the element, not the value of the element. Please help!
Since the list is a list of strings, the elements within the list are not stored as values but as pointers to the string.

Therefore, you need to pass return(@list$) as the return value or do this:

x$ = class.RetrieveElement(1);
ShowMessage(@x$);

I hope I understood your problem correctly.
PointOfLight · 06 Dec 2004, 15:00 UTC
You understood my problem perfectly. The thing is, I tried various iterations using the @, and I kept getting an "address misaligned" error. I will try it again today just to be sure, though.
PointOfLight · 06 Dec 2004, 15:23 UTC
Just to verify, I first tried a return(@data$);. This gave me the "address misaligned" error. Then I left out the @ in the return statement and tried ShowMessage(@val$);, where val$ is the variable assigned to the return of the function. There was no error, but the value displayed was still the address, not the actual value of the string.
Hi,

I just tested the following code and it returns "C" as a string properly working on the PC and PPC.

Code:
#class myclass
private(l$);
list(l$);
Add(l$, "A", "B", "C", "D");

public forward func extract(x$)
#endclass

func myclass.extract(x$)
goto(l$, x$);
return (l$);
end;

proc main
#object myclass c$;
ShowMessage(c.extract(2));
end;


What are the differences in your code?
PointOfLight · 06 Dec 2004, 17:27 UTC
Actually, it might have been working fine this whole time. I have a public variable called errmsg$, which is a string containing any error descriptions. At the beginning of the function I set errmsg$ = "", and then when the function exits I do a compare, errmsg$ <> "". Apparently I need to do @errmsg$ <> "" instead, which solves my problem. Sorry about that :(
No problem, we could have discovered something buggy along the way! ;)