I have to show several Edit components on a form based on a user selection
in a ComboBox.
I've made them all on the form and stick them one above the other, they are
all child from the same groupbox.
First I made them all Invisible and then in the ComboBox OnChange event I
only show the ones I need.
This works fine but it is very messy at design time.
My question is:
Is there a way to store these Edit components on a TPageControl / TabSheet
in a way that I can show Edit1 and Edit2 on the first TabSheet and Edit1 and
Edit3 on the second TabSheet, this as an example.
I want to avoid the creation of the same Edits on multiple Tabsheets.
I don't use a database in this application.
Thanks,
Willy Verbiest
Here is the form
object Form1: TForm1
Left = 192
Top = 205
Width = 408
Height = 307
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object PageControl1: TPageControl
Left = 16
Top = 16
Width = 289
Height = 193
ActivePage = TabSheet2
TabOrder = 0
object TabSheet1: TTabSheet
Caption = 'TabSheet1'
object Edit1: TEdit
Left = 24
Top = 32
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Edit2: TEdit
Left = 32
Top = 88
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit2'
end
end
object TabSheet2: TTabSheet
Caption = 'TabSheet2'
ImageIndex = 1
object Edit3: TEdit
Left = 48
Top = 24
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit3'
end
object Edit4: TEdit
Left = 48
Top = 80
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit4'
end
end
end
end
Here is the unit
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
end.
"Willy Verbiest" <willy.v...@pandora.no spam.be> escreveu na mensagem
news:3d06662e_1@dnews...
use the Edit/ Bringto front option on delphi menu
Something like this
object Form1: TForm1
Left = 192
Top = 205
Width = 408
Height = 307
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object PageControl1: TPageControl
Left = 16
Top = 16
Width = 289
Height = 193
ActivePage = TabSheet2
TabOrder = 0
object TabSheet1: TTabSheet
Caption = 'TabSheet1'
object Edit2: TEdit
Left = 32
Top = 88
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit2'
end
end
object TabSheet2: TTabSheet
Caption = 'TabSheet2'
ImageIndex = 1
object Edit3: TEdit
Left = 32
Top = 64
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit3'
end
object Edit4: TEdit
Left = 40
Top = 120
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit4'
end
end
end
object Edit1: TEdit
Left = 32
Top = 56
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit1'
end
end
"Willy Verbiest" <willy.v...@pandora.no spam.be> escreveu na mensagem
news:3d06662e_1@dnews...
Thanks for your answer; I think I was not clear in my first mail. In fact
what you are suggesting is what I do now.
My problem is that I have 3 regions on the form
User input data
+-----------------+
| 1 |
| |
| |
+-----------------+
Memo1 with 6 lines = user input converted to a communication frame
+-----------------+
| 2 |
| |
| |
+------ ----------+
Memo2 logbook of the communication
+-----------------+
| 3 |
| |
| |
+-----------------+
In area 1 I need edit fields for Type, Port Id, Data, Mask, Time etc
Depending on the selection in a ComboBox I have to show one or more of the
edit fields.
The edit fields are of type TEdit, TSpinEdit and others about 20 in total.
They are now all child of a Groupbox and I use the mechanism of hiding and
showing them
My problem is that these 20 edits cover the whole area 1 and I have to move
several of these edit fields to find the one I want to check his properties
at design time.
At run time I calculate the positions of the edit fields and make them
visible as necessary.
As the form must be able to grow and shrink I use some panels under the
groupboxes so there is no form area visible at design time.
One of the tests I made with a PageControl is to put on each page the edit
fields I need and in the OnChange of an edit field
I write the value to a global variable, which I will use, further in the
program.
i.e.
So I've placed on several TabSheets an Edit field for the "Port Id" value,
they will have names like:
TabSheets1 has Edit1_Port_Id, TabSheets2 has Edit2_Port_Id, TabSheets3 has
Edit3_Port_Id, TabSheets4 has Edit4_Port_Id,
The OnChange event of Edit1_Port_Id to Edit4_Port_Id fields point all to the
same procedure
TForm1.EditChange_Port_Id(Sender: TObject);
begin
if (Sender is TEdit) then
with (Sender as TEdit) do
Port_Id := Text;
end;
The OnShow event of all the TabSheets are pointing to the same OnShow event
to write the current value to the edit field.
procedure TForm1.TabSheet1Show(Sender: TObject);
begin
Edit1_Port_Id.Text := Port_Id;
Edit2_Port_Id.Text := Port_Id;
Edit3_Port_Id.Text := Port_Id;
Edit4_Port_Id.Text := Port_Id;
end;
Now if the user clicks the Build button I can use the global variable
Port_Id and don't have to take care on which TabSheet it was.
I also use a procedure to remove the Tabs from the PageControl so that the
user only sees the TabSheet corresponding with the current ComboBox
selection as there are a lot of selections in the ComboBox and it would not
be nice on the screen to put these texts of the ComboBox in the Tabs of the
PageControl. It is also posible depending on the ComboBox selection that I
make the whole PageControl invisible.
This is the best thing I found out, if this solution is unconventional or
there is a better way to do it please let me know.
Kind regards,
Willy Verbiest
"Saci" <nos...@bol.com.br> wrote in message news:3d0680e2$1_2@dnews...
> The tip is to put Edit 1 on the Main form not on Page control, and
>
> use the Edit/ Bringto front option on delphi menu
>
> Something like this
>
>
>
>I also use a procedure to remove the Tabs from the PageControl so that the
>user only sees the TabSheet corresponding with the current ComboBox
>selection
A (better?) alternative would be to use Frames instead of TabSheets.
If performance requirements allow for it, you can create/destroy them
at runtime, thus saving resources. What the combo selection would do
in this case is decide which frame to create or show.
Manuel Algora
cen...@wanadoo.es
I've considered to use frames but I have the same problem as with
PageControl and Tabsheet,
Frames are other units and when I need the same question (edit Field) in two
frames I end up in the same situation as with a PageControl I have to create
two edit fields. I think I will stick with the solution I found.
Thanks all for the support.
Kind regards,
Willy
"Manuel Algora" <cen...@wanadoo.es> schreef in bericht
news:5eqegug49aviv7vi5...@4ax.com...
On Wed, 12 Jun 2002 11:32:03 +0200, "Willy Verbiest"
<willy.v...@advantra.no Spam.be> wrote:
1. Just one tip with the PageControl and TabSheet's. If you only want
one tab sheet to be visible at a given time you can set TTabSheet's
TabVisible property to false for all tab sheets and then just show the
page that you want to display in the page control with:
pcPages.ActivePage := tsSheet1
or to hide active sheet use
pcPages.ActivePage := nil
In this way you will not see tabs on the screen and still in design
time you get the place holders for your components on every tabsheet.
2. Idea for your problem:
I see that you need to use the same edit controls for more then one
combination of edit controls. IF I would be you I would make it in
this way:
For every component, or to say a parameter or a group of
parameter/controls that always goes together in any combination I
would create a separate TPanel control and put this on this panel. So
finaly there would be as many panels with controls as many controls
there are. For every such panel set no borders and make it allign top.
When you need to have certain combination of entry controls you just
show/hide the panels with controls. First hide all panels, and then
show just the ones that hold the controls that you want to have in
this particular combination of entry.
User would not visualy diferentiate this panels, and you would avoid
run time position calculation for entry controls.
tomi.
Thanks for the suggestions.
I did now the following and I'm very happy with it.
First on top of my form I created a GroupBox with a caption ' User Commands
'
This GroupBox has a fix size.
I've placed a button on it with the caption 'Build command'
I've placed a Combobox in the GroupBox 'User Command'
I've created a frame unit
I've dropped the frame in the GroupBox 'User Commands'
On the frame in the other unit I have placed all the edit fields I needed to
build the commands.
Each edit field is placed in a GroupBox with a proper title; they are placed
on the frame at random.
I wrote a procedure to hide all GroupBoxes of the frame at once.
When the user make a selection with the Combobox then in the 'OnChange'
event I write code to show the GroupBoxes of the edit fields I need, and I
also calculate their position.
This works fine, I only have one edit field for each value I need. At design
time I can spread them all over the frame form so that I see them all and it
is easy to change some parameters of them
Like Maximum or Minimum value.
At run time they sit all at there correct position.
Willy
"Tomislav Kardas" <nomail@sorry> wrote in message
news:3d0c7585...@newsgroups.borland.com...