Is there any event that determines, if the mouse is hovering above an edit box? Basically, I want to show a hint/help for the user, but I want to display an image and simple instructions. What would be the best way to proceed?
Thanks for any help
Use the OnMouseEnter and OnMouseLeave events. In the event handlers, you can set the visibility of a Label or simliar control with the hint text. In the example, I took an empty VCL form and inserted a TEdit and a TLabel. I implemented the OnMouseMEnter and the OnMouseLeave events:
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
procedure Edit1MouseEnter(Sender: TObject);
procedure Edit1MouseLeave(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1MouseEnter(Sender: TObject);
begin
Label1.Visible:=True;
end;
procedure TForm1.Edit1MouseLeave(Sender: TObject);
begin
Label1.Visible:=False;
end;
Another solution could be to use the OnMouseEnter and OnMouseLeave events.
This is a sample found on Embarcadero:
type
TForm1 = class(TForm)
Button1: TButton;
StatusBar1: TStatusBar;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure DisplayHint(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ Here is the implementation of the OnHint event handler }
{ It displays the application’s current hint in the status bar }
procedure TForm1.DisplayHint(Sender: TObject);
begin
StatusBar1.SimpleText := GetLongHint(Application.Hint);
end;
{ Here is the form’s OnCreate event handler. }
{ It assign’s the application’s OnHint event handler at runtime }
{ because the Application is not available in the Object Inspector }
{ at design time }
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnHint := DisplayHint;
end;
You can use special tag on HINT property of TLabel, then manage the output as you need.
Related
I have 2 forms, Form1(it contain 1 button only) and Form2(it contains a memo only). here is the code when I click the button :
begin
Form2.Parent := Self;
Form2.Show;
end;
it was OK, but when I click the memo it can't get focus. But when I press tab, it can get focus. Why it can't get focus during click but it can get focus when I tab? How can I make it focusable when clicked?
EDIT
here is the code in my Form1 :
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
Unit2;
procedure TForm1.btn1Click(Sender: TObject);
begin
Form2.Parent := Self;
Form2.Show;
end;
and this is Form2 :
TForm2 = class(TForm)
memo2: TMemo;
private
{ Private declarations }
public
{ Public declarations }
end;
I have a TDBGrid component. I need to catch the event triggered when I'm resizing a column of the grid.
the only place to get an events seems to be overriding ColWidthChanged...
type
TDBgrid=Class(DBGrids.TDBGrid)
private
FColResize:TNotifyEvent;
procedure ColWidthsChanged; override;
protected
Property OnColResize:TNotifyEvent read FColResize Write FColResize;
End;
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
DBGrid1: TDBGrid;
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
private
procedure ColResize(Sender: TObject);
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TDBgrid }
procedure TDBgrid.ColWidthsChanged;
begin
inherited;
if Assigned(FColResize) then FColResize(self);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DBgrid1.OnColResize := ColResize;
end;
procedure TForm1.ColResize(Sender:TObject);
begin
Caption := FormatDateTime('nn:zzz',now) ;
end;
you need to create a descendent of TDBGrid and implement the event by yourself. Something like this:
unit MyDBGrid;
interface
type
TMyDBGrid = class(TDBGrid)
private
FOnColResize: TNotifyEvent;
protected
procedure ColWidthsChanged; override;
public
published
property OnColResize: TNotifyEvent read FOnColResize write FOnColResize;
end;
implementation
{ TMyDBGrid }
procedure TMyDBGrid.ColWidthsChanged;
begin
inherited;
if (Datalink.Active or (Columns.State = csCustomized)) and
AcquireLayoutLock and Assigned(FOnColResize) then
FOnColResize(Self);
end;
end.
this should work, I don't have time now to test it.
I have a TForm as this:
TMyForm = class (TForm)
[MyAttr('Data')]
edit1: TEdit;
private
FData: String;
end
When I try to get the fields of this form via RTTI, I only get the edit1 field, not FDATA, and when I query for edit1 field attributes a get a empty array.
For anoteher class that not inherit TForm, all work ok. ¿why?
edit for sample
type
{$RTTI EXPLICIT FIELDS([vcPrivate,vcProtected, vcPublic])}
TForm3 = class(TForm)
[TCustomAttribute]
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
[TCustomAttribute]
FData: String;
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
var
LCtx: TRttiContext;
LField: TRttiField;
LAttr: TCustomAttribute;
begin
for LField in LCtx.GetType(Self.ClassInfo).GetDeclaredFields do
begin
Memo1.Lines.Add(lField.Name);
for LAttr in LField.GetAttributes do
Memo1.Lines.Add(#9+LAttr.ClassName);
end;
end;
end.
result where button1 is clicked:
FData
TCustomAttribute
Button1
Memo1
There could be a $RTTI directive somewhere in your project that's causing extended RTTI to not work.
Try adding the following just before the declaration of TMyForm:
{$RTTI EXPLICIT
METHODS(DefaultMethodRttiVisibility)
FIELDS(DefaultFieldRttiVisibility)
PROPERTIES(DefaultPropertyRttiVisibility)}
This will reset RTTI generation for everything declared after it, and you should get proper RTTI after that point.
I would like to know how to get keyboard input in my delphi application while its not focussed.
The application i am programming is going to be taking a screenshot while i am in game.
I have wrote the screen capture code but i am missing this last piece any advice would be appreciated.
You can register a hotkey (using the RegisterHotKey and UnregisterHotKey functions) and use the WM_HOTKEY message to intercept when the key is pressed.
Try this sample
type
TForm3 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
procedure WMHotKey(var Message: TMessage); message WM_HOTKEY;
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
{ TForm3 }
const
SaveScreeenHK=666;
procedure TForm3.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle, SaveScreeenHK , MOD_CONTROL, VK_F10);
end;
procedure TForm3.FormDestroy(Sender: TObject);
begin
UnregisterHotKey(Handle, SaveScreeenHK);
end;
procedure TForm3.WMHotKey(var Message: TMessage);
begin
//call your method here
end;
I have since been busy and created a library for getting keystrokes in delphi.
You can find it here : https://github.com/Kobusvdwalt/DelphiKeylogger
It still needs documentation but basicly you just call the olgetletter function.
Why does the code below return TRUE in Delphi 7 and FALSE in Delphi 2010? TBitBtn is a descendant of TButton.
type
TForm1 = class(TForm)
Button1: TButton;
BitBtn1: TBitBtn;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TestControl( aControl: TControl);
begin
if (aControl is TButton) then showmessage('TRUE') else showmessage('FALSE');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TestControl(BitBtn1);
end;
is did not change. TBitBtn is a subtype of TCustomButton, not TButton, as you state.