Flex 4 Targeting Components that were created at run time - flex4

I have some components that are created at run time, I would like to execute functions in those components during certain parent events.
Problem is this only works with components I create before runtime.
EG I can go this[SomeComponent].BorderShow(); if SomeComponent was already in the code.
How ever if I add new components to the stage on the fly I cant go
this[SomeNewComponent].BorderShow()
Can someone please advice how I could pass a function the name of component as a string and then have said function execute a function or method from the component.
Please and thank you
C

I eventually used an Object as a proxy to the component found by name so that I could target its methods.
C

Related

Calling function of Exe project in referenced aticvex project in vb6

Calling function of Exe project in referenced aticvex project in vb6
I have one AtiveX project in VB6 (Lets call it A )
i have another Exe project in VB6 (Lets call it B )
Project A is referenced in Project B
but now i have a requirement that i want to call function of B inside A
is there a way Can we do it in VB6?
if yes what do i need to search.Already tried searching on Google but not sure i could explain what to search
As i didn't work much on VB6 so i am kind a stuck here what to do
First off let me say that when you run into this problem it is often a sign that the code organization could be improved. Perhaps some modules in A actually should be in B, or they could be broken down in a more modular way that would resolve the problem. I would first encourage you to think about the problem this way.
That said, there are technical ways of doing what you want, I've suggested some examples below.
One approach to this is to utilize an interface. The interface would be provided by A.dll and the class used to implement it is provided by B.exe.
This is rough pseudocode just to sketch out the concept.
Within project A:
Create a class to act as an interface (called ISample). Within ISample have at least one sub or function defined, so you would have ISample.SomeProcedure.
Elsewhere in project A, you need some property or procedure SomeClassInA.RunSampleFunction which will accept an object of type ISample and then call SomeFunction.
Within project B:
Create another class SampleImplementation which Implements the ISample interface. This means it will have an actual concrete implementation of SomeFunction.
From B, create a new object of type SampleImplementation and then pass it to the code in A:
Dim impl As SampleImplementation
Dim objectFromA As SomeClassInA
Set impl = New SampleImplementation
Set objectFromA As New SomeClassInA
' Pass the object from B to A, where A can call its methods:
objectFromA.SomeProcedure impl
This avoids circular references and is a generally object-oriented pattern which I've used before. I will note however that the interface concept in VB6 has some annoyances that you'll have to live with, but for something like this it can be a good tool.
A different approach would be to have a class in A which exposes an event. You can then declare an object from that class in B using WithEvents and attach an event handler to the class. The event handler is just a procedure which exists in B, but now can be called by A.
Events in VB6 also have some limitations (specifically that the WithEvents object has to be within global scope IIRC) but you can usually live with / work around those problems as well.
The interface approach may be more general and a more powerful way to share information between A and B, but the event approach could be quicker to get working. Depends a lot on the specifics of what you need to accomplish.

Customizable model file for a Laravel 5 package

I'm developing a Laravel 5 package where I have a "Member" model which currently extends App\User model. I would like to know the best practice to let any developer use a custom "Member" model instead of the one from the package. This is for example to allow a developer use another table.
One approach that seems to work without having done a deep test with it is to make an alias in my package service provider in the register() method:
$MemberModel = 'MyVendor\MyPackage\Member';
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('MyMember', $MemberModel);
In this case I have to:
Replace all entries in the code from the original class to the alias
Delete all php "use" entries related to it
Get the value of $MemberModel from a config file or the database
But I don't know if it is a good way to solve it or It may cause any conflict.
Is there any other and better approach for this goal? Thanks in advance!
I finally had to test by myself this approach without haven't read the solution anywhere else, but anyway everything seems to work fine in my source code.
If anyone is looking for doing anything similar, the code example in my question works because the $MemberModel is defined with a value. If you want to get that value from a Model instance, as me, you have to add that code in the boot() method of the service provider.

Declaring stores, models and views in app.js?

I want to know if it is an obligation to declar all stores/Models/views that my application has in the app.js ? I'm saying that because I have tested the following situation : declaring just controllers in app.js and then trying to set needed stores/Models/Views in the corresponding controller.js, but doesn't work [undefined store...] !
in my case I'm structuring the application in modules like this :
app.js
Sales
-- salesController.js
-- salesStore.js
-- salesModel.js
-- salesView_1.js
Account
-- accountController.js
-- accountStore.js
-- accountModel.js
-- accountView_1.js
-- accountView_2.js
and so on...
Any information about this ?
According to what the question's owner said, he has already known how to define an application in MVC structure. The point is: why Ext.require in controllers alone does not work, right?
There are some descriptions about explicit definition of controllers,stores,models,views in app.js:
profiles - instantiates each Profile and determines if it should be active. If so, the Profile's own dependencies are also loaded
controllers - instantiates each Controller after loading
stores - instantiates each Store, giving it a default store ID if one is not specified
It means that all of those necessary stuffs are initiated before and right when your application is loaded. But Ext.require does not, because it's designed for asynchronous way. For example, say that in your controller (which you requires all other stuffs: models, views, stores), you jump in a view that use a store, which is defined by class, not any initiated instance, so it left undefined.
Shortly to say, the formal way to declare all required stuffs in app.js ensures you have an instance (of controller/store/model/view) when you need it. But Ext.require support your class code, not instance initialization.

What determines the order of compliation or execution of source file in Delphi Prism?

Having written my Delphi Prism program enough to compile and run on Window and Linux (mono) without compilation errors, I am finding out that my constructors and load events are firing at different order than I expected. I thought, files get executed in the order that they are listed in the project file like in Delphi .dpr file. Speaking of .dpr file, is there a similar file for Delphi Prism that I am not looking into. I looked into program.pas file and properties. I didn't see anything there to give me a hint or clue.
How do you make sure that the project files get executed in right order in Delphi Prism?
Delphi Prism compiles in the order the files are defined in the project. However, there should not be anything that depends on the order of the files as there are no initialization sections.
As for your other question. Program.pas by default contains the entry point, it's a method called "Main", you could see this as the main begin/end.
.NET does not know about the order your classes are listed in your program file. It just sees classes.
Under normal circumstances you could think of this rule:
Static (class) constructors are executed immediately before the instance .ctor or another static (class) method is called on this class for the first time
While this is not true every time (they could be called earlier, but not later), this is a good approximation which works out most of the time.
So to ensure a certain order for static class initialization, I rely on the following:
I have one static class that has an Initialize() method. This method is the first thing I call in the Main() method of my program. In this method I call Initialize-Methods on other classes in the required order. This makes sure, that the initialization code is executed.

CodeIgniter: Decision making for creating of library & helper in CodeIgniter

After developing in CodeIgniter for awhile, I find it difficult to make decisions when to create a custom library and when to create a custom helper.
I do understand that both allow having business logic in it and are reusable across the framework (calling from different controller etc.)
But I strongly believe that the fact that CI core developers are separating libraries from helpers, there has to be a reason behind it and I guess, this is the reason waiting for me to discover and get enlightened.
CI developers out there, pls advise.
i think it's better to include an example.
I could have a
class notification_lib {
function set_message() { /*...*/}
function get_message() {/*...*/}
function update_message() {/*...*/}
}
Alternatively, i could also include all the functions into a helper.
In a notification_helper.php file, i will include set_message(), get_message(), update_message()..
Where either way, it still can be reused. So this got me thinking about the decision making point about when exactly do we create a library and a helper particularly in CI.
In a normal (framework-less) php app, the choice is clear as there is no helper, you will just need to create a library in order to reuse codes. But here, in CI, I would like to understand the core developers seperation of libraries and helpers
Well the choice comes down to set of functions or class. The choice is almost the same as a instance class verses a static class.
If you have just a simply group of functions then you only need to make a group of functions. If these group of functions share a lot of data, then you need to make a class that has an instance to store this data in between the method (class function) calls.
Do you have many public or private properties to store relating to your notification messages?
If you use a class, you could set multiple messages through the system then get_messages() could return a private array of messages. That would make it perfect for being a library.
There is a question I ask myself when deciding this that I think will help you as well. The question is: Am I providing a feature to my framework or am I consolidating?
If you have a feature that you are adding to your framework, then you'll want to create a library for that. Form validation, for example, is a feature that you are adding to a framework. Even though you can do form validation without this library, you're creating a standard system for validation which is a feature.
However, there is also a form helper which helps you create the HTML of forms. The big difference from the form validation library is that the form helper isn't creating a new feature, its just a set of related functions that help you write the HTML of forms properly.
Hopefully this differentiation will help you as it has me.
First of all, you should be sure that you understand the difference between CI library and helper class. Helper class is anything that helps any pre-made thing such as array, string, uri, etc; they are there and PHP already provides functions for them but you still create a helper to add more functionality to them.
On the other hand, library can be anything like something you are creating for the first time, any solution which might not be necessarily already out there.
Once you understand this difference fully, taking decision must not be that difficult.
Helper contains a group of functions to help you do a particular task.
Available helpers in CI
Libraries usually contain non-CI specific functionality. Like an image library. Something which is portable between applications.
Available libraries in CI
Source link
If someone ask me what the way you follow when time comes to create Helpers or Libraries.
I think these differences:
Class : In a nutshell, a Class is a blueprint for an object. And an object encapsulates conceptually related State and Responsibility of something in your Application and usually offers an programming interface with which to interact with these. This fosters code reuse and improves maintainability.
Functions : A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value. You already have seen many functions like fopen() and fread() etc. They are built-in functions but PHP gives you option to create your own functions as well.
So go for Class i.e. libraries if any one point matches
global variable need to use in two or more functions or even one, I hate using Global keyword
default initialization as per each time call or load
some tasks are private to entity not publicly open, think of functions never have public modifiers why?
function to function dependencies i.e. tasks are separated but two or more tasks needs it. Think of validate_email check only for email sending script for to,cc,bcc,etc. all of these needs validate_email.
And Lastly not least all related tasks i.e. functions should be placed in single object or file, it's easier for reference and remembrance.
For Helpers : any point which not matches with libraries
Personally I use libraries for big things, say an FTP-library I built that is a lot faster than CodeIgniters shipped library. This is a class with a lot of methods that share data with each other.
I use helpers for smaller tasks that are not related to a lot of other functionality. Small functions like decorating strings might be an example. Or copying a directory recursively to another location.

Resources