writing a cfc with better technique - coldfusion

i have one question, i have a parent cfc created generic file and a child cfc created. now i created one method method in child cfc and used that function in the parent cfc to run my code and return me the status of true/false.
the above is working but i want it to be a better way, using a setter/getter and property tags to make it that generic so i do not have to use the child function call in parent because that is breaking the oops concept, any idea how can do it
right now i have this
parent.cfc
if(mychildfunction() = 100) {
dump("yeah")
}
else {
dump("no")
}
child.cfc
function mychildfunction() {
return "90"
}

Related

CMDIFrameWnd::MDIGetActive returns null when called from external code

I have inherited some legacy code that i'm required to integrate with a modern c# GUI. The codebase is a MFC MDI application, that creates a type library and registers a COM component to expose the application API for external applications and scripting.
Throughout the MFC application (henceforth I will refer to the MFC code as "the application") there is a function that checks for an active MDI document and returns it, or null. This method is called from a "MainFrame" class which inherits CMDIFrameWnd. it looks something like this:
CMDIChildWnd * pChildFrame = MDIGetActive();
if (pChildFrame)
{
CDocument *pDoc = (CDocument *) pChildFrame->GetActiveDocument();
if (pDoc)
{
return(pDoc);
} else {
return NULL;
}
I have created a test c# console application and can successfully import the COM component and access the API, and make calls to it. The problem is that whenever I call something that requires an active document via the API, MDIGetActive() returns null. For example, I can open a document via the API, and I can visually confirm it opens in the running MFC application. But if I call the API method to save this file, the active document is null. But if I call the same method via the application GUI, this works fine. It is the same function call, the exposed API method is just a wrapper.
Strangely enough when I open a file via the API method, it eventually executes the same check for an active document which succeeds. After getting the active document, it calls CDocument::UpdateAllViews() to update the UI. Any calls made after this via the API will result in no active document.
I'm at a loss here, I can't understand why the active document is null. I'm still working my way through MFC documentation but I haven't found anything that would suggest why this is the case. Does anyone know?
Another way to avoid any GetActiveWhatever() method is the following code, which can be called from your CYourApp class:
POSITION posDoc, pos = GetFirstDocTemplatePosition();
while (NULL != pos)
{
CDocTemplate* pDocTemplate = (CDocTemplate*)GetNextDocTemplate(pos);
posDoc = pDocTemplate->GetFirstDocPosition();
while(NULL != posDoc)
{
CDocument* pDoc = pDocTemplate->GetNextDoc(posDoc);
if(NULL != pDoc)
pDoc->UpdateAllViews(pSender, lHint, pHint);
}
}
Of course, once you have the document, you'll have any view attached from that document.

How do I manage recurrent child UIViewControllers?

Scenario:
I instantiate a UIViewController and added it to a
containerViewController.
I dismiss (remove) this child
I select this same child to display again.
My Concern: I wish to create a single child UIViewController instance. But It appears that I would create an additional instance of the child view controller per 'case' iteration, which I do not want.
Question: Does Swift already handle this? ...or must I check for the current view controller's instance prior to making it a child?
If I have to check for its existance, then I'll have to make 'viewController' global for all cases.
No Swift doesn't handle this automatically. You must check the existing child view controllers to prevent adding duplicates.
You could use code like this:
if let controller = parent.childViewControllers.filter { $0 is CountriesViewController }.first {
// use existing child controller here
}
else {
// create new child controller and add it to parent here
}

C++, Passing custom class object in wxWidgets

Can someone explain me how to pass a custom class object to another function in wxWidgets? I have a wxDialog class called AddUser which contains a void type OnButtonClick function that creates an object of a custom class "User". How can I pass that object to another OnButtonClick function that is located in Main class?
One important thing to know (in case you don't already) about wxDialog is that it is quite okay to create them on the stack (most wxWidgets windows should be created on the heap).
This means that your dialog instance remains available even after it has been closed by the user pressing "Ok". You can test for user responses by the following code:
... existing method ...
AddUser dialog (this);
if (dialog.ShowModal() == wxID_OK)
{
... process new user ...
}
Because the dialog is still instantiated, you can include a method in your dialog code that returns the new user as follows:
User AddUser::GetUser ()
{
return newUser;
}
However, you should of course be careful where the new user is actually created. For example, if the new user object is created locally in the dialog, then you will need to make a copy of it (as the above example will do). If it is created on the heap (which I wouldn't advise) then you can return a pointer. A third alternative would be to pass a reference to the GetUser method so the dialog method looks like this:
bool AddUser::GetUser (User& user)
{
// Make sure that all fields are valid. Simple example given, but
// should be more complete.
if (TextName->GetValue() != "" && TextSurname->GetValue() != "")
{
user.setName(TextName->GetValue());
user.setSurname(TextSurname->GetValue());
return true;
}
return false;
return newUser;
}
And the call looks like this:
void wxBiblioFrame::OnButAddUserClick(wxCommandEvent& event)
{
AddUser dialog(this);
myUserDialog dialog (this);
myUserClass newUser;
if (dialog.ShowModal() == wxID_OK)
{
if (dialog.GetUser (newUser))
{
... process and store the new user ...
}
else
{
... handle the error ...
}
}
// NOTE: no need to Destroy() the dialog.
}
By the way, unless your user class is huge, I wouldn't be too concerned making copies of the object from an efficiency point of view. Creating and closing the dialog is likely to dwarf any time taken in making a copy.
You can't call an OnClick event and pass something different than the parameters in the event signature. If you need somthing like tis then maybe you should consider reiterating your application's architecture.

Firemonkey: Getting parent form of control

I have a custom control which needs to get access to the height of the main form it is on. Since it is common for this control to be nested in a series of panels, I have written this code to try and get me to the main form:
TControl * control = this;
while( control->HasParent() )
{
control = control->ParentControl;
ShowMessage( control->Name );
}
Using the ShowMessage statement to track my progress, as I step through the code I get all the way up to "BasePanel" which in this case is the last control up the ladder before the "MainForm." However, when the call to ShowMessage happens for what should be the "MainForm" I get an access violation.
Is there some reason I am unable to access the main form of a control this way? Is there a better way to access a control's main form?
You are not checking if ParentControl returns a NULL pointer before reading its Name. When HasParent() returns true, ParentControl is NOT guaranteed to be valid. Case in point - TForm is NOT a TControl descendant in FireMonkey, so it cannot be returned by ParentControl.
The purpose of HasParent() is to report whether the component has a parent or not. TFmxObject overrides HasParent() to report whether the TFmxObject.Parent property is NULL, and overrides GetParentComponent() to return an appropriate TComponent for that parent. TFmxObject.Parent returns a TFmxObject, as parent/child relationships do not have to be visual in FireMonkey like they do in VCL, so Parent and GetParentComponent() can actually return different objects at times.
You should be using GetParentComponent() instead of ParentControl, as the documentation says:
Call HasParent to determine whether a specific component has a parent.
Derived classes override this method to implement proper handling for parenting.
Use GetParentComponent to retrieve the component reference.
For example:
TComponent * comp = this;
while( comp->HasParent() )
{
comp = comp->GetParentComponent();
ShowMessage( comp->Name );
}
However, if your intent is to find the parent TForm specifically, use your control's Root property instead:
TCommonCustomForm *form = dynamic_cast<TCommonCustomForm*>(this->Root->GetObject());

Multiple windows with QT

I'm a student and for my thesis I want to create a question-based game; I would like to use QT to elaborate the graphical interface, but I've never used it and I don't know how to create an application with multiple windows.
There is a base-class (abstract) called "Form" and three others classes that inherits from Form: MainMenuForm, LoginForm and GameForm.
In some of the examples I found, the layout of the window is setted in the constructor and in the main is called the method show(), but I would like to do something like this in the main:
// Creates a FormFactory object and ensures singleton instance
FormFactory * factory;
factory = factorySingleton.GetFactory();
//select a Form to display
int choice = 1;
Form * actualForm;
while (choice != 0)
{
factory->Init(choice);
actualForm = factory->ReturnActualForm();
choice = actualForm->Display();
}
The Display method, common to every derived-Form, must return an int that indicates which window display (for example, the Display method of MainMenuForm returns 2 if the user want to proceed to the Login window or 0 if the user want to close the application); obviously, the Display method must also show the form.
Finally, I noticed that in all examples they write
return app.exec();
in the end of the main.
For my project, where am I supposed to write app.exec()? Before, after or inside the while statement?
Your design is quite bad. The code you quoted should be in a separate class which is instantiated before calling app.exec(). The current solution only allows to select the form once, it will be displayed and when you close it, the program ends.
Read Qt docs about signals and slot, and how to write Qt GUI apps, you need a different approach.