Sign in Join

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

Mailing lists / lazarus / 2012-01

TTabControl has problem with storing/retreving objects

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Donald R. Ziesig

Hi All!

I have an app that uses a TTabControl to select the display of one of many objects. The code is really trivial in the real app, but I have further simplified it to the bare essentials:

unit Unit1;
{$mode objfpc}{$H+}
interface

uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,

   ComCtrls;
type
   { TForm1 }
   TForm1 = class(TForm)
     Button1: TButton;
     Label1: TLabel;
     TabControl1: TTabControl;
     procedure Button1Click(Sender: TObject);
     procedure TabControl1Change(Sender: TObject);
   private
     { private declarations }
     N : Integer;
   public
     { public declarations }
   end;
var
   Form1: TForm1;
implementation
{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
   Inc(N);
   TabControl1.Tabs.AddObject(IntToStr(N),TObject(N));
end;
procedure TForm1.TabControl1Change(Sender: TObject);
var
   I : Integer;
begin
   I := TabControl1.TabIndex;
   Label1.Caption := IntToStr(Integer(TabControl1.Tabs.Objects[I]));
end;
end.

Pressing Button1 adds consecutively-numbered tabs a tab SHOULD set Label1's caption to the number on the tab (and DOES when used with Delphi). It actually outputs non-consecutive numbers in the 37,000,000 range. I get similar results using Windows, OSX and Debian.

In the real app, I use an object with a name, but when I select a tab, it goes somewhere in the address space (not sure where in the context of the app) and returns a string of un-printable characters as the name (and other random values for the remaining contents of the object).

As I said above, the exact same code in Delphi (2006 and 2007) works as expected, but obviously is limited to Windows.

I tried similar operations with a TListBox and the object was returned correctly so I don't think the problem is with TStrings or its descendents.

Any help would be appreciated.

Don Ziesig

P.S. I have tried to find the LCL code and debug the library myself but I must be missing something in my searches. Some pointers in that area would also be appreciated.

Reply by email

Hans-Peter Diettrich
to Donald R. Ziesig
Show quoted text 13 lines
procedure TForm1.Button1Click(Sender: TObject); begin Inc(N); TabControl1.Tabs.AddObject(IntToStr(N),TObject(N)); end; procedure TForm1.TabControl1Change(Sender: TObject); var I : Integer; begin I := TabControl1.TabIndex; Label1.Caption := IntToStr(Integer(TabControl1.Tabs.Objects[I])); end;

AFAIR the Tabs.Objects property is implemented differently from Delphi, i.e. the LCL doesn't support it at all :-(

Chances for an fix are low, because the LCL TabControl is based on the gtk implementation, that differs widely from the Win32 ComCtrls implementation.

P.S. I have tried to find the LCL code and debug the library myself but I must be missing something in my searches. Some pointers in that area would also be appreciated.

Controls have their high-level interface in the LCLBase package, e.g. "class TTabControl" in lcl\ComCtrls.pp, and their associated widget in e.g. lcl\interfaces\win32\win32wscomctrls.pp.

DoDi

Reply by email