CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Fri Jul 28, 2017 1:45 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
 Post subject: WITH .. DO?
PostPosted: Thu May 18, 2017 12:08 pm 
Offline

Joined: Wed Dec 28, 2016 11:00 pm
Posts: 37
Does anybody know if there is some Codesys OOP variant of the WITH statement?
This type of statement would be usefull when initiliasing objects or setting more then one property at the same time.

pseudocode example;

WITH <object> DO
.<PROPERTY1> := Value1;
.<PROPERTY2> := Value2;
.<PROPERTY3> := Value3;
.<PROPERTY4> := Value4;
END_WITH;


Top
   
 Post subject: Re: WITH .. DO?
PostPosted: Wed Jun 07, 2017 5:25 am 
Offline

Joined: Mon May 15, 2017 6:47 am
Posts: 38
Hermsen wrote:
Does anybody know if there is some Codesys OOP variant of the WITH statement?
This type of statement would be usefull when initiliasing objects or setting more then one property at the same time.

pseudocode example;

WITH <object> DO
.<PROPERTY1> := Value1;
.<PROPERTY2> := Value2;
.<PROPERTY3> := Value3;
.<PROPERTY4> := Value4;
END_WITH;


Last edited by nothinrandom on Wed Jun 07, 2017 6:00 pm, edited 1 time in total.

Top
   
 Post subject: Re: WITH .. DO?
PostPosted: Wed Jun 07, 2017 11:20 am 
Offline

Joined: Fri Feb 10, 2017 6:12 am
Posts: 14
Code:
var
    obj: <object>;
    p: pointer to <object>;
end_var

p := adr( <object> );

p^.<PROPERTY1> := Value1;
p^.<PROPERTY2> := Value2;
p^.<PROPERTY3> := Value3;
p^.<PROPERTY4> := Value4;


Top
   
 Post subject: Re: WITH .. DO?
PostPosted: Wed Jun 07, 2017 2:07 pm 
Offline

Joined: Mon Oct 01, 2012 8:33 am
Posts: 7
You could also use the REFERENCE data type instead of POINTER
Code:
var
    obj: <object>;
    R: REFERENCE TO to <object>;
end_var

R REF= obj;

R.<PROPERTY1> := Value1;
R.<PROPERTY2> := Value2;
R.<PROPERTY3> := Value3;
R.<PROPERTY4> := Value4;


Top
   
 Post subject: Re: WITH .. DO?
PostPosted: Fri Jun 09, 2017 2:03 pm 
Offline

Joined: Wed Dec 28, 2016 11:00 pm
Posts: 37
The above options will do the trick I guess! thank you for the response!


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited