Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 3 Jahren, 7 Monaten
Letzter Beitrag:
vor 3 Jahren, 7 Monaten
Beteiligte Autoren:
Marius, Piet van Zanten, Alexandre Leclerc, Bart VDE, Fabrice Harari, Arie

[WD18] Creating a view in a class

Startbeitrag von Marius am 17.11.2014 08: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.


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.



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.


von Piet van Zanten - am 17.11.2014 09:43
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:

and the classs:

clGlobalView is a Class
MyView_EAINFO is Data Source

PROCEDURE Constructor()
HCreateView(MyView_EAINFO, EAInfo_A, "EAINFO_A_ID", "", "", hViewDefault)

PROCEDURE Destructor()


von Marius - am 17.11.2014 11:18

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


von Piet van Zanten - am 17.11.2014 11:39
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.

von Marius - am 17.11.2014 11:56

why do you declare the class method as global?

Best regards

von Fabrice Harari - am 17.11.2014 11:56
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.

von Marius - am 17.11.2014 12:11
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

von Arie - am 17.11.2014 12:46

Use quotes :



von Bart VDE - am 17.11.2014 12:59
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

von Alexandre Leclerc - am 17.11.2014 13:35
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.


von Marius - am 18.11.2014 05:11
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.