Discussions related to Visual Prolog
Michel
Posts: 10
Joined: 8 Nov 2025 17:17

some help about OOP

Post by Michel »

Hi,
I am not new to Prolog ( Turbo Prolog 1 and then Turbo Prolog 2 ) and I like it. I am a good "C" programmer ( classic K&R ) and I like it but, in fact, I dislike OOP which give me nightmares.

If in one file ( say "mydialog.pro" ) I declare two radioButton ( radioButton_ctl, radioButton2_ctl) for exemple.

From inside "mydialog.pro" if I want to enable/disable each of one or the two, I don't have any problem but if I want to get the same action, externaly, from say "mytwo.pro", I get issue(s)

Even if I declare a predicate in "mydialog.pro" called from "mytwo.pro", I obtain a result like

"error c229 : Undeclared identifier 'mydialog::radioButton_ctl'" :?

The calling predicate acts correctly ( tested with a simple call to a message ), inside "mydialog.pro" the two radioButtons seems to be unknown even declared correctly as they works fine.

I read and re-read tips and tricks, forums to find alone a solution but, at this time, I don't feel comfortable with OOP, sorry.

Visual P. is a VERY powerfull soft, the IDE is perfect, it compiles very fastly and the "*.exe" is light but, in fact, the problem is me.

Here is screen part of my medical ( homeopathic ) program in development...

Warm regards
Michel (from France).
You do not have the required permissions to view the files attached to this post.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1499
Joined: 28 Feb 2000 0:01

Re: some help about OOP

Post by Thomas Linder Puls »

Yes, I can see that there are a number of fundamental things you need to learn. The purpose of it all is of course not just to make it more complicated. There are also benefits.

For dialogs then main benefit is that you can have several dialogs of the same kind at the same time.

Your dialog has a corresponding "mydialog" object. And the radioButton_ctl is stored inside this object.

All data is by default hidden from external manipulation; it can only be manipulated from the code inside the mydialog implementation.

To manipulate it from outside you will have to expose something on the object, by declaring it in the objects interface (in mydialog.i).

In this case you can choose to expose the entire radioButton_ctl as a readable property. (I would probably expose something more "narrow").

It will look like this:

Code: Select all

interface mydialog ... properties     radioButton_ctl : radioButton (o). ...
Now you can enable/disable the button from outside, like this:

Code: Select all

    ...     MyDialog = mydialog::new(Parent),     MyDialog:radioButton_ctl:setEnabled(false),     MyDialog:show(),     ...
You will need access to the object that represents the dialog (the mydialog object) in the code above it is done through the MyDialog variable.

From your image I guess that you want to control a button on the first dialog from the second dialog. To do this you will have to pass "This" in the first dialog to the second dialog, and make the change through the received object (of type mydialog).

Code: Select all

clauses     onMyDialogButtonX(...) :-             Parent = This,             MyDialog = This, %This argument is for accessing radioButton_ctl             Second= mysecondDialog::show(Parent, MyDialog),             ...
The two variables Parent and MyDialog are just used to give the arguments a name.
Regards Thomas Linder Puls
PDC
User avatar
Thomas Linder Puls
VIP Member
Posts: 1499
Joined: 28 Feb 2000 0:01

Re: some help about OOP

Post by Thomas Linder Puls »

ChatGPT have created this answer:

What you are hitting is not really "OOP magic", it is mostly scope + object vs class.

mydialog::radioButton_ctl means: "find a class-level entity named radioButton_ctl in scope mydialog".

But your radio buttons are almost certainly not class members. They belong to the dialog object / dialog implementation context, so they are available inside the dialog’s own object predicates, but not as a public class member from outside. That is why the compiler says:

Undeclared identifier 'mydialog::radioButton_ctl'

In Visual Prolog, the implementation scope can contain private entities, and object members are accessed through the current object (This) or through an object reference, not as arbitrary external names. The language reference also makes this distinction: class declarations expose the public part, while implementations may contain private entities; object members are invoked on an object, and inside object predicates the current object is available as This.

So the practical rule is:
  • Inside mydialog.pro: you can use the controls directly, because you are in the dialog’s own implementation/object context.
  • Outside, in mytwo.pro: you should not try to access the control identifier directly.
  • Instead, expose a public predicate on the dialog, and call that predicate on the dialog object.
A good pattern is this.

In the dialog interface/class, expose operations you want from outside:

Code: Select all

interface myDialog_i     predicates         setRadio1Enabled : (boolean State).         setRadio2Enabled : (boolean State).         setBothEnabled : (boolean State). end interface myDialog_i   class mydialog : myDialog_i end class mydialog
Then in mydialog.pro implementation:

Code: Select all

implement mydialog       clauses         setRadio1Enabled(State) :-             radioButton_ctl:setEnabled(State).           setRadio2Enabled(State) :-             radioButton2_ctl:setEnabled(State).           setBothEnabled(State) :-             radioButton_ctl:setEnabled(State),             radioButton2_ctl:setEnabled(State).   end implement mydialog
Then from mytwo.pro:

Code: Select all

clauses     somePredicate(Dlg) :-         Dlg:setRadio1Enabled(false),         Dlg:setRadio2Enabled(true).
where Dlg is the dialog object:

Code: Select all

Dlg = mydialog::new(), Dlg:setBothEnabled(false).
The important point is: call the predicate on the dialog instance, not by trying to reach the internal control name from outside.

So, not this:

Code: Select all

    mydialog::radioButton_ctl
but this style:

Code: Select all

    Dlg:setRadio1Enabled(false)
or, if you really made it a class predicate, then a public class predicate such as:

Code: Select all

    mydialog::disableSomething(...)
However, for GUI controls this is usually an object operation, not a class operation.

Why it works inside mydialog.pro
Because inside an object predicate, Visual Prolog implicitly works with the current object (This). The language reference explicitly states that object predicates have access to This, and other object members can be called directly inside that context.

Why it fails outside
Because outside that object context, radioButton_ctl is not a visible public class-level identifier. It is part of the dialog’s internal state/implementation.

So the mental model that usually helps old Turbo Prolog users is:
  • Think of the dialog controls as private fields of the dialog object.
  • From outside, never touch the fields directly.
  • Ask the dialog to do it for you through a predicate.
If you paste the relevant parts of mydialog.pro and mytwo.pro, I can rewrite them into the smallest possible non-OOP-looking Visual Prolog solution.
Regards Thomas Linder Puls
PDC
Michel
Posts: 10
Joined: 8 Nov 2025 17:17

Re: some help about OOP

Post by Michel »

Thanks !!! It is true I don't like OOP because ( as a good programer in C ), it give more limitations and restrictions than K&R. I feel prisonier and not free to make my own bugs ( :-( ) or to be "a genious" or quite....

But, your answer gives me some solutions I tried but only "test and try" spending plenty of time without satisfaction.

One mode time, I say "thanks" very much. You give me some keys I suspected but not really understood.

Warm regards, Michel
User avatar
drspro2
VIP Member
Posts: 128
Joined: 28 Apr 2006 12:03

Re: some help about OOP

Post by drspro2 »

and what is actually the difference between .cl and .i files?

because when you let the IDE create a dialog , it creates both .cl and .i files. In both of them it allows
you to assign predicates which are visible from outside


thankyou