The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 structures
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

mkoetse

Netherlands
Posts

Posted - 02/03/2004 :  5:30:06 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,

Could anyone tell me where I could find some more information (e.g. on the web) on using structures in (origin)C. I never used them before, and I'd like to learn how use of them.

Regards,

Marc

cpyang

USA
1406 Posts

Posted - 02/03/2004 :  7:43:57 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can read about struct in any standard C or C++ books. I just want to point out that Origin C has support for Tree and any branch of a tree can be assigned to a struct and vice versa.

This will allow low level functions to be written using struct as argument, to conform to standard C, and higher level functions can keep parameters in a tree and just pass branches of a tree into a low level C function via a struct.

The following code shows how this works,



#include <Origin.h>
#include <GetNBox.h>

// good to typdef a struct before using it
typedef struct tagTest
{
bool readOnly;
char filename[MAXFULLPATH];
} myStructTest;


// event handler for button in GetNBox to open File dialog
static bool get_file_name_handler(TreeNode& myTree, int nRow, int nCntrlType, Dialog& getNDlg)
{
string str = GetOpenBox("*.TXT Text file", GetAppPath());
myTree.filename.strVal = str;
return true;
}

void test_tree_to_struct()
{
GETN_TREE(myTree)
// make sure tree node tagName identical to struct member name
GETN_CHECK(readOnly, "Read Only", false)
GETN_BUTTON(filename, "File name", "c:\\test.txt")
GETN_OPTION_EVENT(get_file_name_handler)

if(GetNBox(myTree, "Save As", "Save some info into a file"))
{
myStructTest fInfo; // declare struct on stack
fInfo = myTree; // direct assignment from treenode to matching struct

printf("file = %s, read only = %d\n", fInfo.filename, fInfo.readOnly);
}
}




CP


Go to Top of Page

mkoetse

Netherlands
Posts

Posted - 02/04/2004 :  02:24:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanx,

But this is a few levels of programming ahead of where I'm standing right now, I'm afraid:)

MMK

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000