technotesLogo.gif
How to use strings in arrays?
Each element of an array is by default a double type value (8 bytes). Strings cannot be stored directly in an array element, therefore only the string pointer is stored in the array. If you get the value of an array element that is pointing to a string, all you will get is a memory address location where the string is located. You need to use the @ operator to convert the pointer to a string.:
proc main dim(array$, 10);
array$[0] = "THIS IS A STRING";
array$[1] = "THIS IS ANOTHER STRING";
ShowMessage(@array$[0]);
ShowMessage(@array$[1]);
end;
How do return an array from a func?
Returning an array from a function is quite easy but to assign the new array returned to a variable can be tricky if you don't know how. You need to use the & operator to assign a new pointer to the variable.:

func mytest
  dim(array$, 10);
  Fill(array$, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  return (array$);
end;

proc main
  dim(newarray$, 10);
  &newarray$ = mytest;
  For(i$, 0, 9)
      ShowMessage(newarray$[i]);
  end;
end;


How do I use linked-list as parameters?
Linked-list variables are very special. They are usually perceived as single values to the PPL interpreter unless you use special list functions with them. Passing linked-lists as parameters can only be done by passing them as pointers.proc test(l$)
  add(l$, 10, 20, 30);
end;
proc main
  list(l$);
  test(&l$);
  ForEach(l$)
      ShowMessage(l$);
  end;
end;
What if you don't know the size of an array returned from a func?
In order to return an array from a function, you have to make sure you have declared an array that is large enough to hold the data that gets returned.The ForEach statement works, but it loops over all elements of the target array. Make sure that you process your subset of values and not the garbage at the end of the array.

How do I create a linked-list?
A linked-list is made of a infinite (memory capacity is your only limit) number of elements linked together. You can build lists by adding elements, inserting element and removing elements. You can access elements of a list directly by it's index location or by moving forward or backward within the list.:
List(l$);
Add(l$, 1, 2, 3, 4, 5, 6, 7);
Goto(l$, 2);
ShowMessage(l$);
The list variable will always contain the value of the list element the list cursor is on. You can move this cursor by using the Goto() function or the First(), Last(), Next() or Prior() functions.:
First(l$);
ShowMessage(l$);
Next(l$);
ShowMessage(l$);
Prior(l$);
ShowMessage(l$);
Goto(l$, 2);
ShowMessage(l$);
How do I move elements within the list?
You can move elements to different position within the list by using the LMove() function.:
List(l$);
Add(l$, 1, 2, 3, 4, 5, 6);
LMove(l$, 0, 3);

The list will now contain the following elements:
2, 3, 4, 1, 5, 6
How do I copy a list to an array?
In PPL it is possible to copy a list to an array by doing the following:
list(l$);
add(l$, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
Dim(a$, 10);
ListToArray(l$, a$);
Can I use a WIN32 API function?
The #declare statement can be used to map WIN32 API functions to PPL. The syntax is:
#declare PPL_Alias DLL_Name Win32API_Name #InputParams #OutputParms
You can use this to call an API function that hasn't been declared yet. Most declares are in Windows.PPL. Here is an example:
#declare GetWindow apidll GetWindow 2 1
The DLL_Name parameter (apidll in the above example) is an alias. This is so that when switching platforms, the different DLL names among platforms can be taken into account. You can find these names declared in DEFS.PPL.
The #declareapi keyword solves a similar platform problem; the selection of the ASCII or the Unicode version of the function automatically.  Using SetWindowsText as an example. Look in Windows.ppl and you'll see:
#declareapi SetWindowText apidll SetWindowText 2 1
The PPC uses Unicode text and XP uses Ascii text. The Windows OS accomplishes this by having 2 functions SetWindowTextW and SetWindowTextA. A macro exists to map the function you need to SetWindowText. In PPL, this is done by #declareapi. It really looks for SetWindowTextW and SetWindowTextA within the referenced DLL.

How to use objects in a linked-list?
It is possible to store objects in linked-list offering a wide range of possibilities to your applications. You don't need to store objects using their pointers. All you need to do is to assign the current list element with an object and PPL will take care of the rest.

#class myclass
public (z$);
private (x$);
  nproc create
x$ = args$[0];
end;
  func getx
return(x$);
end;

proc m
ShowMessage(x$ + "," + z$);
end;
#endclass
proc main
Local(l$, i$);
  List(l$);
  for(i$, 1, 5)
Add(l$);
#object myclass l$(i$);
end;
  foreach(l$)
l.z$ = l.getx * 2;
l.m;
end;
end;
How to use objects in an array?
Support for objects in arrays is supported by default in PPL. All you need to do is to assign an object to an array using the = operator. You cannot directly store an object into an array element using the #object statement, you need to assign it after with the = operator.
#class myclass
public(v$, x$);
  public proc m
ShowMessage(v$ + "," + x$);
end;
#endclass
#class myclass2
public(v$);
  public proc m
ShowMessage(v$);
end;
#endclass
proc main
dim(o$, 10);

For (i$, 1, 5)
#object myclass z$;
o$[i] = z$;
o$[i].x$ = i$ * 2;
myclass2(o$[i]).v$ = i$; // Classtyping
end;

For (i$, 1, 5)
o$[i].m;
myclass2(o$[i]).m; // Classtyping
end;
end;
How to create a memory allocation and return the pointer from a function?
In function MyTest we create a new variable based on the size of the variable string$ adding 10 to the new length. We use the static(n$) to make sure the pointer of ptr$ will not be destroyed when the function MyTest exit. We then concatenate string$ to the string " New" and put the result into n$. We then have to return the pointer of n$ by doing return(&n$);.When we call MyTest from the Main procedure, the return value is a pointer value assigned to variable ptr$. We then need to output the memory content of that pointer. We use @ptr$. The @ will convert the pointer to the memory content. We display it as a string. Then we need to free the memory allocated in MyTest of ptr$ because PPL cannot do it anymore since ptr$ contains a numerical value (a pointer address value).
func mytest (string$)
new(n$, sizeof(string$)+10);
static(n$);
n$ = string$ % " new";
return(&n$);
end;
proc main
ptr$ = mytest("Old ");
ShowMessage(@ptr$);
free(ptr$);
end;
How to use lists as parameters and return list values?
Lists are handled as normal variables by the PPL interpreter. It means that the current list position index value is used by the interpreter at all time. If you assign a value to a list, the current list position value is set, the same for returning a list variable from a func. Only the current list position value will be returned. The best way to return list variables to a proc or func is to pass the parameter variable as a pointer with the & operator. In the example above, we first pass l$ as a non-pointer value, therefore the values 4, 5 and 6 are not added to the list. The second time we call the test procedure, we pass the list variable as pointer, therefore the 4, 5 and 6 values are properly added to the list on return.
proc test(l$)
add(l$, 4, 5, 6);
end;
proc main
list(l$);
add(l$, 1, 2, 3);
test(l$);
ForEach (l$)
ShowMessage(l$);
end;
test(&l$);
ForEach (l$)
ShowMessage(l$);
end;
end;