?
Solved

String to MemHandle

Posted on 2004-07-31
14
Medium Priority
?
231 Views
Last Modified: 2013-12-27
The code below has eluded me for quite awhile now and I have given up on how to perform a simple task like getting a string from a record into a text field due to the complete lack of documentation by Palm. This is really a C issue rather than Palm but as Palm is all about databases one would think that displaying the data would be a priority. The problem is with StrCopy and no matter what I do I get all these stupid errors like char* to struct_opaque* etc when trying to complie. Any help greatly appreciated.


static void ActionLoadRecords (FormPtr frm)
{
      FieldPtr fld;
      MemHandle h;
      Char*      buffer;
      Char      place[90];
      WChar      outChar;
      UInt16            index;
      UInt32      inOffset = 0;
      DmOpenRef gDB = 0;
      UInt16      length;
      UInt16      b;
      
      index = 1;
      h = DmQueryRecord(gDB, index);
      buffer =  MemHandleLock(h);
      MemHandleUnlock(h);
      
      length = StrLen(buffer);
      place [length];
      b=0;
      while (inOffset<length)
            {
            inOffset += TxtGetNextChar(buffer, inOffset, &outChar);
            if (outChar == nullChr)
                  {
                  place[b-1]=outChar;
                  }
            }
      StrCopy(h, place); //this is the problem line
      
      fld = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, ActionPrevField));
      FldSetTextHandle (fld, h);
      FldReleaseFocus (fld);
}
0
Comment
Question by:bravotango
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11683426
Hi bravotango,

I know a bit of C, if you can post the *exact* error messages here, may be I can be of some help

Sunnycoder
0
 

Author Comment

by:bravotango
ID: 11683475
Hello there Sunnycoder, thanks for the quick response. Here is the exact compile error:
Error   : illegal implicit conversion from 'struct _opaque *' to
'char *'
Action.c line 96   StrCopy(h, place);

Hope that helps.

Cheers

0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11683492
>MemHandle h;
>Char     place[90];
>StrCopy(h, place); //this is the problem line

StrCpy expects to have two char * s as its arguments ... here one of your arguments is MemHandle type ... are you sure this is correct ?

what is the data type of MemHandle? If you are confident that it is the same as char * (or atleast, if you want that to happen), then this should work

StrCopy(((char *)h), place);
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:bravotango
ID: 11683516
Yes Sunnycoder, I just ran that and it compiled without complaint but crashed on the emulator. Most likely your StrCopy(((Char*)h), place); did the trick but there is another problem somewhere. It seems I must have a MemHandle to get it out of the data record but I then need to work on that MemHandle so I convert it to a string and then I have to get it back to a MemHandle to get it into a field. Maybe I can work directly on the MemHandle h rather than a string. I will try that and see.
0
 

Author Comment

by:bravotango
ID: 11683558
I really think I need to somehow convert the string place to suit MemHandle h and not the other way round. I just don't know how to do that.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11683561
post the data type of MemHandle

error message indicates 'struct _opaque *'
Can you post struct _opaque here
0
 

Author Comment

by:bravotango
ID: 11683578
Sorry still the same error. I have run into this problem in the past and put it in the too hard basket. Can't find any example of it but there has got to be a simple way of getting data from a database into a field. Maybe I'm trying to do it the wrong way or something. I would like to see a simple app like a hello world thing with a database and a field but Metrowerks or Palm have never had the decency to do that.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11683591
Can you post struct _opaque here
0
 

Author Comment

by:bravotango
ID: 11683620
I tried struct_opaque and the compile error was the same as before. Sorry I had to leave for awhile to bait my cat trap as the cats were kicking up a row outside. Chicken is on the menu tonight.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11683644
find the definition of struct _opaque and post that definition here ... Do not try to compile by replacing char * with struct _opaque ... it will never work
0
 

Author Comment

by:bravotango
ID: 11683699
All I can find in the docs are numerous references to do with fields such as," Your code should treat the FieldType structure as opaque." whatever that means. FldSetTextHandle (fld, h) definitely requires h to be type MemHandle, the problem is getting string into that MemHandle.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 400 total points
ID: 11683889
What this tells me is that you should not try to copy a string into MemHandle ... MemHandle seems to be a struct which has several fields ...

Found some examples and references.... try these
http://www.codeproject.com/ce/palmdb.asp
http://www.palmos.com/dev/support/docs/palmos/FilesAndDatabases.html
http://www.palmos.com/dev/support/docs/palmos/DataAndResourceManager.html
0
 
LVL 6

Assisted Solution

by:msjammu
msjammu earned 1600 total points
ID: 11683972
Hi,

Sorry for being late but I thinkl I can Help

Your code I have modified

======================================
static void ActionLoadRecords (FormPtr frm)
{
     FieldPtr fld;
     MemHandle       h;
     Char*           buffer;
     Char           place[90];
     WChar           outChar;
     UInt16     index;
     UInt32     inOffset = 0;
     DmOpenRef       gDB = 0;
     UInt16     length;
     UInt16     b;
     
     index = 1;

     h = DmQueryRecord(gDB, index);
     buffer =  MemHandleLock(h);
     //MemHandleUnlock(h);
     
     length = StrLen(buffer);
     
     //place [length];
     
     b=0;
     
     while (inOffset<length)
     {
           inOffset += TxtGetNextChar(buffer, inOffset, &outChar);
        if (outChar == nullChr)
        {
              place[b]=outChar; //Modified b from b-1
        }
        b ++; //I addedd
     }
     
     //StrCopy(h, place); //this is the problem line
     StrCopy(buffer,place);
     
     fld = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, ActionPrevField));
     FldSetTextHandle (fld, h);
     FldReleaseFocus (fld);

     MemHandleUnlock(h); // Inserted here
}

======================================

I try to explain the Problem

MemHandle is a Void* data type.

I is used to allocate memory for Movable chuncks

Now DmQueryRecord returns such a unlocked handle whitch you store in some memhandle type variable

Palm OS can move this chunck for memory management So you have to lock this chunck for the time you require to process/access its data.

So MemHandleLock locks the check and return the ptr of type char*

You can perform operations on that pointer type such as Updations deletions
at the end when you unlock all the updations are retained in original handle

that handle can be assigned to a field
as FldSetTextHandle

Any query plz ask

Regards,
0
 

Author Comment

by:bravotango
ID: 11687255
I am indebted to msjammu. You solved my problem . I was about to give up and look for some other way. Many thanks for your help and also to sunnycoder for looking for a solution. My biggest error was to try to StrCopy to the MemHandle instead of to the pointer.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When I was a beginner in Windows Mobile programming, even for small test I used to create a single MFC dialog-based application with one button, and put my test code in the OnLButtonDown method. For Pocket PC it worked fine, on some Windows CE d…
With Windows Embedded Handheld, called Windows Mobile, Microsoft re-designed the user interface. The Start Icon moved down to the bottom, inside the menu bar area.   If you need to hide the Start Icon and/or the SIP (soft input panel, softwar…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question