|
| [WD18] Creating a view in a class |
| Iniciado por guest, 17,nov. 2014 09:21 - 10 respuestas |
| |
| | | |
|
| |
| Publicado el 17,noviembre 2014 - 09:21 |
Hi Everyone
I want to move the creation of a view into a class.
This next two lines of code needs to go somewhere in the class, but I just can't figure it out.
MyView_EAINFO is Data Source HCreateView(MyView_EAINFO, EAInfo_A, "EAINFO_ID", "", "", hViewDefault)
This method below should "See" this View, but the compiler is complaining about inaccessibilty.
PROCEDURE GLOBAL TestView(nEAINFO_ID) IF HReadSeekFirst(MyView_EAINFO,EAINFO_ID,nEAINFO_ID) THEN Info("Found") END
Placing the creation of the view in the method doesn't make sense as I don't want to create the view everytime this method is called. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,noviembre 2014 - 10:43 |
Hi,
MyView_EAINFO is Data Source goes in the Class declaration. (between "is a class" and "end") HCreateView can go in the Constructor code or if you want to be able to re-initialize the view with different parameters then you create a new method and create the view there.
Regards, Piet. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,noviembre 2014 - 12:18 |
Hi Piet
Thank you for the information.
I'm still not there. There are two errors left and I hope that you can assist.
The button on the form that calls this method gives me the error "'TestView' method of 'clGlobalView' class is not global : it cannot be called from a global method.
and the "TestView"methhod say that "the identifier "EAINFO_A_ID' is unknown or inaccessible.
I've tested the code (All code in another button) to make sure that the field names are correct. Somehow, I miss an important placement of the code at the right place.
The code in the button: clGlobalView.TestView(1)
and the classs:
clGlobalView is a Class MyView_EAINFO is Data Source END
PROCEDURE Constructor() HCreateView(MyView_EAINFO, EAInfo_A, "EAINFO_A_ID", "", "", hViewDefault)
PROCEDURE Destructor()
PROCEDURE TestView(nEAINFO_ID) IF HReadSeekFirst(MyView_EAINFO,EAInfo_A_ID,nEAINFO_ID) THEN Info("Found") END |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,noviembre 2014 - 12:39 |
Hi,
You need to declare an instance of the class first in the button code and then use that instance to call the procedure: clMyGlobalView is clGlobalView clMyGlobalView.TestView(1)
Regards, Piet |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,noviembre 2014 - 12:56 |
Hi
why do you declare the class method as global?
Best regards |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,noviembre 2014 - 12:56 |
Hi Piet
So close, but still so far.
I still sit with the remaining error.
"TestView"methhod say that "the identifier "EAINFO_A_ID' is unknown or inaccessible.
The "EAINFO_A_ID" is in the datafile and in the view, but somehow it doesn't recognize it. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,noviembre 2014 - 13:11 |
Hi Fabrice
In my many attempts to solve this, I've put GLOBAL in the beginning of the process to resolve this issue. I've removed it as you can see in my second post to Piet, but I still sit with this final error. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,noviembre 2014 - 13:46 |
I guess the compiler isn't smart enough to "see" what fields are in your view, because the view is build in code. I would use a query instead of the view. Much more readable, better to maintain and then the compiler knows about it. And also intellisense can help you while editing |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,noviembre 2014 - 13:59 |
Hi,
Use quotes :
IF HReadSeekFirst(MyView_EAINFO,"EAInfo_A_ID",nEAINFO_ID) THEN Info("Found") END
Regards, Bart |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,noviembre 2014 - 14:35 |
Hi MvdW,
Just few notes: (1) Data sources name are not behaving the same in classes as elsewhere, (2) Connections are broken in classes in some specific use cases (not fixed yet as of WD19). I understand that you use a datasource in classes.
Make sure to give the exact name you want in your data source using the name property else the data source name will be prefixed with the class name. This is not your immediate problem but I give you the information.
For your class, following what you want to do: - Declare the Data Source as Global (private if you want) - Then either: - Put the creation code of the view inside the constructor of the class. Why? Because if you put the code in the declaration section of the class, it could be invoked way before the analysis and DB connections are opened. So you will have the kind of error you have right there. In the constructor, simply put a check to know if the DataSource was created and initialized properly or not before and just create it once. Then you have your global DataSource. Every instance of the class will use the same DataSource. - Or, if you do not need any class object (so the constructor will never be called), simply make a global procedure to create the DataSource. Then either call it one at program start at the good moment, or call it in every global member of your class when it needs the DataSource - like the constructor it will create the DataSource if not already declared only.
I hope this can help you finish your code.
Best regards, Alexandre Leclerc |
| |
| |
| | | |
|
| | |
| |
| Publicado el 18,noviembre 2014 - 06:11 |
Hi Everyone
Thank you all for your feedback.
I think that with all the new pointers, I'm in a better position to solve these issues.
Regards Marius |
| |
| |
| | | |
|
| | | | |
| | |
|