Lazarus

Programming => LCL => Topic started by: Espectr0 on April 01, 2023, 01:20:02 pm

Title: Control inside control...
Post by: Espectr0 on April 01, 2023, 01:20:02 pm
Hola,

I have a component (TCustomEdit) that I add a TUpDown inside with the following code (constructor):

Code: Pascal  [Select][+][-]
  1.   FUpDown := TUpDown.Create(Self);
  2.   with FUpDown do
  3.   begin
  4.     SetSubComponent(True);
  5.     Width        := 14;
  6.     Height       := Self.Height;
  7.     Increment    := 1;
  8.     Flat         := True;
  9.   end;
  10.  

and (AdjustClientRect):

Code: Pascal  [Select][+][-]
  1. begin
  2.   inherited;
  3.   with FUpDown do
  4.   begin
  5.     Align   := alNone;
  6.     Anchors := [akLeft, akTop];
  7.     Parent  := Self.Parent;
  8.     Left    := Self.Left + Self.Width - Width;
  9.     Top     := Self.Top;
  10.     Height  := Self.Height;
  11.   end;
  12. end;
  13.  

It works correctly but the error that I found is when changing the border of the TCustomEdit (runtime and desigtime) to bsNone, TUpDown disappears.
Also if I put it back to bsSingle it does not appear...  %)

Any idea how to solve it?

Thanks!

Title: Re: Control inside control...
Post by: jamie on April 01, 2023, 03:35:58 pm
We are back to the parent issue again, only this time you must use the SELF only as the parent and make all of your locations work with the client of your parent, not the Parent of the parent etc.

 This is only assuming that you are actually attempting to get the updown control to sit inside of the control under it.

btw. The TUpDown does have an Associate property that allows it to hug itself to a side of a control.
Title: Re: Control inside control...
Post by: Espectr0 on April 01, 2023, 03:55:05 pm
If I understood modified the following line:

Code: Pascal  [Select][+][-]
  1. Parent  := Self.Parent;
  2.  
  3. to
  4.  
  5. Parent  := Self;

but now TUpDown does not appear  :(


Quote
The TUpDown does have an Associate property that allows it to hug itself to a side of a control.

That's right, but I want to put it inside instead of next to it :)

Title: Re: Control inside control...
Post by: Blaazen on April 01, 2023, 04:48:26 pm
This works:
Code: Pascal  [Select][+][-]
  1.  
  2.   UpDown1.Parent:=Edit1;  
  3.   UpDown1.Anchors:=[akRight];
  4.   UpDown1.AnchorSideRight.Control:=Edit1;
  5.   UpDown1.AnchorSideRight.Side:=asrRight;
  6.   UpDown1.AnchorVerticalCenterTo(Edit1);

However, I'm not sure if placing TUpDown on the TEdit will work well on all widgetsets. It may cause some visual glitches, disappearing, maybe.
Title: Re: Control inside control...
Post by: Blaazen on April 01, 2023, 05:13:56 pm
It work in Qt4. GTk2 and GTk3 do not allow you to have TEdit as a Parent of anything.
Title: Re: Control inside control...
Post by: jamie on April 01, 2023, 05:28:53 pm
Yes, that is true also in Windows, I forgot about that.

It's a restriction of the LCL, not windows.
 Wouldn't something like a spin edit work but maybe for text in a Stringlist ?


Title: Re: Control inside control...
Post by: Espectr0 on April 01, 2023, 05:41:20 pm
so I should use it next to it and not inside the control :(
Title: Re: Control inside control...
Post by: jamie on April 01, 2023, 05:55:55 pm
Yes, exactly.

 If I knew exactly what you are trying to do I can punch out an example.

 if for example, you wanted a scrolling combobox using the simple form with no drop down and also give you an editor feature, you can attached that to the side of a combobox.Simple style.

You can stretch the box out of course to see the list of choices etc.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.UpDown1ChangingEx(Sender: TObject; var AllowChange: Boolean;
  2.   NewValue: SmallInt; Direction: TUpDownDirection);
  3. begin
  4.   Case Direction of
  5.    UpdUp:With ComboBox1 do
  6.     if ItemIndex >=0 Then ItemIndex := ItemIndex-1;
  7.    UpdDown:With ComboBox1 Do
  8.     If ItemIndex < Items.Count-1 Then ItemIndex := ItemIndex+1;
  9.   end;
  10. end;  
  11.                                            
  12.  

Something like that.
in that case, you do not associate the arrows with the combobox, just attached them.
Title: Re: Control inside control...
Post by: Espectr0 on April 01, 2023, 06:35:21 pm
I tell you,
in my application I have a time component (tcustomedit + tupdown + functions),
currently to put it to the side use:

Code: Pascal  [Select][+][-]
  1.     FUpDown.AnchorToCompanion(akLeft, FSpinSpacing, Self);
  2.     FUpDown.AnchorVerticalCenterTo(Self);
  3.  

and it works perfectly now I wanted to implement "onmouseenter/leave" to show or hide "tupdown".
If I implement it in the tedit when exiting I can no longer place the mouse over the tupdown because is hidden by my tedit mouseleave :D

I don't know if I explain myself with my bad English
TinyPortal © 2005-2018