【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.2.4.38.16 Project::FindFunction
Contents
Description
Find a function in the specified file and compile and link it as needed.
Syntax
Function FindFunction( LPCSTR lpcszFunctionName, LPCSTR lpcszFileName = NULL, BOOL bCompileDependents = false, BOOL bSuppressPromptBox = false, BOOL bCheckFileChange = false, int nOverloadIndex = 0, const FunctionPointer& funcRef = NULL )
Parameters
- lpcszFunctionName
- [input] Name of function to be called
- lpcszFileName
- [input]Optional input name of file, if NULL then \OriginLab\lpcszFunctionName.cpp is used
- bCompileDependents
- [input]Optional input causes dependent (included) files to be compiled and linked
- bSuppressPromptBox
- [input]true will hide the box that comes up when the needed function has not been compiled and Origin C compiler must be invoked
- bCheckFileChange
- [input]true will recompile source file if it was modified since last time it was loaded, false will not
- nOverloadIndex
- [input]If there is more than one function with same name, need to specify this index to get the correct function pointer.
- funcRef
- [input]Optional. If there is more than one function with same name, pass the FunctionPointer object as prototype reference to obtain correct function pointer.
Return
Returns a valid pointer to the found function on success and an invalid function pointer on failure.
Examples
EX1
// This code demonstrates how FindFunction may be used // to make a function call by means of a function pointer void AddColumns(Worksheet& wks, int nn) { if( wks ) { for( int ii = 0; ii < nn; ii++ ) { wks.AddCol(); } } } typedef void (*FUNCTYPE)(Worksheet& wks, int nn); void myFunction() { string strPath; strPath.Format("%sOriginC\\OriginLab\\test.c", GetAppPath(TRUE)); Function fn = Project.FindFunction("AddColumns", strPath); FUNCTYPE pfn = fn; // Can also be done on one line: //FUNCTYPE pfn = Project.FindFunction("AddColumns", strPath); if( pfn ) { Worksheet wks; wks.Create(); pfn(wks, 5); } }
EX2
// following example can be found in OriginEvents.c typedef bool (*FUNC_OCEVENTS)(DataRange &dr, int nWinType); static void OnWksSelectionChange(DataRange &dr) { // can use relative path from OriginC subpath, also, file extention .c is assumed Function fn = Project.FindFunction("OnSelChange", "OriginLab\\GlobalEvents"); FUNC_OCEVENTS pfn = fn; if(pfn) pfn(dr, EXIST_WKS); }
EX3
// This is a complete example that shows how to call the import_file // function defined in OriginLab's FileImport.c file. #include <Origin.h> typedef int (*ImportFileFuncPtr)(LPCSTR strPageName, int nIndexLayer, LPCSTR lpcszDataFile, LPCSTR lpcszFilterName); void import_file_to_active_layer() { // This example will import Origin's simple group.dat file. string strDataFile; strDataFile.Format("%sSamples\\Graphing\\group.dat", GetAppPath(TRUE)); // Get full path of the file containing the function definition. string strPath; strPath.Format("%sOriginC\\OriginLab\\FileImport.c", GetAppPath(TRUE)); // Find the function in the specified file and compile and link it // and its dependencies. ImportFileFuncPtr pfn = Project.FindFunction("import_file", strPath, true); if( pfn ) { Worksheet wks = Project.ActiveLayer(); if( wks ) { WorksheetPage pg = wks.GetPage(); pfn(pg.GetName(), wks.GetIndex(), strDataFile, "ASCII.oif"); } } }
Remark
See Also
Header to Include
origin.h