Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-09

Custom component: cannot make Items: TStrings

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vojtěch Čihák

Hi,
 
you have unusual getter:
 
function TATTabs.GetItems: TStrings;
var
  D: TATTabData;
  i: integer;
begin
  Result:= TStringList.Create;
  for i:= 0 to TabCount-1 do
  begin
    D:= GetTabData(i);
    if Assigned(D) then
      Result.Add(D.TabCaption)
    else
      Result.Add('?');
  end;
end;           
 
IMO, when you run app, ATTabs should read Items from *.lfm. But it creates new instance of TStringList instead. New instance is created from existing tabs, therefore it is empty. Even more, you don't Free then TStringList anywhere, there will be many instantioned Results. I'm not sure with solution, maybe you test csLoading somewhere.  
V.

Reply by email

Alexey
to Vojtěch Čihák
Vojtěch Čihák wrote
ATTabs should read Items from *.lfm. But it creates new instance of TStringList instead. New instance is created from existing tabs, therefore it is empty.

I changed getter. it uses now FTabItems (field) and fills it on each GetItems. But it don't help...

Regards, Alexey

Reply by email

Michael Van Canneyt
to Alexey: Hi. I added to ATTabs prop Items: TStrings. It has getter/setter. It has registering in…
Alexey wrote 10 lines
Hi. I added to ATTabs prop Items: TStrings. It has getter/setter. It has registering in IDE. - in designer, OI can set Items and tabs appear - if i run app, tabs dont appear- ?? - if I restart IDE, app's LFM looses Items- ?? https://github.com/alexey-t/attabs

Remove the clear statement in the setter ?

It clears FTabItems, which you just assigned. That's pointless. Also, if FTabItems equals AValue, it will clear the AValue.

Michael.

Reply by email

Alexey
to Michael Van Canneyt
Michael Van Canneyt wrote
Remove the clear statement in the setter ? It clears FTabItems, which you just assigned. That's pointless. Also, if FTabItems equals AValue, it will clear the AValue

hmm, setter don't clear FTabItems, it clear another FTabList [TList].

procedure TATTabs.SetItems(AValue: TStrings);
var
   i: integer;
begin
   FTabItems.Assign(AValue);
   Clear;
   for i:= 0 to AValue.Count-1 do
     AddTab(-1, AValue[i]);
end;

(updated repo)

Regards, Alexey

Reply by email