Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
14
Erster Beitrag:
vor 5 Jahren, 6 Monaten
Letzter Beitrag:
vor 5 Jahren, 5 Monaten
Beteiligte Autoren:
David Egan, RAUL2, Stefan Bentvelsen, Jeremiah Lin, Carlo Hermus, Ola

[WD17] How to share the project context in an external component

Startbeitrag von Stefan Bentvelsen am 26.11.2012 10:34

Hi all,

the subject says it all.

I've made an external component and use it in a particular project.
How can I configure th component to share the project context (mentioned in the help file, see notes of ComponentInfo() function) ?

I cannot find anything about it in the help file.

Antworten:

Re: [WD17] How to share the project context in an external component (SOLVED)

Hi,

I've found how to share the project's context with the external component.
You have to use ComponentLoad() with the ccGlobal option. Example:


ComponentLoad(VisualUserGroupware,"",ccGlobal)


von Stefan Bentvelsen - am 26.11.2012 13:54
Hello Stephan.
I think this thread can answer an old question of mine... The thing is: I compile an external component containing code to change de DB (HChangeConn...()) issuing a code posted by Guenter to select a Classic or C/S HF DB by an INI file. The problem I've found is that it seems that the component has its own context. The code (HChangeConn()) is executed inside the component but doesn't change my DB at all. The only way I could make it work is getting rid of the component and issuing instead a set of procs (because the code executes in the same context I guess...)

I should try it again of course, but do you think that the ccGlobal might work?

Regards.

von RAUL2 - am 27.11.2012 20:40
Raul2,

I think you need to create a library instead. I have tried to implement components in the past and 2 things I realy needed didn't work for me.

1. Load component based on availability in a directory not hardcoded in the main application.
2. Integrate the Datafiles of the components with the main application and other components.

I ended up by creating 1 application 1 analysis. It has cost me to much time already to figure out if it was my own knowledge or it was not possible.

von Carlo Hermus - am 27.11.2012 22:57
Hi Guys
We had similar hassles but got components working nicely eventually. We do virtually everything by query however so not sure whether using Hcommands would impact on this.

Our app is structured modularly so we have a separate component for each module, one for data acess & one for all the lookup windows. The only component which is aware of the data or the analysis is the Data Access component; each other component includes it & our parent Exe project includes all the components.

Within the Data Access component we have an Application class which makes the connection (details from an Ini file). The Connection method is called as part of the Constructor. The Application class is instanciated from the Project Initialisation code of each other component (although this is a global class & this is not strictly necessary we found it preferable, mainly so we would know what's going on!). Essentially then we end up with a separate connection for each module. Our Data Access component has at least one class for each file (or more accurately each business object) & these classes do all the data updating/ retrieving etc.

I would have preferred to have it all working on a single "shared" connection but couldn't find any way to do this. A similar problem which we did manage to resolve was to do with global variables and classes which need to be identical in each component (eg we have a class which holds the current user details. If that is changed, every component must reflect that change). We got round this one by declaring all these things within the Application class & then using Memory Zones. A global procedure in our Application class is called whenever a global variable or class is changed, which updates the Memory Zone. Took a fair bit of sweat & tears before I got it sussed but it now works like a charm. If this is any help let me know & I'll post the code

Cheers

David Egan

von David Egan - am 28.11.2012 07:42
I have ended up on the same line of thinking as Carlo.

I have a rather extensive app with several "sub-systems", many of which would be ideal candidates for a component. In my old DOS app-collection having the same functions I hade some 20 full-size exes using the same set of data and screens (windows).

But if everything needs to be seamlessly integrated with everything else, then I cannot see any other (simple) solution than to include everything in a single app and single analysis.

This makes everything very compliant with the KISS priciple, and currently this is quite OK, as the resources of even today's cheapest computers are practically limitless.

The main "problem" with this approach is the large file size of the files which slows down any update process over internet (with a few seconds, or minutes at worst...).

Best regards
Ola
http://www.pienoismalli.com
http://www.datamyyra.fi

von Ola - am 28.11.2012 12:28
Hi Raul2,

yes, I think the ccGlobal option might work.
In my case it does make the difference.

von Stefan Bentvelsen - am 28.11.2012 14:51
Quote
Carlo Hermus
Raul2,

I think you need to create a library instead. I have tried to implement components in the past and 2 things I realy needed didn't work for me.
....

Carlo, in that opportunity, time was against me, and the only "fast" solution was to compile everything into a single project. So, I've never tested the library approach but it could be interesting.

Regards.

von RAUL2 - am 28.11.2012 20:36
Quote
David Egan
... If this is any help let me know & I'll post the code

Cheers

David Egan

Hi David. I think it would really great if you can post some code, or at least, the conceptual solution for this problem.

The main mistery for me is: how do you access your data from the component and expose it to the parent EXE!!!???

It would be great to collaborate for creating a kind of framework (classes, componentes, whatever...) to separate the data access from the presentation layer. In that case (your case I guess), how do you bind data to the controls?

Kind regards.

von RAUL2 - am 28.11.2012 20:44
Hi Raul
Sorry for the delay, been out of the office for a couple of days.

Most of the code for our Data Access component uses OOP, based on Peter Holeman's excellent OOP stategy document http://repository.windev.com/resource.awp?file_id=91;exemple-pour-utiliser-une-strategie-poo%E2%8C%A9=UK which I highly recommend. However I'm sure with some modifications the general concept should work fine in a non-OOP manner.

Our approach is basically as follows:
Data Access Component
Includes Application class which makes the connection to the database
Has class for each data file, with fields named identically to the analysis.
'Find' method of class moves data from file into object via FileToMemory(object,DBFilename)
'Save' method of class moves data from object to file via MemorytoFile(object,DBFileName) & then HAdd or HModify

Executable
Application class is declared in Project Init & connects to database
Window declares instance of File class in window init code (MyDataClass is cDataFile )
After this is declared, the variable (or more accurately each 'field' within the object) is available for data binding to controls in the IDE
MyDataClass.Find()
SourceToScreen(MyWindow..Name,"MyDataClass") Alternatively data can be accessed directly via MyDataClass.FieldName
To save record, ScreenToSource or directly as above. Note it is always the object fields we are working with, never the data file fields. Then MyDataClass.Save()

Hope this helps. If you can't make sense of it, let me know & I'll see if I can put together a small project which shows this working & make it available. Might take a few days though as I am pretty busy at the moment.

Cheers

David

von David Egan - am 30.11.2012 06:02
Hi
I have put together a small project (actually 3 projects) which shows how we use components. The 3 projects are the Executable, a Data Access component which is the only place where the data is physically accessed and a Dataview component which handles lookups.

The project can be downloaded from www.expresslanepos.com.au/WinDev/Component.zip


Cheers

David

von David Egan - am 13.12.2012 19:37
Quote
David Egan
Hi
I have put together a small project (actually 3 projects) which shows how we use components. The 3 projects are the Executable, a Data Access component which is the only place where the data is physically accessed and a Dataview component which handles lookups.

The project can be downloaded from www.expresslanepos.com.au/WinDev/Component.zip


Cheers

David

Hi David, thanks a lot!!! I'll take a loot at that.
Best regards.

von RAUL2 - am 13.12.2012 21:16
Hi David,

thanks for the sample DataAccess, DataView, Executable

but where do you put logic to update another file?
do you use Application Trigger (Update components) or
Database Trigger?

Best Regards
Jr

von Jeremiah Lin - am 03.01.2013 09:11
Hi Jr

All updating is done via the Data Access component through classes. I personally do not use triggers at all, although that would certainly be a valid way to do it.

If there are multiple files to be updated then that is directly handled within the class, generally with a separate method called within a transaction frame to ensure that all related files are updated or the main object class may instanciate a class for a related file and handle the update that way, depending on the situation

Bear in mind that a class is not necessarily a data file; it is a business object which can read & write to multiple files. For example we have a sales transaction class which is used for each line of a sale. This writes to something like half a dozen files, all of which are handled directly within the class.

HTH

David

von David Egan - am 03.01.2013 19:05
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.