diff --git a/.gitattributes b/.gitattributes index 4c0bfd3e3c..095965303c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -745,6 +745,7 @@ docs/xml/lcl/spin.xml svneol=LF#text/xml eol=lf docs/xml/lcl/stdactns.xml svneol=LF#text/xml eol=lf docs/xml/lcl/stdctrls.xml svneol=LF#text/xml eol=lf docs/xml/lcl/stringhashlist.xml svneol=LF#text/xml eol=lf +docs/xml/lcl/tarrayexample.pas svneol=native#text/plain docs/xml/lcl/textstrings.xml svneol=LF#text/xml eol=lf docs/xml/lcl/toolwin.xml svneol=LF#text/xml eol=lf docs/xml/lcl/translations.xml svneol=LF#text/xml eol=lf diff --git a/docs/xml/lcl/dynamicarray.xml b/docs/xml/lcl/dynamicarray.xml index 1518712ad7..89228da7d0 100644 --- a/docs/xml/lcl/dynamicarray.xml +++ b/docs/xml/lcl/dynamicarray.xml @@ -1,426 +1,315 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +--> + + It implements a resizable 2d array containing pointers. + + + + + + + + + + + + + + + + + + + + + + + Type for event handling + + + + + + instance of the TArray that causes the event + + + + The related Col of the event + + + + The related Row of the event + + + + The related Item of the event + + + + + + + + + + The instance of the TArray that causes the Exchange event + + + + + + + + + + + + It implements a resizable 2d array. + + + + + + + It contains the first dimension of the array. + + + + + + A user-defined function to be called when an item is destroyed. + This can happen in ClearCol,Clear,SetLength + + + + + A user-defined function to be called when a new item is created. + + + + + + Returns the stored item(actually pointer) in array + + + + + + + the stored item,pointer. + + + + the first dimension of the array. + + + + the second dimension of the array. + + + + Sets an item in the array [col][row]. + + + + + + + the first dimension of the array. + + + + the second dimension of the array. + + + + the value to be stored. + + + + Clears the given TList + The given TList is assumed to be the COL of the array. + + + + + + Tlist to be cleared. + + + + the first dimension of the array. + + + + Extends a row to its new size(Rows) + + + + + + + current column + + + + new row size + + + + The row to be operated on. + + + + event handler called when an item is destroyed. + + + + + + + the column of the destroyed item. + + + + the row of the destroyed item. + + + + the item itself before it is unlinked. + + + + + + + + + + + + + + + + + + + + Resizes the array. + + + + + + + + new column size + + + + new row size + + + + Deletes a column or a row of an array. + + + + + + + + Do you want to delete a column? + + + + index of a row or a column + + + + Moves a column to another column or a row to another row. + + + + + + + + Do you want to move a column? + + + + source + + + + destination + + + + Swaps two rows or two columns. + + + + + + + + Do you want to move a column? + + + + index of row or column + + + + index of row or column + + + + Removes all elements from the array. + + + + + + + + Reads/Writes an element from the array. + + + + + + + + + + + + + + + User-defined function which is called when an item is destroyed. + + + + + + User-defined function which is called when an item is created. + + + + + + + + diff --git a/docs/xml/lcl/tarrayexample.pas b/docs/xml/lcl/tarrayexample.pas new file mode 100644 index 0000000000..aef820ace6 --- /dev/null +++ b/docs/xml/lcl/tarrayexample.pas @@ -0,0 +1,73 @@ +program tarrayexample; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Classes + { add your units here },strings,DynamicArray; + +type +Tarrayexampleclass=class +private +procedure doDestroyItem(Sender: Tobject; Col,Row: Integer;var Item: Pointer); + +end; + +procedure Tarrayexampleclass.doDestroyItem(Sender: Tobject; Col,Row: Integer; + var Item: Pointer); +begin + strdispose(Item); +end; + + +var FCols: Tarray; +var ex:Tarrayexampleclass; + +begin +FCols:= TArray.Create; +ex:= Tarrayexampleclass.Create; +FCols.OnDestroyItem:=@ex.doDestroyItem; +FCols.SetLength(8,8); +//FCols.OnNewItem:=@doNewItem; +FCols.arr[0,0]:=StrNew('string1'); +FCols.arr[4,7]:=StrNew('string2'); +FCols.arr[4,3]:=StrNew('string3'); +writeln('0,0:'+Pchar(FCols.arr[0,0])); +writeln('4,7:'+Pchar(FCols.arr[4,7])); +FCols.MoveColRow(true,4,5); +writeln('after moving column 4 to 5'); +writeln('5,7:'+Pchar(FCols.arr[5,7])); +writeln('before exchanging row 7 and 3:'); +writeln('5,3:'+Pchar(FCols.arr[5,3])); +writeln('5,7:'+Pchar(FCols.arr[5,7])); +FCols.ExchangeColRow(false,7,3); +writeln('after exchanging row 7 and 3:'); +writeln('5,3:'+Pchar(FCols.arr[5,3])); +writeln('5,7:'+Pchar(FCols.arr[5,7])); +FCols.DeleteColRow(true,5); +writeln('after deleting column 5:'); +try + writeln('5,3:'+Pchar(FCols.arr[5,3])); //this raises an exception +except + writeln ('An exception has taken place be because 5,3 does not exist.'); +end; +try + writeln('5,7:'+Pchar(FCols.arr[5,7])); //this raises an exception +except + writeln ('An exception has taken place be because 5,7 does not exist.'); +end; +FCols.Clear; writeln('after clear:'); +try + writeln('4,7:'+Pchar(FCols.arr[4,7])); //this raises an exception +except + writeln ('An exception has taken place be because 4,7 does not exist.'); +end; +FCols.Destroy; +ex.Destroy; +readln; +end. + +