Ok. Question for my fellow Monkeyteers (is that a word). I am working on a custom component (I missed coderage session on custom FM components - looking forward to the replay) for the smoking ape. How the f**k do I add a caret to it? I have tried duplicating the code from TMemo but its just not working..... The positioning is right, the caret is parented to the control, it should be getting drawn - what could I be missing here? If I do a canvas.drawrect then I can see the size an position look about right, but the caret itself just isn't there.....
you're probably too frustrated and missing something, look more carefully at the TMemo code and it's parent(?)
ReplyDeletea TMemo parent is TScrollBox - no help there. Currently stepping through the paint procedures, wondering if I'm missing something stupid like a parent or something.....
ReplyDeletehaven't touched the monkey yet, but I'm sure that there's something you're missing, take a deep breath, maybe a 5 min break and review what you've done and what not
ReplyDeleteIndeed. I have worked out that I don't need to do begin/end scene in my paint (which is odd)
ReplyDeleteYou must implement interface ICaret
ReplyDeleteICaret = interface
['{F4EFFFB8-E83C-421D-B123-C370FB7BCCC7}']
function GetObject: TCustomCaret;
procedure ShowCaret;
procedure HideCaret;
end;
see function TMemo.CreateCaret etc
done that already, still not working. well, sometimes it is. Its most odd - it will display only when the position isn't changed, its not in top left (0,0) position and you repaint..... then it shows, otherwise it thinks its visible but its not on screen.
ReplyDeleteOh. FFS. you have to do a caret.updateflasher and the magic works. AHHHHHHHHHHHHH I have wasted all day on that!
ReplyDeletePaul Foster it could be worst, imagine if there wasn't any documentation on that (:
ReplyDeleteI never found it in the documentation - I gave up with that ages ago, it doesn't work at all on my desktop, at least on this laptop I can get at it, but nowhere did I see a mention of the requirement to call updateflasher to make work. Now if only I can get it to show when there is no text in the control.......
ReplyDeleteI know ^_^
ReplyDeleteWhat is your version of Delphi?
ReplyDeletehttp://docwiki.embarcadero.com/Libraries/XE5/en/FMX.Types.ICaret
For example TButton with caret:
unit Unit3;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.Edit;
type
TButton = class (FMX.StdCtrls.TButton, ICaret)
private
FCaret: TCaret;
protected
function ICaret.GetObject = GetCaret;
function GetCaret: TCustomCaret;
procedure ShowCaret;
procedure HideCaret;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
public
destructor Destroy; override;
end;
TForm3 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.fmx}
{ TButton }
type
TMyCaret = class (TCaret)
end;
destructor TButton.Destroy;
begin
FreeAndNil(FCaret);
inherited;
end;
function TButton.GetCaret: TCustomCaret;
begin
if FCaret = nil then
begin
FCaret := TMyCaret.Create(Self);
FCaret.Visible := True;
FCaret.ReadOnly := False;
FCaret.Color := TAlphaColorRec.Red;
FCaret.Size := TSizeF.Create(3, 12);
end;
Result := FCaret;
end;
procedure TButton.HideCaret;
begin
TMyCaret(GetCaret).Hide;
end;
procedure TButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
inherited;
TMyCaret(GetCaret).Pos := TPointF.Create(X, Y);
end;
procedure TButton.ShowCaret;
begin
TMyCaret(GetCaret).Show;
end;
end.
You don't need icaret for it to work. I think, because I am writing a memo component and have custom drawing that I need the update flasher because its being positioned during the paint (although this may change). Each paint seems to hide it.
ReplyDelete