Hello,
It is probably not necessary to go thru all that documentation from Microsoft to understand what foreach does in Origin C.
The foreach construct allows you to loop thru the collection of all objects in a class.
Consider the following example:
void test1() { // Delcare worksheet object Worksheet wks("Data1"); // Loop thru all columns of the worksheet foreach(Column col in wks.Columns) { printf("Column name: %s\n",col.GetName()); } }
The Worksheet object contains a collection of Columns, and foreach is used here to loop thru all columns in the data1 worksheet.
Let us look at another example: The Project class consists of a collection of Pages (Worksheets, Matrices, Graphs, Notes etc). A Page in turn is a collection of Layers (Graphs can have multiple layers, Worksheet has only 1 layer etc.). If the Page is a Worksheet, then the Layer then consists of a collection of Columns.
In the code below, foreach is used first to loop thru all Pages of the Project, and then to loop thru all columns of Worksheet Pages.
void test2() { // Declare Project to point to current project Project proj; // Loop thru all Pages (windows) in Project foreach(PageBase pb in proj.Pages) { // Check Page (window) type. Worksheet is type = 2 int iType = pb.GetPageType(); //if Page is Worksheet, then if(iType == 2) { // Cast the PageBase object to a Page object Page pg = pb; // Report name of the Page printf("Page name: %s\n",pg.GetName()); // Loop thru all layers of the Page (Wks has only one layer) foreach(Layer ly in pg.Layers) { // Cast the Layer object to a Worksheet object Worksheet wks = ly; // Loop thru all Colums of the Worksheet foreach(Column col in wks.Columns) { // Report name of Column printf(" Column name: %s\n",col.GetName()); } } } } }
You can look for more examples on using foreach by searching for it in the Origin C Help file.
Easwar OriginLab.
P.S. This forum removes all tabs/indents and so the code examples above do not look good, but they should work fine! |