<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Advanced pointer to struct members</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/01846c948f/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/01846c948f/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/01846c948f/</id><updated>2022-01-27T19:12:19.258000Z</updated><subtitle>Recent posts to Advanced pointer to struct members</subtitle><entry><title>Advanced pointer to struct members</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/01846c948f/?limit=25#8ae3" rel="alternate"/><published>2022-01-27T19:12:19.258000Z</published><updated>2022-01-27T19:12:19.258000Z</updated><author><name>alebrije</name><uri>https://forge.codesys.com/u/alebrije/</uri></author><id>https://forge.codesys.comf29b56b9817d769321b69e58d9b6eb2007201f51</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thannk you fajean i replied to you in the folllowing link &lt;a href="https://forge.codesys.com/forge/talk/Engineering/thread/b64911d912/?limit=25#0c0f"&gt;https://forge.codesys.com/forge/talk/Engineering/thread/b64911d912/?limit=25#0c0f&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Advanced pointer to struct members</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/01846c948f/?limit=25#ad79" rel="alternate"/><published>2022-01-27T15:20:21.970000Z</published><updated>2022-01-27T15:20:21.970000Z</updated><author><name>fajean</name><uri>https://forge.codesys.com/u/fajean/</uri></author><id>https://forge.codesys.comacbc214ecb80cd3000640675c22e9bffe4895a0c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;To achieve what you want, you do not declare a "POINTER TO ARRAY[] OF STRING".  You declare a "POINTER TO STRING". You can use the array subscript notation directly with this pointer. The array subscript notation performs dereferencing, just like using "^".  In fact, ptr&lt;span&gt;[0]&lt;/span&gt; and ptr^ are equivalent as far as I can tell.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;PROGRAM&lt;/span&gt; &lt;span class="n"&gt;MAIN&lt;/span&gt;
&lt;span class="n"&gt;VAR&lt;/span&gt;
  &lt;span class="n"&gt;INIValues1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;ARRAY&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;STRING&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;INIValues1_ptr&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;POINTER&lt;/span&gt; &lt;span class="k"&gt;TO&lt;/span&gt; &lt;span class="n"&gt;STRING&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;

&lt;span class="n"&gt;INIValues1_ptr&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;INIValues1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;INIValues1_ptr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Test'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Advanced pointer to struct members</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/01846c948f/?limit=25#a5e6" rel="alternate"/><published>2022-01-27T13:30:53.818000Z</published><updated>2022-01-27T13:30:53.818000Z</updated><author><name>alebrije</name><uri>https://forge.codesys.com/u/alebrije/</uri></author><id>https://forge.codesys.coma764d9e282cad22a004f87cf0966db4d4f3a7955</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello, &lt;br/&gt;
I would like to save some values in a structure named Test&lt;br/&gt;
The structures is &lt;/p&gt;
&lt;p&gt;TYPE test :&lt;br/&gt;
STRUCT&lt;br/&gt;
    generalinfo :general; // 2 variables as string&lt;br/&gt;
    testfreatures : freatures; // 2 variables as string&lt;br/&gt;
END_STRUCT&lt;br/&gt;
END_TYPE&lt;/p&gt;
&lt;p&gt;I'm using a pointer to the struct test &lt;br/&gt;
VAR&lt;br/&gt;
    INIValues1 : POINTER TO ARRAY &lt;span&gt;[0..1000]&lt;/span&gt; OF STRING;&lt;br/&gt;
END_VAR&lt;br/&gt;
INIValues1 := ADR(Test);&lt;br/&gt;
// I want to write the values as follow&lt;br/&gt;
INIvalues1^&lt;span&gt;[0]&lt;/span&gt;.^&lt;span&gt;[0]&lt;/span&gt; := 'Test';&lt;/p&gt;
&lt;p&gt;How can I mange to do this... I would like later only to replace the struct so my function fits for many different structures&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Advanced pointer to struct members</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/01846c948f/?limit=25#c97b" rel="alternate"/><published>2020-02-27T13:49:05.994000Z</published><updated>2020-02-27T13:49:05.994000Z</updated><author><name>Comingback4u</name><uri>https://forge.codesys.com/u/comingback4u/</uri></author><id>https://forge.codesys.comf37c6b2484fbe5536a876f55aff2137050d3b419</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Someone will correct me if i'm wrong but when you use a pointer and want to access the values directly you need to de-reference it by using the ^. The de-reference comes after the variable pointer name and before the struct member.&lt;/p&gt;
&lt;p&gt;So to access a pointer inside the FB you would use:&lt;br/&gt;
    Measurement^.History&lt;span&gt;[3]&lt;/span&gt; := 1.0; //set a single array value&lt;br/&gt;
    temp := Measurement^.History&lt;span&gt;[3]&lt;/span&gt; ; //get a single array value&lt;br/&gt;
    Measurement^.MaxValue := 5.0; //set a member variable&lt;br/&gt;
    temp := Measurement^.MaxValue; //get a member variable&lt;/p&gt;
&lt;p&gt;If you are trying to pass the addr of a value while still in the FB you wouldn't need the ADR() since it is already referenced as a pointer. Otherwise you are passing an address of an address.&lt;br/&gt;
    SomePointerToReal := Measurement.MaxValue; //pass the addr of a value&lt;br/&gt;
    SomePointerToRealArr := Measurement.History; //pass the address of an array&lt;br/&gt;
    SomePointerTosHisto := Measurement; //Pass the address of the structure&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Advanced pointer to struct members</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/01846c948f/?limit=25#1077" rel="alternate"/><published>2020-02-27T13:49:05.909000Z</published><updated>2020-02-27T13:49:05.909000Z</updated><author><name>tjarcoboerkoel</name><uri>https://forge.codesys.com/u/tjarcoboerkoel/</uri></author><id>https://forge.codesys.comf14da893cf889e4ae229f1fea68fa3ecd48ce68c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi readers,&lt;/p&gt;
&lt;p&gt;If I have a structure called sHisto:&lt;br/&gt;
STRUCT&lt;br/&gt;
    History: ARRAY &lt;span&gt;[1..64]&lt;/span&gt; OF REAL:&lt;br/&gt;
    MaxValue: REAL;&lt;br/&gt;
    MinValue:  REAL;&lt;br/&gt;
    AvgValue: REAL;&lt;br/&gt;
END_STRUCT&lt;/p&gt;
&lt;p&gt;And I pass it to a functionblock as a pointer:&lt;br/&gt;
Measurement: POINTER TO sHisto;&lt;/p&gt;
&lt;p&gt;How do I reference the members inside a functionblock? Is the following right?&lt;br/&gt;
   Measurement.History&lt;span&gt;[3]&lt;/span&gt; := 1.0;        //set a single array value&lt;br/&gt;
   temp := Measurement.History&lt;span&gt;[3]&lt;/span&gt;^ ;    //get a single array value&lt;br/&gt;
   Measurement.MaxValue := 5.0;        //set a member variable&lt;br/&gt;
   temp := Measurement.MaxValue^;   //get a member variable&lt;/p&gt;
&lt;p&gt;SomePointerToReal     := ADR(Measurement.MaxValue);  //pass the addr of a value&lt;br/&gt;
   SomePointerToRealArr := ADR(Measurement.History);     //pass the address of an array&lt;br/&gt;
   SomePointerTosHisto  := (Measurement);                    //Pass the address of the structure&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>