Ok, now I'm wondering if something I've been seeing isn't a bug in Free Pascal or Lazarus.
Here is the code I'm using.
-----------------------------------------------------------------------------------------
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ComCtrls, StdCtrls,Functions;
type
{ TForm1 }
TForm1 = class(TForm)
Edit1: TEdit;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
);
begin
Form1.Edit1.Caption := 'HI';
MyKeyPress(Sender,Key,Shift);
end;
initialization
{$I unit1.lrs}
end.
---------------------------------------------------------------------------------
unit Functions;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,Dialogs,Forms,Graphics;
Function MyKeyPress(Sender: TObject; var Key: Word; Shift: TShiftState):Boolean;
implementation
uses unit1;
Function MyKeyPress(Sender: TObject; var Key: Word; Shift: TShiftState):Boolean;
begin
if Sender is TForm then
begin
showmessage(tform(sender).ActiveControl.Name ) ;
showmessage(tform(sender).ActiveControl.Caption);
showmessage(tform(Sender).ControlByName('Edit1').Caption);
end;
end;
end.
--------------------------------------------------------------------------------------
This works for the first 2 showmessages. If you run this, click on the edit box and press a key you'll see the name of the current control shown, Edit1, in the popup, press ok and you'll see another popup with the word 'HI' in it. press ok again and you get a
'Project project1 raised exception class 'External: SIGSEGV'.
Seems like the info is there in the TFORM object but when I try to access it by name the entire program goes belly up. I think I can get away with using just the ActiveControl but just for the record I'd like to know why it crashes??