Recent

Author Topic: Control inside control...  (Read 459 times)

Espectr0

  • Full Member
  • ***
  • Posts: 156
Control inside control...
« 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!

« Last Edit: April 01, 2023, 01:24:05 pm by Espectr0 »

jamie

  • Hero Member
  • *****
  • Posts: 5362
Re: Control inside control...
« Reply #1 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.
The only true wisdom is knowing you know nothing

Espectr0

  • Full Member
  • ***
  • Posts: 156
Re: Control inside control...
« Reply #2 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 :)


Blaazen

  • Hero Member
  • *****
  • Posts: 3234
  • POKE 54296,15
    • Eye-Candy Controls
Re: Control inside control...
« Reply #3 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.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Blaazen

  • Hero Member
  • *****
  • Posts: 3234
  • POKE 54296,15
    • Eye-Candy Controls
Re: Control inside control...
« Reply #4 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.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 5362
Re: Control inside control...
« Reply #5 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 ?


The only true wisdom is knowing you know nothing

Espectr0

  • Full Member
  • ***
  • Posts: 156
Re: Control inside control...
« Reply #6 on: April 01, 2023, 05:41:20 pm »
so I should use it next to it and not inside the control :(

jamie

  • Hero Member
  • *****
  • Posts: 5362
Re: Control inside control...
« Reply #7 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.
The only true wisdom is knowing you know nothing

Espectr0

  • Full Member
  • ***
  • Posts: 156
Re: Control inside control...
« Reply #8 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
« Last Edit: April 01, 2023, 06:36:56 pm by Espectr0 »

 

TinyPortal © 2005-2018