I think you are doing a little extra work than you have to...and, as they
say, too much is exactly as wrong as too little ;-)

.
.
P := LstGetSelectionText(List, Selection);  { Goood, obtains pointer to the
text }

{ The following line should not be necessary, since a string is directly
returned! }
ListText := MemHandleLock(P); 

{ This line is also not neccessary, since you haven't allocated any memory
so you can free it! }
MemHandleFree(P);
.
.

The point is, that after you make the LstGetSelectionText() call, you do
have what you want - the P variable points to the memory where the string is
placed.
For you as a Pascal developer this might be a little unusual, since Pascal
strings are not the same as C strings. I am afraid you will have to get used
to that. What you get as return from that function is a C string, that is,
address in the memory, where the actual text is placed and it is
zero-terminated, as opposed to size-headed.

You may also want to change the P variable type from MemPtr to CharPtr and
eventually typecast when doing the call.

To make sure this is right, do the following:

P := LstGetSelectionText(List, Selection);
FrmCustomAlert(AlertShow, CharPtr(p), '', '');

Depending on how FrmCustomAlert() is done in your Pascal enviornment, you
may have to call a function like PascalString2CString(); I do not know the
exact name, but if FrmCustomAlert() expects Pascal string, then you
obviously have to convert P to it first.

- bobby


> -----Original Message-----
> I am trying to learn about the Popup List and as part of my 
> "learning" application, I have a List (ListVarietal - a list 
> of varieties of wine :-) !!).  When a slection is made, I 
> want to put up a Alert box to tell me what was selected - 
> just part of learning.  Well, I am not sure how to handle the 
> strings - even after reading the "Bible".  Now, some of my 
> Procedures/Functions are slightly different from "C" (I can 
> read "C", but I am not a proficient "C" programmer - Delphi 
> instead).  Below is my
> Event handler, but everything goes South!!  I get the message 
> that I am trying to access memory that should not be 
> accessed.  I understand this (thanks to the "Bible"), but I 
> do not know how to retrieve the Item and convert it to text 
> that can be put into the Alert (once I am comfortable doing 
> that, I will put it into an "Edit" field).
> 
> procedure PopuptriggerVariety_OnPopSelect(var Handled: 
> Boolean; ControlID: UInt16; ControlP: ControlType; ListID: 
> UInt16; ListP: ListType; Selection: Int16; PriorSelection: Int16);
> var
>   Form: FormPtr;
>   List: ListPtr;
>   ListIndex: UInt16;
>   P: MemPtr;
>   ListText: PChar;
> begin
>   FrmCustomAlert(AlertShow, 'Here I am!, '', '');
>   Form := FrmGetActiveForm;
> 
>   //From here on I am lost!!!!
> 
>   //The name of the List is ListVariety
> 
>   ListIndex := FrmGetObjectIndex(Form, ListVariety);
>   List := FrmGetObjectPtr(Form, ListIndex);
>   P := LstGetSelectionText(List, Selection);
>   ListText := MemHandleLock(P);
> 
>   MemHandleFree(P);
>   Handled := True;
> end;

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to