Using DBCTRL Grid - delphi

I am using TDBCtrl Grid, and I can only see one record to see next record I have to scroll however I have set RowCount=5. Also, my dbgridCTRL can only allow TDBEdit or TEdit controls. I want to display static text also. Can you please suggest How can I display the Labels on DBCTRL Grid.
This is how the currently looks like. The Rans Member etc are staticText control. However I want to display multiple records at the same time.
object DBCtrlGrid1: TDBCtrlGrid
Left = 4
Top = 2
Width = 215
Height = 122
AllowDelete = False
AllowInsert = False
DataSource = DSCredit
PanelHeight = 122
PanelWidth = 199
TabOrder = 0
RowCount = 1
OnPaintPanel = DBCtrlGrid1PaintPanel
end

Height == PanelHeight * RowCount. And same for widths/columns.
You have to set sizes of panels and girds in a way, that several panels would fit inside the visible area of the grid. If the panel size is the same as the total size of all panels - then thereis just no places for other panels being visible.
PS. x-ref https://stackoverflow.com/questions/20658435/
Below is the example of DFM with the controls inside the Control Grid. The DFM example above shows empty grid without internal controls.
object Form9: TForm9
Left = 0
Top = 0
Caption = 'Form9'
ClientHeight = 390
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object grid1: TDBCtrlGrid
Left = 48
Top = 38
Width = 217
Height = 300
PanelHeight = 100
TabOrder = 0
object pnl1: TPanel
Left = 0
Top = 16
Width = 185
Height = 41
Caption = 'pnl1'
TabOrder = 0
object dbedt1: TDBEdit
Left = 48
Top = 11
Width = 121
Height = 21
TabOrder = 0
end
end
end
end

Related

Delphi - Button images suddenly not showing

Delphi 11.1 Windows application, suddenly my TButtons with images are not displaying the images. They normally don't display in debug mode, but now they're not showing in release mode.
These are TButton components with TImageList assigned and ImageIndex value assigned. I have several TBitBtn components that are displaying properly.
First screenshot shows TButton with miscButtons chosen as images and ImageIndex 16. The image shows in IDE. Second screenshot is running the application. I already changed Go To Activity to TSpeedButton, so the image is working.
object btnReqNewActivity: TButton
Left = 141
Top = 454
Width = 175
Height = 40
Caption = 'Request NEW Activity'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
ImageIndex = 16
ImageMargins.Left = 5
Images = miscButtons
ParentFont = False
TabOrder = 1
OnClick = btnReqNewActivityClick
end
object btnExportClassicList: TButton
Left = 333
Top = 454
Width = 78
Height = 40
Caption = 'Export'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
ImageIndex = 4
ImageMargins.Left = 5
Images = miscButtons
ParentFont = False
TabOrder = 2
OnClick = btnExportClassicListClick
end

How to align controls left and top without fixed width?

I have 6 RichEdit controls in ScrollBox. They need to be aligned left in sequence from top to bottom, but I need width to be not fixed, so I can use scroll bar to scroll to see full text, when text length goes beyond ScrollBox width.
If I set:
RichEdit1.Align := alTop;
RichEdit2.Align := alTop;
RichEdit3.Align := alTop;
RichEdit4.Align := alTop;
RichEdit5.Align := alTop;
RichEdit6.Align := alTop;
they align perfectly and stay fixed in design so can't move them accidentally, but the width gets fixed. Not good.
If I align them manually, then they are not fixed when clicking on them and can be moved and I need to re-arrange all the time. Annoying.
The picture show on top all RichEdits with Align = alTop and width is fixed to ScrollBox width.
Bottom example is with manual alignment of all RichEdits that width can go beyond ScrollBox's width, but they can be moved around in design:
So, I would like to get them fixed to left, top as does alTop, but not to fix the width. How can I achieve this?
At design time use Align = alTop. Then, at runtime (e,g, OnCreate of form) set Align := alNone, and change the width as you like.
If preventing accidental moving is your goal, I see two solutions.
Use Delphi's "Lock Controls" option
Edit > Lock Controls, but this is a temporary solution which is not saved, and upon closing / re-opening, it will be disabled again.
Align them all inside of a panel
And then make that panel to the width you need. However this still wouldn't prevent you from accidentally moving the panel - just the edit controls. And even then, you're still able to re-arrange aligned controls - if you were to accidentally drag one beyond the edge of its neighbor.
Here's a sample DFM structure:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 340
ClientWidth = 392
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ScrollBox1: TScrollBox
Left = 24
Top = 8
Width = 329
Height = 281
TabOrder = 0
object Panel1: TPanel
Left = 3
Top = 3
Width = 500
Height = 217
TabOrder = 0
object Edit1: TEdit
Left = 1
Top = 1
Width = 498
Height = 21
Align = alTop
TabOrder = 0
Text = 'Edit1'
ExplicitLeft = 40
ExplicitTop = 48
ExplicitWidth = 121
end
object Edit2: TEdit
Left = 1
Top = 22
Width = 498
Height = 21
Align = alTop
TabOrder = 1
Text = 'Edit2'
ExplicitLeft = 16
ExplicitTop = 56
ExplicitWidth = 121
end
object Edit3: TEdit
Left = 1
Top = 43
Width = 498
Height = 21
Align = alTop
TabOrder = 2
Text = 'Edit3'
ExplicitLeft = 40
ExplicitTop = 96
ExplicitWidth = 121
end
object Edit4: TEdit
Left = 1
Top = 64
Width = 498
Height = 21
Align = alTop
TabOrder = 3
Text = 'Edit4'
ExplicitLeft = 32
ExplicitTop = 128
ExplicitWidth = 121
end
object Edit5: TEdit
Left = 1
Top = 85
Width = 498
Height = 21
Align = alTop
TabOrder = 4
Text = 'Edit5'
ExplicitLeft = 56
ExplicitTop = 160
ExplicitWidth = 121
end
object Edit6: TEdit
Left = 1
Top = 106
Width = 498
Height = 21
Align = alTop
TabOrder = 5
Text = 'Edit6'
ExplicitLeft = 80
ExplicitTop = 192
ExplicitWidth = 121
end
end
end
end
On another note, this has inspired me to investigate how I can implement a LockChildren Boolean property on the TControl level which, when enabled, prevents you from moving or sizing its child controls.
Actually, I just found an apparent bug in Delphi with the "Lock Controls" option. If you enable it on a form, then close and re-open the form, the controls are no longer locked. But at the same time, if you go to the "Edit" menu, the "Lock Controls" option appears as if it's still enabled (even though it isn't). I think I recall this bug waaaaaay back in Delphi 7, but I see it still on Delphi 10 Seattle.
EDIT I found the QC report still open:
http://qc.embarcadero.com/wc/qcmain.aspx?d=82764

Resizing elements on formResize in delphi

I'm currently trying to resize components in my form but i can't figure it out how it works. I've tried OnResize and OnCanResize event but it won't change my component heigh or widht.
What i did until now is adding like fixed values to my heigh when the user is resizing but it doesn't resize the given component.
For example:
In my FormResize even i have something similar to:
procedure myform.FormResize(Sender TObject);
var
width: integer;
begin
width := grid.Width +100; //yes it only grows but it doesn't even work
grid.setBounds(grid.Left,grid.Top,width,grid.height);
end;
This doesn't work.
I also tried changing direcly with grid.Width := grid.Width +100 but it doesn't work either
I tried putting the same code in CanResize but same issue. I've tried with break points if it's the right event and if the procedure is being executed when i resize and yes it is. So i guess i missed something. My purpose is to resize the grid to keep the ratio to my form when ever a user resize/maximize the form.
So what is the proper way to resize a component?
Thank you.
DFM
object BDDTool: TBDDTool
Left = 0
Top = 0
Caption = 'BDD Manager'
ClientHeight = 303
ClientWidth = 680
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
Menu = mMainMenu
OldCreateOrder = False
Position = poScreenCenter
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13
object pnlFileManager: TPanel
Left = 8
Top = 8
Width = 665
Height = 289
BevelOuter = bvNone
TabOrder = 0
object Label1: TLabel
Left = 156
Top = 263
Width = 86
Height = 13
Caption = 'Primary key color:'
end
object Label2: TLabel
Left = 364
Top = 263
Width = 86
Height = 13
Caption = 'Foreign key color:'
end
object sgFilePreview: TStringGrid
Left = 143
Top = 23
Width = 514
Height = 234
Align = alCustom
ColCount = 1
Enabled = False
FixedCols = 0
RowCount = 2
TabOrder = 0
OnDrawCell = sgFilePreviewDrawCell
OnMouseDown = sgFilePreviewMouseDown
ColWidths = (
64)
RowHeights = (
24
24)
end
object btnConnectToDB: TButton
Left = 0
Top = 32
Width = 137
Height = 25
Caption = 'Connect to DB'
Enabled = False
TabOrder = 1
OnClick = btnConnectToDBClick
end
object btnCreateTabIncK: TButton
Left = 0
Top = 94
Width = 137
Height = 25
Caption = 'Create table (inc keys)'
Enabled = False
TabOrder = 2
OnClick = btnCreateTabIncKClick
end
object btnCreateTabGuidK: TButton
Left = 0
Top = 125
Width = 137
Height = 25
Caption = 'Create table (guid keys)'
Enabled = False
TabOrder = 3
end
object btnAscFk: TButton
Left = 0
Top = 156
Width = 137
Height = 25
Caption = 'Associate foreign keys'
Enabled = False
TabOrder = 4
OnClick = btnAscFkClick
end
object pnlFKColor: TPanel
Left = 456
Top = 263
Width = 81
Height = 18
TabOrder = 5
end
object btnDeconnectDB: TButton
Left = 0
Top = 63
Width = 137
Height = 25
Caption = 'Deconnect from DB'
Enabled = False
TabOrder = 6
OnClick = btnDeconnectDBClick
end
end
object pnlPKColor: TPanel
Left = 256
Check you grid's Align property. If it's set something else to alNone then the resizing won't work as excepted.
Instead of OnResize try to use Anchors. Anchors will tell the component where its edges will "glued" inside its parent. If you set an empty Anchor [] it will remains always centered, if you set it to [akBottom, akRight] it will remains in the Bottom Right corner of its parent when the parent component is resized. If you set it to [akLeft, akTop, akRight, akBottom] then it will resize in vertically and horizontally too and maintains space between the parent's edges and its own.
If you use Anchors, you doesn't need the OnResize event for that.

How to Resize a TEdit inside a TGridPanel without use the alClient align

I need to work with the folow structure:
TEdit inside TGdridPanel inside TGridPanel
In others words, exist a TGridPanel and in one of the cells I need to insert other TGridPanel.
In this internal TGridPanel a need to insert two TLabels and two TEdits, like this:
______________________
| TLabel1 | TLabel 2 |
______________________
| TEdit 1 | TEdit 2 |
______________________
When I resize the external TGridPanel, the internal one resize too, because the internal TGridPanel align is setup alClient, and when this happend I want resize the Label's and the Edit's like if them was anchored on left and right, but it doesn't when they are inside the TGridPanel and if I set the align of the this internals components as alClient, they are distorted.
I can't use other way, because I'm moving in a code very stable and do not have permission to change it.
Could please somebody help me?
Thank you.
The screenshots to be sure this is what you want... no code, just design...
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 337
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object grdpnl1: TGridPanel
Left = 0
Top = 0
Width = 635
Height = 337
Align = alClient
Caption = 'grdpnlOutside'
ColumnCollection = <
item
Value = 33.333333333333340000
end
item
Value = 33.333333333333340000
end
item
Value = 33.333333333333340000
end>
ControlCollection = <
item
Column = 0
Control = lbl1
Row = 0
end
item
Column = 1
Control = lbl2
Row = 0
end
item
Column = 2
Control = lbl3
Row = 0
end
item
Column = 0
Control = lbl4
Row = 1
end
item
Column = 1
Control = grdpnlInside
Row = 1
end
item
Column = 2
Control = lbl5
Row = 1
end
item
Column = 0
Control = lbl6
Row = 2
end
item
Column = 1
Control = lbl7
Row = 2
end
item
Column = 2
Control = lbl8
Row = 2
end>
RowCollection = <
item
Value = 33.333333333333340000
end
item
Value = 33.333333333333340000
end
item
Value = 33.333333333333340000
end>
ShowCaption = False
TabOrder = 0
ExplicitLeft = 144
ExplicitTop = 64
ExplicitWidth = 273
ExplicitHeight = 105
object lbl1: TLabel
Left = 1
Top = 1
Width = 211
Height = 111
Align = alClient
Caption = 'lbl1'
ExplicitLeft = 91
ExplicitTop = 50
ExplicitWidth = 16
ExplicitHeight = 13
end
object lbl2: TLabel
Left = 212
Top = 1
Width = 211
Height = 111
Align = alClient
Caption = 'lbl1'
ExplicitWidth = 16
ExplicitHeight = 13
end
object lbl3: TLabel
Left = 423
Top = 1
Width = 211
Height = 111
Align = alClient
Caption = 'lbl1'
ExplicitWidth = 16
ExplicitHeight = 13
end
object lbl4: TLabel
Left = 1
Top = 112
Width = 211
Height = 111
Align = alClient
Caption = 'lbl1'
ExplicitWidth = 16
ExplicitHeight = 13
end
object grdpnlInside: TGridPanel
Left = 212
Top = 112
Width = 211
Height = 111
Align = alClient
Caption = 'grdpnlInside'
ColumnCollection = <
item
Value = 50.000000000000000000
end
item
Value = 50.000000000000000000
end>
ControlCollection = <
item
Column = 1
Control = pnlBottomRight
Row = 1
end
item
Column = 0
Control = pnlBottomLeft
Row = 1
end
item
Column = 0
Control = pnlTopLeft
Row = 0
end
item
Column = 1
Control = pnlTopRight
Row = 0
end>
RowCollection = <
item
Value = 50.000000000000000000
end
item
Value = 50.000000000000000000
end>
ShowCaption = False
TabOrder = 0
ExplicitLeft = 312
ExplicitTop = 168
ExplicitWidth = 185
ExplicitHeight = 41
object pnlBottomRight: TPanel
Left = 105
Top = 55
Width = 105
Height = 55
Align = alClient
BevelOuter = bvNone
Caption = 'pnlBottomRight'
ShowCaption = False
TabOrder = 0
ExplicitLeft = 136
ExplicitTop = 72
ExplicitWidth = 185
ExplicitHeight = 41
DesignSize = (
105
55)
object edtRight: TEdit
Left = 0
Top = 17
Width = 105
Height = 21
Alignment = taRightJustify
Anchors = [akLeft, akRight]
TabOrder = 0
Text = 'edtRight'
ExplicitTop = 10
end
end
object pnlBottomLeft: TPanel
Left = 1
Top = 55
Width = 104
Height = 55
Align = alClient
BevelOuter = bvNone
Caption = 'pnlBottomRight'
ShowCaption = False
TabOrder = 1
ExplicitLeft = 136
ExplicitTop = 72
ExplicitWidth = 185
ExplicitHeight = 41
DesignSize = (
104
55)
object edtLeft: TEdit
Left = 0
Top = 17
Width = 105
Height = 21
Anchors = [akLeft, akRight]
TabOrder = 0
Text = 'edtLeft'
end
end
object pnlTopLeft: TPanel
Left = 1
Top = 1
Width = 104
Height = 54
Align = alClient
BevelOuter = bvNone
Caption = 'pnlBottomRight'
ShowCaption = False
TabOrder = 2
ExplicitLeft = 136
ExplicitTop = 72
ExplicitWidth = 185
ExplicitHeight = 41
DesignSize = (
104
54)
object lblLeft: TLabel
Left = 0
Top = 20
Width = 105
Height = 13
Anchors = [akLeft, akRight]
AutoSize = False
Caption = 'lblLeft'
end
end
object pnlTopRight: TPanel
Left = 105
Top = 1
Width = 105
Height = 54
Align = alClient
BevelOuter = bvNone
Caption = 'pnlBottomRight'
ShowCaption = False
TabOrder = 3
ExplicitLeft = 136
ExplicitTop = 72
ExplicitWidth = 185
ExplicitHeight = 41
DesignSize = (
105
54)
object lblRight: TLabel
Left = 0
Top = 20
Width = 105
Height = 13
Alignment = taRightJustify
Anchors = [akLeft, akRight]
AutoSize = False
Caption = 'lblRight'
end
end
end
object lbl5: TLabel
Left = 423
Top = 112
Width = 211
Height = 111
Align = alClient
Caption = 'lbl1'
ExplicitWidth = 16
ExplicitHeight = 13
end
object lbl6: TLabel
Left = 1
Top = 223
Width = 211
Height = 113
Align = alClient
Caption = 'lbl1'
ExplicitWidth = 16
ExplicitHeight = 13
end
object lbl7: TLabel
Left = 212
Top = 223
Width = 211
Height = 113
Align = alClient
Caption = 'lbl1'
ExplicitWidth = 16
ExplicitHeight = 13
end
object lbl8: TLabel
Left = 423
Top = 223
Width = 211
Height = 113
Align = alClient
Caption = 'lbl1'
ExplicitWidth = 16
ExplicitHeight = 13
end
end
end
Use the OnResize event of the inner TGridPanel to resize its child controls however you like. Use the inner TGridPanel's ClientWidth/ClientHeight to help calculate the sizes if you want them to fill the entire area.

Stackable Panel Delphi Component

does anyone know of a Delphi component that implements something similar to what jquery sortable does, but for a desktop application?
i.e. a vertical control that contains a number of panels that can be reordered and also used as containers for other components (specifically TMemos containing different bits of text).
Thanks for any info,
Breandan.
While I do it from code, and not designtime, this is what I would use a TScrollbox or TPanel containing some Frames or Panels, which are all aligned top, for. If I want a collapse/expand for the frames, I just put a button in the frame that allows you to collapse the frame to a minimal height such as 20 pixels when collapsed, and something taller when expanded.
the frames inside could really be any control you want, even Panels containing a few other controls. The top level controls can be reordered within the parent panel or scrollbox.
TMS Has TAdvPanelGroup that can be collapsed/expanded. See screenshot in the lower-right:
http://www.tmssoftware.com/site/advpanel.asp
Only one run, then I move and resize them from the running application.
Here's the dfm:
object Form2: TForm2
Left = 0
Top = 0
Caption = 'Form2'
ClientHeight = 337
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object clbr1: TCoolBar
Left = 0
Top = 0
Width = 635
Height = 313
Bands = <
item
Control = gb1
ImageIndex = -1
MinHeight = 123
Width = 629
end
item
Control = pnl1
ImageIndex = -1
MinHeight = 112
Width = 629
end>
object gb1: TGroupBox
Left = 11
Top = 0
Width = 620
Height = 123
Caption = 'gb1'
TabOrder = 0
object lbledt1: TLabeledEdit
Left = 112
Top = 40
Width = 121
Height = 21
EditLabel.Width = 32
EditLabel.Height = 13
EditLabel.Caption = 'lbledt1'
TabOrder = 0
end
end
object pnl1: TPanel
Left = 11
Top = 125
Width = 620
Height = 112
Caption = 'pnl1'
TabOrder = 1
object rg1: TRadioGroup
Left = 128
Top = 4
Width = 185
Height = 105
Caption = 'rg1'
Items.Strings = (
'dsfsdf'
'sdfsdfsd')
TabOrder = 0
end
end
end
end
I haven't found a standard control that does what you want in Delphi 2007, but I would offer a custom solution similar to the one Warren suggested. The main difference is that I would create it within a TFrame so you could more easily maintain the code that allows you to manipulate the controls and their interaction with each other. You could also create methods within the frame for adding new panels (with memos and the text to display), move them around, etc.
It's a bit of work but it can also be a great learning experience. The best part is once you are done you can reuse that frame anywhere you want on any form or within another frame. If you do it right it will work without hassle as well.

Resources