Jump to content
Sign in to follow this  
WalkingAway

ChangeTracking with dynamically created TMemo ...

Recommended Posts

Hello.

I need help.

I didn't entirely understand, but the same code working with TMemo component dropped to the form and not working with dynamically created TMemo.

More strangely, when I have two buttons (one for creating and one for calling recalc height of memo) - by clicking one after one - ok, but inside one (creating and updating height - not).

What is the reason?

Thanks.

 

unit Unit46;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Memo.Types,
  FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, FMX.StdCtrls;

type
  TForm46 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Memo1ChangeTracking(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form46: TForm46;
  Memo1: TMemo;

implementation

{$R *.fmx}

procedure TForm46.Button1Click(Sender: TObject);
begin
  Memo1 := TMemo.Create(self);
  Memo1.Parent := Form46;
  Memo1.Name := 'Memo1';
  Memo1.DataDetectorTypes := [];
  Memo1.Lines.Clear;
  Memo1.Lines.Add('AAAAAAAAAAAAAA');
  Memo1.ShowScrollBars := False;
  Memo1.OnChangeTracking := Memo1ChangeTracking;
  Memo1.Align := TAlignLayout.Horizontal;
  Memo1.EnabledScroll := False;
  Memo1.TabOrder := 0;
  Memo1.WordWrap := True;

 

  Memo1ChangeTracking(Memo1); //here is wrong Memo1.ContentBounds.Height
end;

procedure TForm46.Memo1ChangeTracking(Sender: TObject);
begin
  Memo1.Height := Memo1.ContentBounds.Height + 5;
end;

procedure TForm46.Button2Click(Sender: TObject);
begin
  Memo1ChangeTracking(Memo1);
end;

end.

Share this post


Link to post

It is possible that the ContentBounds might not have been updated yet if you call Memo1ChangeTracking in the same code scope as where you created the Memo. Some controls do some updates and calculations on their paint cycle which has not yet occured while in the Button1Click procedure.

 

Inspect the source code for the TMemo and possibly TEdit and check how ContentBounds gets populated and where it gets updated. That will probably give you an idea about whats happening here

Edited by PeaShooter_OMO

Share this post


Link to post

I have tried, but with no success.

Something like DoRealign is the place where this happens.

But actually this call not helps at all...

Only when I physically change something in memo, then fires this ChangeTracking ...

 

So close, but my skills  too low to solve this problem

 

Thanks

Share this post


Link to post

You can always set the Memo to a default height upon creation and then allow it to be changed dynamically as soon as the contents change. Or you can add some sort of text afterwards to force Memo1ChangeTracking but I strongly believe in first figuring out why this is happening so that you can make an informed decision about how to approach the issue.

 

You say your skills are too low to solve this problem. I disagree with such a statement. It is exactly the reason and opportunity for you to learn and acquire the skill. Put your head down and go through the source code and follow the breadcrumbs. Don't give up.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×