CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Sat Jul 21, 2018 3:05 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Apr 16, 2018 10:30 am 
Offline

Joined: Wed Jun 08, 2016 12:03 pm
Posts: 52
Hi!

I want to pass a array of strings throught a function and that function is going to return back the array. So I need to use pointers for that.

Let's keep it simple!
I first have my array:

Code:
myStrArray: ARRAY[0..10] OF STRING;


Then I need to convert myStrArray to a pointer.

Code:
p_myStrArray: POINTER := ADR(myStrArray);



Then I need to pass p_myStrArray throught my function

Code:
p_returnArray := myFunc(p_myStrArray);
(*....*)
FUNCTION myFunc: POINTER
VAR_INPUT
   p_myStrArray: POINTER;
END_VAR
VAR
END_VAR

myFunc := p_myStrArray; // Return statement



And then recive my pointer and turn it back to an array

Code:
returnArray: ARRAY[0..10] OF STRING;
returnArray := p_returnArray^;


But it won't work for me. What have I missed?


Top
   
PostPosted: Mon Apr 16, 2018 11:53 am 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 234
Wrap your array with an fb and pass the fb to the funtion as varinout. Or better, the funtion could be an method of the fb.

If not, you don t know from inside the funtion array dimension.


Top
   
PostPosted: Mon Apr 16, 2018 5:08 pm 
Offline

Joined: Mon Oct 01, 2012 8:33 am
Posts: 34
I didn't know the compiler would allow this
Code:
FUNCTION myFunc: POINTER
VAR_INPUT
   p_myStrArray: POINTER;
END_VAR


Maybe try this instead
Code:
FUNCTION myFunc: POINTER  ARRAY[0..10] OF STRING
VAR_INPUT
   p_myStrArray: POINTER  ARRAY[0..10] OF STRING;
END_VAR[/quote]


Then when you call the function you may try this
Code:
VAR
    MyStrArray: ARRAY[0..10] OF STRING;
    PtrReturnArray : POINTER TO ARRAY[0..10] OF STRING;
END_VAR

PtrReturnArray := myFunc(ADR(MyStrArray));


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

All times are UTC+01:00


Who is online

Users browsing this forum: toatan.th@gmail.com and 2 guests


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