This "execute block" of which I never heard of thrills me.
Would this be possible in my table as well?
Yes, it is. Just paste the given code into a TIBQuery and see the result (change the TBL variable at the top).
The problem however is that this does not include editing capabilities in the TDBGrid.
(You also didn't ask about that in your original post...)
The number of fields don't matter. They are presented in a TDBGrid in vertical layout so will scroll when there are too many for the view.
Do you think, I shall use one or more ideas from above, when you see how many fields there are?
At the moment I ask myself if I shall do them in a crowd of DBEdit-fields instead.
Normally, for a editable config screen I would choose TDBEdit or TValueListEditor.
Going with the TDBEdit's you could do something like this:
I just made the simple example real quick... with left side the TDBGrid (non editable) vertical view of the table.
(That's the IBQuery1/Datasource1)
At the right I have a ScrollBox1 where I dynamically put in some TDBEdit's.
When there are more TDBEdit's for the view you'll get the scrollbars (as seen in the image).
Of course you can also use the TValueListEditor or TStringGrid or anything you want, but the TDBEdit's are easy because you can just use .Post/.Commit in a button.
procedure TForm1.FormCreate(Sender: TObject);
var
S: string;
I, X, Y: integer;
Ed: TDBEdit;
begin
IBDatabase1.Connected := True;
// setup the transposed TDBGrid view
s := '';
s := s + 'EXECUTE BLOCK' + #13;
s := s + 'RETURNS (FLD VARCHAR(20), VAL VARCHAR(200)) AS' + #13;
s := s + 'DECLARE TBL VARCHAR(20);' + #13;
s := s + 'BEGIN' + #13;
s := s + ' TBL = ''LAND'';' + #13;
s := s + ' FOR SELECT X.RDB$FIELD_NAME' + #13;
s := s + ' FROM RDB$RELATION_FIELDS X' + #13;
s := s + ' WHERE (X.RDB$RELATION_NAME = :TBL)' + #13;
s := s + ' ORDER BY X.RDB$FIELD_POSITION INTO FLD DO' + #13;
s := s + ' BEGIN' + #13;
s := s + ' EXECUTE STATEMENT ''SELECT FIRST 1 '' || FLD || '' FROM '' || TBL INTO VAL;' + #13;
s := s + ' SUSPEND;' + #13;
s := s + ' END' + #13;
s := s + 'END' + #13;
IBQuery1.SQL.Text := s;
IBQuery1.Active := True;
// example of just putting everything in TScrollbox
IBQuery2.SQL.Text := 'SELECT * FROM LAND';
IBQuery2.Active := True;
// we now fill the TScrollBox
Y := 5; // we begin at Y position 5
for I := 0 to IBQuery2.FieldCount - 1 do
begin
Ed := TDBEdit.Create(ScrollBox1);
Ed.Parent := ScrollBox1;
Ed.Top := Y;
Ed.Left := 100; // adjust if you have larger descriptions/labels
Ed.DataSource := DataSource2;
Ed.DataField := IBQuery2.Fields[I].FieldName;
// we also want a label in front of the TDBEdit
with TLabel.Create(Ed) do
begin
Parent := Ed.Parent;
Left := 10;
Top := Y;
Text := IBQuery2.Fields[I].FieldName;
end;
Y := Y + Ed.Height + 3; // now increase for the next TDBEdit
end;
end;
BTW... You could also design a real screen but then you need to know all the fields.
In my own program I have dynamic procedure where I can easily create and change such screens.
This is because some fields also need to be TDBComboxes instead of TDBEdit for the lookup or foreign keys.
For LAND it's looks something like this:
AddBox(0, 0, 100, 'Financieel');
AddEdit(true, 1, 50, 'EXPORTCODE', 'Exportcode');
AddEdit(true, 1, 50, 'DAGBOEK', 'Dagboek');
AddEdit(true, 1, 50, '1.L_Valuta', 'Valuta');
AddEdit(true, 1, 30, '2.L_BTWHOOG', 'Btw hoog');
AddEdit(true, 1, 30, '3.L_BTWLAAG', 'Btw laag');
AddEdit(true, 1, 30, '4.L_BTWNUL', 'Btw nul');
AddEdit(true, 1, 30, '5.L_BTWVERLEGD', 'Btw verlegd');
And with the AddBox and AddEdit I can also put inputboxes next to each other.
But when you don't know the number of content of the fields, the first method with TScrollBox would be fine.