• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

Grouping controls

Hi Experts,
my form has up to 30 label and listbox components. A label belongs to a listbox. The label contains the name of the list. The user can move the lists but the caption has to be move with the list. Somehow can I "group" this two controls or when one of them will be moved the other component has to change his position accordingly using the Top and Left parameters? Which solution is better?
regards
Janos
0
kacor
Asked:
kacor
  • 12
  • 7
  • 4
  • +2
1 Solution
 
jyh1002Commented:
I think you could use TFrame. Make a new frame from menu: "File | New | Frame" and put a label and a listbox component in it and set AutoSize to True.
From the form that will have 30 labels and listboxes, add 30 frames using frame component in "Standard Tab" of component pallet.

framesample.bmp
0
 
jyh1002Commented:
You can access each label or listbox like

Frame11.Label1.Caption := 'List1'
0
 
kacorretiredAuthor Commented:
Sorry, I can't test it now because I had to start a full scan. (I can't start my outlook and I mean I can have virus).
wbr Janos
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Geert GruwezOracle dbaCommented:
how are you moving the controls now ?
using WM_HITTEST and htCaption ?
0
 
kacorretiredAuthor Commented:
Hi,
thanks for your comment. I had some viruses :-( but deleted all successful.

I am in early phase and I don't decided.
0
 
Geert GruwezOracle dbaCommented:
have you actually got anything moving yet ?
because at runtime, it's not that easy ...
0
 
kacorretiredAuthor Commented:
Earlier I realized a moving. if you are interested I'll show you
0
 
Geert GruwezOracle dbaCommented:
i know how to do it,
but to give you an answer on your question we need to know roughly how you did the moving

there are several ways of doing it,
so if you narrow it down with some code it would be easier to help.
0
 
kacorretiredAuthor Commented:
thanks I'll show it in an other topic
0
 
MerijnBSr. Software EngineerCommented:
You can take a look at how TLabeledEdit is implemented, it does exactly what you want but it uses a label with an edit instead of a label with a listbox
0
 
bokistCommented:
one of possible solutions (not tested)

supposing you have components named as :
    Label_1, Label_2, ... Label_30  
and
    Listbox_1, Listbox_2, ... Listbox_30



procedure TForm1.MouseDown(Sender: TObject; Button: TMouseButton;
                Shift: TShiftState; X, Y: Integer);
var
   comp : TComponent;
   name, nr : string;
begin
  if Ssleft in Shift then
     begin
     if (Sender is TListbox) then
         begin
         ReleaseCapture;
         name := (Sender as TListbox).Name;
         nr := trim(copy(name, pos('_', name)+1, 2));
         comp := frmMain.FindComponent('Label_' + nr) as TLabel;
         (Sender as TListbox).Perform(WM_syscommand, $F012, 0);
         (Comp as TLabel).Top := (Sender as TListbox).Top - 20;
         (Comp as TLabel).Left := (Sender as TListbox).Left;
         (Comp as TLabel).Refresh;
     end;
     if (Sender is TLabel) then
         begin
         ReleaseCapture;
         name := (Sender as TLabel).Name;
         nr := trim(copy(name, pos('_', name)+1, 2));
         comp := frmMain.FindComponent('Listbox_' + nr) as TListbox;
         (Sender as TLabel).Perform(WM_syscommand, $F012, 0);
         (Comp as TListbox).Top := (Sender as TLabel).Top + 20;
         (Comp as TListbox).Left := (Sender as TLabel).Left;
         (Comp as TListbox).Refresh;
     end;
end;

Open in new window

0
 
Geert GruwezOracle dbaCommented:
a property of a label is FocusControl
you set this property to the control you want to *link*

you could then try to find the label using this property


   

function TForm1.LabelOf(aComp: TComponent): TLabel;
var I: Integer;
begin
  Result := nil;
  for I := 0 to ComponentCount-1 do
    if (Components[I] is TLabel) and (TLabel(Components[I]).FocusControl = aComp) then 
    begin
      Result := TLabel(Components[I]);
      Break;
    end;
end;

Open in new window

0
 
kacorretiredAuthor Commented:
jyh1002,
thanks for your advise. My problem is as follows:
The frame has the property Name and Delphi creates a class name based on this name. For example Name of frame is Frame1 then the class TFrame1 will be created, the for name List created class is TList, or Form -> TForm, etc.This names are reserved names I mean. I can't limit the names given by users  as frame names.
If I use this frame names to distinguish the lists this can lead to not wanted problems.
Therefore I can't use your sugestion for my project.
with best regards
Janos
0
 
kacorretiredAuthor Commented:
jyh1002,
I revised my earlier comment. The frame name is hidden for the user. There your suggestion is acceptable.
I have to assure the user he can delete any list (eg. frame) because what you see on the form is the list itself. But I can't delete list it is part of the control. To delete this control I have to delete the frame. What I see is the list. Therefore I have to use a twodimensional array. The first column contains the list names, the second the frame names. When I try to delete the list (what I can click on) using indirect reference first I search the list in the first column to find the clicked list. When it was found I can reference the frame name from the second column to delete the frame. It is a bit complicated. Could someone suggest an easier way?
wbr
Janos
0
 
Geert GruwezOracle dbaCommented:
could you provide a more general description as what you want to do with this form ?
0
 
kacorretiredAuthor Commented:
well,
I'd like to make a GUI for developing SQL-based database. I told earlier a number of 30 for the number of controls (frame+caption+list) but of course this can be higher according to needs.
0
 
kacorretiredAuthor Commented:
why? I tested some of graphic database developing programs but neither of them fulfilled the requirements I needed to develop a job.
 I don't want to describe this phenomenas because this would be the essence of this project and new in this area.
0
 
Geert GruwezOracle dbaCommented:
is it something like a diagram of a database ?

the caption would be the tablename and the frame the fieldlist ...
something like that ?
0
 
jyh1002Commented:
I think once you find ListBox then you can get the reference to Frame using Parent property easily.

if FoundListBox.Parent is TFrame1 then
  TFrame1(ListBox.Parent).Free;

0
 
jyh1002Commented:
Let say, you have a ListBox named "ItemGroup" that keeps 30 ListBox's variable.
When user clicks a item in ItemGroup, you can delete the Frame like
procedure TForm1.FormCreate(Sender: TObject);
begin
  ItemGroup.AddItem('Box1', Frame11.ListBox1);
  ItemGroup.AddItem('Box2', Frame12.ListBox1);
  // ...
end;
 
procedure TForm1.ItemGroupClick(Sender: TObject);
var tmpObj: TObject;
begin
  tmpObj := ItemGroup.Items.Objects[ItemGroup.ItemIndex];
  if Assigned(tmpObj) and (tmpObj is TListBox) then
  begin
    if TListBox(tmpObj).Parent is TFrame1 then
      TListBox(tmpObj).Parent.Free;
  end;
end;

Open in new window

0
 
kacorretiredAuthor Commented:
Geert_Gruwez,
yes

jyh1002
thanks for your suggestion and for the code!
Janos
0
 
kacorretiredAuthor Commented:
thanks. I asked something and you gave the exact answer.
0
 
Geert GruwezOracle dbaCommented:
new in this area ...
have you tried toad from quest ?

http://www.quest.com/Toad-Data-Modeler/
0
 
kacorretiredAuthor Commented:
yet not but thank you for this suggestion.

I know this will be hard.
wbr
Janos
0
 
kacorretiredAuthor Commented:
I surfed the site you suggested but they have not elaborate version for my need. But I will test.

again thank you for your comments. When I have difficulties I'll ask my next question :-))

Janos
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 12
  • 7
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now