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+}
interfaceuses
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.
