Discussions related to Visual Prolog
hadiranji
Posts: 11
Joined: 7 Dec 2013 15:16

define clause with value from edit control

Unread post by hadiranji »

hi

i am new in visual prolog and need to define clause with value from edit control but i received error :
"The object member 'edit_ctl' is used in the class predicate"

how can do it ?
please help me

Code: Select all

class facts     edge:(string,string,string).   clauses     classInfo(className, classVersion).   edge("A","B",edit_ctl:getText()). edge("A","C",edit1_ctl:getText()).
User avatar
Thomas Linder Puls
VIP Member
Posts: 1399
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

There is a huge temoral issue here: The class facts exists all the time, the editor controls only some of the time. Furthermore the text in the edit controls chages while the user edits.

So you must ask your self when should these values be transferred from the edit controls an into the facts.

Assuming that you want it to happen when the user presses OK in the dialog.

To do this you must attach a click-listener to the OK button:
  • Select the button in the dialog editor
  • In the Events tab in the Properties editor: write onOkClick next to the ClickResponder entry (fiunish with enter).
This should give you code like this:

Code: Select all

predicates     onOkClick : button::clickResponder. clauses     onOkClick(_Source) = button::defaultAction.
And in this code you can assert the relevant facts:

Code: Select all

predicates     onOkClick : button::clickResponder. clauses     onOkClick(_Source) = button::defaultAction :-         assert(edge("A","B",edit_ctl:getText())),         assert(edge("A","C",edit1_ctl:getText())).
Regards Thomas Linder Puls
PDC
hadiranji
Posts: 11
Joined: 7 Dec 2013 15:16

Unread post by hadiranji »

assert command is work but only once
when the fact is defined by assert command i can't change value of fact !

and assert definition is different by define rule in class predicates and some time i received "Stack ower flow" error
User avatar
Thomas Linder Puls
VIP Member
Posts: 1399
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

Facts can be asserted and retracted, but not changed.

assert adds one more fact to the fact database; it does not change any facts which are already in the database.

retract can remove facts that match the term it is called with.

To update a fact you will have to retract it and assert the updated version.

Stack overflow is caused by recursive calls that goes "infinitely" deep.
Regards Thomas Linder Puls
PDC
User avatar
George
Active Member
Posts: 47
Joined: 19 Sep 2011 8:54

Unread post by George »

Please go through the following URL to get a detail knowledge on assert and retract,

Assert:
http://wiki.visual-prolog.com/index.php ... tes#assert

Retract:
http://wiki.visual-prolog.com/index.php ... es#retract

It is very important concepts - you have to use very carefully those built in predicates -

The idea is that,
whatever you define under "class facts" or "facts", we can called them as Internal database(IDB) - whatever you do assert they will be storing a data into the IDB. You have to cleanup them if they no more use by using retract predicate(there are may way we can retract - read the URL for more understanding)
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282
Harrison Pratt
VIP Member
Posts: 441
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

Look at "single" facts.
User avatar
George
Active Member
Posts: 47
Joined: 19 Sep 2011 8:54

Unread post by George »

Look for fact variable & properties too
:idea:
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282
Post Reply