Solved

String to MemHandle

Posted on 2004-07-31
14
223 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
  • 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 100 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 400 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now