Forum > Beginners

Array properties [SOLVED]

<< < (2/3) > >>

pascal111:

--- Quote from: ASerge on May 17, 2021, 02:55:02 pm ---
--- Quote from: pascal111 on May 17, 2021, 02:39:36 pm ---I don't see any array declaration or is the array declaration inside the methods and I don't think so because it is thus a temporary array or is this a dynamic array style?"

--- End quote ---
From the mentioned documentation "These are properties that accept an index, just as an array does."

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---property Items[i: LongInt]: ...property StrItems[S: string]: ...
--- End quote ---

يبدو أنّ المعنى فعلاً هو أنّ هذه الخصائص إنّما تسلكـ سلوكـ المصفوفات لذلكـ شُبّهت بها.

google translate:

"It seems that the meaning really is that these properties but rather behave like arrays, so they are likened to them."

pascal111:

--- Quote from: Handoko on May 17, 2021, 02:58:42 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---property Something[i : Sometype] //  is an array property.
Don't be confused with the static array or dynamic array. They all have similarity but different.

--- End quote ---

كلامكـ صحيح لكن الإشكالية كما ذكر @lucamar في الربط الداخلي مع نوع آخر من البيانات والذي قد يكون مصفوفة فعليّه أو غيرها.

google translate:

"Your statement "speaking" is correct, but the problem "matter", as mentioned by @lucamar, is in the internal linking with another type of data, which may be an actual array or something else."

lucamar:

--- Quote from: pascal111 on May 17, 2021, 04:40:01 pm ---[...] "assigning" the property with data is permanent throughout the life of the object?
--- End quote ---

Yes, of course. Otherwise it would make little sense.

Suppose you want a class to hold some strings, kind of a "light" version of TStringList, which you could access either by their index of by looking up its contents:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TMyStrings = class  private    fStrings: TStringArray; {= "array of Strings"}    function GetItems(Index: Integer): String;    procedure SetItems(Index: Integer; AValue: String);    function GetIndexOf(What: String): Integer;  public    property Items[Index: Integer]: String read GetItems write SetItems;    property IndexOf[What: String]: Integer read GetIndexOf;  end;
We have implemented it by using a real array, though it doesn't really matters, and since it belongs to the object, whatever we do with it, it will be there as long as the instance itself exits, so we can for example add a string using:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---MyStrings.Items[8] := 'Something or other';which will invoke the setter:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TMyStrings.SetItems(Index: Integer; AValue: String);begin  if Length(fStrings) <= Index then    SetLength(fStrings, Index+1);  fStrings[Index] := AValue;end;and we can now retrieve it by turning around and doing:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---StrIndex := MyStrings.IndexOf['Something or other'];with the security that, if we programmed it properly, the later won't fail and StrIndex will be eight ( 8 ).

pascal111:

--- Quote from: lucamar on May 17, 2021, 05:32:31 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---StrIndex := MyStrings.String['Something or other'];
--- End quote ---

هل تعني:

google translate:

"Do you mean:"


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---StrIndex := MyStrings.IndexOf['Something or other']; 

lucamar:

--- Quote from: pascal111 on May 17, 2021, 05:50:27 pm ---Do you mean:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---StrIndex := MyStrings.IndexOf['Something or other'];
--- End quote ---

Oops! Yes, that's what I meant ... sorry, corrected now :-[

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version