TStrings [SOLVED] lazarus / 61-Beginners ---------------------------------------------------------------------- pascal111 · 2021-05-29 17:23 لم أكن أعلم أنّ في لغات البرمجة المرئيّة أدوات للبيانات غير الأدوات الكلاسيكيّة مثل المصفوفات والمُتغيّرات والمؤشرات ،وكُنتُ أظنّ أنّ الـ data structure أو بنى البيانات المُتقدمّة عبارةٌ عن تلكـ النماذج المذكورة في مرجع الـ Turbo Pascal ولغة الـ الـ C++ أشياءٌ مثل الـ trees والـ lists ولكنّني في هذا الرابط وجدتُّ أنواعاً أخرى https://wiki.freepascal.org/Data_Structures,_Containers,_Collections وأُريدُ أن أستفسر عن كيفيّة الإستفادة من الـ TStrings فرُبّما العمل مع الحرفيّات ليس مُعقداً مثل الحسابات الرقميّة. كيف يُمكنني الإستفادة من الـ TStrings في برامجي؟ google translate: "I did not know that in visual programming languages ​​there are tools for data other than classic tools such as arrays, variables and indicators "pointers", and I used to think that the data structure or advanced data structures are those models mentioned in the Turbo Pascal reference and C ++ language things like trees and lists, but in This link found other types https://wiki.freepascal.org/Data_Structures,_Containers,_Collections I want to inquire about how to take advantage of TStrings, maybe working with craftsmen "strings" is not as complicated as digital calculations. How can I use TStrings for my programs?" ---------------------------------------------------------------------- jamie · 2021-05-29 17:41 Tstrings is a base class.. it has lots of Abstract members in it that needs to be filled in if you decide to use them, otherwise you do not need to fill them in..  There are methods that are not abstract but do depend on certain abstract members to be implemented.  Normally Tstrings is used in calling parameters to allow any class to be accepted that is based from Tstrings or you can create a class of your own using TSTRINGs as the inherited class and thus you implement your version of the abstract members.  Doing this, all functions that knows how to interact with a class that is based from a TString will function correctly...  you can view the source code of the TStrings to get a better idea..  I wanted to add that also there are many virtual methods that really do nothing but can be overridden.. ---------------------------------------------------------------------- MarkMLl · 2021-05-29 17:58 Extensive documentation available via https://www.freepascal.org/docs.html , in particular https://www.freepascal.org/docs-html/current/rtl/classes/index.html noting that these are part of FPC not Lazarus/LCL. And in this case there's plenty of useful material in the Wiki... just remember that the documentation has precedence. MarkMLl ---------------------------------------------------------------------- Handoko · 2021-05-29 18:09 Don't use TStrings directly, instead use TStringList. TStringList is a class inherited from TStrings. You only use TStrings if you want to write your own class based on it. I believe you already know what array is. You can think TStringList as a kind of array for storing string data. https://www.freepascal.org/docs-html/rtl/classes/tstringlist.html Here is a very simple demo showing how to use TStringList: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    procedure FormCreate(Sender: TObject);  private    FVisitorNames: TStringList;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  FVisitorNames   := TStringList.Create;  Button1.Caption := 'Add a visitor';  Button2.Caption := 'No more visitor';  Button2.Visible := False;end; procedure TForm1.Button1Click(Sender: TObject);var  S: string;begin   // Ask  S := InputBox('Add Visitor', 'Name', '');  if S = '' then Exit;  FVisitorNames.Add(S);   // Ask more  Button1.Caption := 'Add more visitor';   // At least 3 visitors  if FVisitorNames.Count >= 3 then    Button2.Visible := True; end; procedure TForm1.Button2Click(Sender: TObject);var  S: string;begin  S := FVisitorNames[0] + ' is the first visitor.' + LineEnding +       FVisitorNames[FVisitorNames.Count-1] + ' is the last visitor.' + LineEnding +       'The total visitors are ' + FVisitorNames.Count.ToString + ' persons.';  ShowMessage(S);end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  FVisitorNames.Free;end; end. ---------------------------------------------------------------------- pascal111 · 2021-05-29 19:26 Quote from: Handoko on May 29, 2021, 08:09:18 pmDon't use TStrings directly, instead use TStringList. TStringList is a class inherited from TStrings. You only use TStrings if you want to write your own class based on it. I believe you already know what array is. You can think TStringList as a kind of array for storing string data. https://www.freepascal.org/docs-html/rtl/classes/tstringlist.html Here is a very simple demo showing how to use TStringList: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    procedure FormCreate(Sender: TObject);  private    FVisitorNames: TStringList;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  FVisitorNames   := TStringList.Create;  Button1.Caption := 'Add a visitor';  Button2.Caption := 'No more visitor';  Button2.Visible := False;end; procedure TForm1.Button1Click(Sender: TObject);var  S: string;begin   // Ask  S := InputBox('Add Visitor', 'Name', '');  if S = '' then Exit;  FVisitorNames.Add(S);   // Ask more  Button1.Caption := 'Add more visitor';   // At least 3 visitors  if FVisitorNames.Count >= 3 then    Button2.Visible := True; end; procedure TForm1.Button2Click(Sender: TObject);var  S: string;begin  S := FVisitorNames[0] + ' is the first visitor.' + LineEnding +       FVisitorNames[FVisitorNames.Count-1] + ' is the last visitor.' + LineEnding +       'The total visitors are ' + FVisitorNames.Count.ToString + ' persons.';  ShowMessage(S);end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  FVisitorNames.Free;end; end. كلامكـ صائب ،فيبدو أنّ هناكـ تصنيفاً للأصناف داخل وحدات الـ Free Pascal ولكل صنف وظائف وتخصص. google translate: "Your words are correct, it seems that there is a classification of items "classes" within the Free Pascal units, and each class has functions and specializations." ---------------------------------------------------------------------- Handoko · 2021-05-29 19:30 For your information, abstract class basically means you should not use it directly but you write your own class based on it. TStrings is an abstract class. https://freepascal.org/docs-html/ref/refse36.html#x71-950006.2 ---------------------------------------------------------------------- pascal111 · 2021-05-29 20:03 Quote from: jamie on May 29, 2021, 07:41:34 pmTstrings is a base class.. it has lots of Abstract members in it that needs to be filled in if you decide to use them, otherwise you do not need to fill them in..  There are methods that are not abstract but do depend on certain abstract members to be implemented.  Normally Tstrings is used in calling parameters to allow any class to be accepted that is based from Tstrings or you can create a class of your own using TSTRINGs as the inherited class and thus you implement your version of the abstract members.  Doing this, all functions that knows how to interact with a class that is based from a TString will function correctly...  you can view the source code of the TStrings to get a better idea..  I wanted to add that also there are many virtual methods that really do nothing but can be overridden.. بما أنّ لديكـ فكرةً جيّدةً عن الـ interfaces فهل يُمكنكـ أن تُخبرني عن الـ interfaces المُسمّى IFPObserved والذي يدخل في بناء الصنف القاعدي لـ TStrings والمُسمّى TPersistent في هذا الرابط https://lazarus- ccr.sourceforge.io/docs/rtl/classes/tpersistent.html وهذا الرابط https://lazarus-ccr.sourceforge.io/docs/rtl/classes/ifpobserved.html ،يبدو أنّ لديكـ فكرةً جيّدة تُحاول سبر أسرار الـ TStrings؟ google translate: "Since you have a good idea of ​​interfaces, can you tell me about the interfaces called IFPObserved that are included in the construction of the base class for TStrings called TPersistent in this link https://lazarus-ccr.sourceforge.io/docs/rtl/classes /tpersistent.html and this link https://lazarus- ccr.sourceforge.io/docs/rtl/classes/ifpobserved.html Do you seem to have a good idea trying to fathom the secrets of TStrings?" ---------------------------------------------------------------------- jamie · 2021-05-29 22:36 look here. https://www.freepascal.org/docs-html/rtl/classes/ifpobserver.html That is the interface that receives notification messages from the observed objects to use that, you can insert this in your class definition..  TFORM1 = Class(Tform, IfpObserver); You will get a compiler error of course because you need to implement the method also.. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure FpObserveredChange(ASender:TObject; Operation:TObserveredOoperation;Data:Pointer);  Put that in the Tform1 Class and implement the body of it like you would any other method.. So this is the concept behind it. You create an object that has a IfpObverser interface, for example a TstringList and you can add a observer to the list. In this case if you were to do as I showed you above the TFORM1 would be the observer.   When ever the stringlist makes a change it sends notices to all the observers in the list. the Observers receive this and can do as they please with it. I can make an example if you wish.. ---------------------------------------------------------------------- jamie · 2021-05-29 23:05 An Example project ---------------------------------------------------------------------- MarkMLl · 2021-05-30 06:30 Quote from: pascal111 on May 29, 2021, 10:03:36 pmgoogle translate: "Since you have a good idea of ​​interfaces, can you tell me about the interfaces called IFPObserved that are included in the construction of the base class for TStrings called TPersistent in this link https://lazarus-ccr.sourceforge.io/docs/rtl/classes /tpersistent.html and this link https://lazarus- ccr.sourceforge.io/docs/rtl/classes/ifpobserved.html Do you seem to have a good idea trying to fathom the secrets of TStrings?" I find it a little disturbing that a user should be investigating interfaces and deeply-defined abstract classes before getting to grips with classes like TStringList which have immediate practical use. @Pascal111, what's going on here? Are you trying to teach yourself Pascal by reading the reference manual in page order, in the same way that Gabriel Kron taught himself English? MarkMLl ---------------------------------------------------------------------- pascal111 · 2021-05-30 12:15 Quote from: MarkMLl on May 30, 2021, 08:30:01 amQuote from: pascal111 on May 29, 2021, 10:03:36 pmgoogle translate: "Since you have a good idea of ​​interfaces, can you tell me about the interfaces called IFPObserved that are included in the construction of the base class for TStrings called TPersistent in this link https://lazarus-ccr.sourceforge.io/docs/rtl/classes /tpersistent.html and this link https://lazarus- ccr.sourceforge.io/docs/rtl/classes/ifpobserved.html Do you seem to have a good idea trying to fathom the secrets of TStrings?" I find it a little disturbing that a user should be investigating interfaces and deeply-defined abstract classes before getting to grips with classes like TStringList which have immediate practical use. @Pascal111, what's going on here? Are you trying to teach yourself Pascal by reading the reference manual in page order, in the same way that Gabriel Kron taught himself English? MarkMLl سوف أتعلّم TStringList بالطبع ولكن لا مانع من أخذ فكرة عن أصناف أخرى وأنواعها وبعض المعلومات عنها وإلا لن تكون هناكـ ثقافة حول Free Pascal. بمناسبة ذِكر Gabriel Kron فلقد وجدت هذا الجزء الذي يتكلّم عن تعلّمه الإنجليزيّة: google translate: "I will be learning TStringList of course, but I don't mind getting an idea of ​​other brands "classes" and their types and some information about them, otherwise there will be no culture about Free Pascal. On the occasion of Gabriel Kron's mention, I found this section on his learning of English:" QuoteIt rather disappointed me to realize that familiarity with German and French would not be of much practical use in my attempts to relieve Europe of my presence. I sensed - in spite of the arguments of those who had travelled far and wide - that once Europe receded behind my back the only language that would enable me to move about freely must be English. Unfortunately (or fortunately) no English-Hungarian dictionary could be procured in all Transylvania, and the only one I could get hold of was a big Muret-Sanders type of English-German dictionary, containing over a hundred thousand words. Of course it was out of the question to repeat the stunt of tearing out the pages and memorizing them one after another, as they contained so many archaic and technical words. What I did was to borrow an English book, which happened to be H.G. Wells' The Food of the Gods, and beginning with the first page I wrote out a hundred words each day and committed them to memory. After eight or ten pages the text began to assume more human form, and past the first chapter the content even became enjoyable. http://www.quantum-chemistry-history.com/Kron_Dat/KronGabriel1.htm لسوء الحظ ،لم تعُد طريقته في تعلّم الإنجليزيّة صالحةً لي الآن ،إلا أنّها طريقة رائعة وذكيّة وعاملة. google translate: "Unfortunately, his method of learning English no longer works for me now, but it is wonderful, smart and working (way)." ---------------------------------------------------------------------- pascal111 · 2021-05-30 18:23 إليكُم هذا البرنامج البسيط والذي يستخدم الـ TStringlist. google translate: "Here is a simple program that uses the TStringlist." (https://i.postimg.cc/jDLMfmC1/Screenshot-at-2021-05-30-20-12-47.png) https://www.mediafire.com/file/5f6jnuqmccccel3/Project_13.rar/file