Support Board
Date/Time: Wed, 05 Mar 2025 18:29:28 +0000
[Programming Help] - ACSIL - How to use sc object in header file?
View Count: 709
[2022-01-13 20:57:03] |
frozentundra - Posts: 94 |
Hello, Context of my question: I'd like to create a "helper" header file with functionality I will re-use across studies I write. Rather than re-writing these helper functions every time I make a new study, I want to create a single header file that will house all of these helper functions. I could include this helper header file in new studies and be able to shorten my dev time. The good: The header file I was able to create and include with my study file. Both compile fine without errors. The question: How do I reference the SCStudyInterfaceRef sc object that is injected into the SCSFExport scsf_MyStudyName function from my helper.h header file? How are other developers accomplishing this? |
[2022-01-13 21:09:34] |
User907968 - Posts: 834 |
ACSIL Programming Concepts: Passing ACSIL Interface Members Structure To Secondary Function
|
[2022-01-13 21:29:04] |
frozentundra - Posts: 94 |
@User907968 - passing in the object to other calls works, but is there a way to pass it in one time, not on every function call? For example, how to pass it in to the constructor, store it on the header file side, and access it from the header file functions? Does that make sense?
|
[2022-01-14 12:18:32] |
User310645 - Posts: 49 |
Each time Sierra calls into your study you get a new SCStudyInterfaceRef so no you cannot store it between calls. If your objects are created and destroyed on each call then yes you could pass the sc ref in a constructor to any class you define in a header file. Header file class SomeFuncClass { public: SomeFuncClass(SCStudyInterfaceRef r) : sc(r); DoSomethingWithScRef() { sc.Something(); } private: SCStudyInterfaceRef sc; } Normal study .cpp file SCSFExport scsf_StudyEntryPoint(SCInterfaceStudyRef sc) { /* usual study setup/init */ SomeFuncClass myObj(sc); myObj.DoSomethingWithScRef(); } If you have objects you want to persist across study entry calls then you would have to use sc.Get/SetPersistentPointer(). However, you would still need to update any stored study ref on each call into the your study. |
[2022-01-14 15:16:56] |
frozentundra - Posts: 94 |
@User310645 - Thank you for providing this help. I had to make one minor change to your header file example, to include { } after I assign r to sc. Now I can instantiate my Helper obj from my header file once in my study, pass the sc object into the constructor, and from there on out just call helper method calls as needed from that object. Thank you again, really appreciate it. |
To post a message in this thread, you need to log in with your Sierra Chart account: