1
General / Re: storing string
« Last post by ASerge on Today at 11:06:57 pm »I don't really like all the solutions from above.
It takes a lot of effort to figure out why it works.
And repeated conversions of types.
In some solutions, they forgot about freeing up memory, apparently they tested it only on constants.
In my opinion, there is already a container for strings, it's easy enough to use it:
It takes a lot of effort to figure out why it works.
And repeated conversions of types.
In some solutions, they forgot about freeing up memory, apparently they tested it only on constants.
In my opinion, there is already a container for strings, it's easy enough to use it:
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, Forms, Controls, StdCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- private
- FTagHolder: TStringList;
- public
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.lfm}
- { TForm1 }
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- Button1.Tag := FTagHolder.Add('Some string');
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- Caption := FTagHolder[Button1.Tag];
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- FTagHolder := TStringList.Create;
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- FTagHolder.Free;
- end;
- end.