We help IT Professionals succeed at work.

Very easy...

Sendo
Sendo asked
on
This is for learning sake (just beginner):
I created a simple paradox table (named "INFO) with folowing field info:
Name -Surname-Company-Adress-City-HomePhone-CompanyPhone-GSM-EMail
I would like to have a combo or something like it with items in it,like:
1.)Full Personal Info (My grid would display name/surname/adress/city/Phone/GSM/EMail)
2.)Personal Phone (My grid would display name/surname/Phone
and so on...
I understand that my grid will display results of a queery based on the "INFO" table.How am I to
go about this i.e how am I to service onclick event of the combo and what is the queery SQL supposed to
look like?Please go slow...just learning...
Comment
Watch Question

Commented:
Hi Sendo,

I'll try to go slow :)

Your query SQL could look like this:

select
  *
from
  INFO

This way you select all field from the table. This has the advantage that you do not need to change the query when you add fields to the table.

After you open the query using Open you can change what appears in the browse changing the Visible property of some fields:

Query1.FieldByName('Surname').Visible := False;

From you question I read that you want presets in a combobox. You have to set Style property of the TComboBox to csDropDownList and have a FormCreate event that sets the MyCombo.ItemIndex to 0;

If you add a OnChange event on the combobox your OnChange code could look like this:

procedure TForm1.MyComboChange(Sender: TObject);
begin
  case MyCombo.ItemIndex of
    0: begin
      Query1.FieldByName('Surname').Visible := True;
      ... more Visible property settings ...
    end;
    1: begin
      Query1.FieldByName('Surname').Visible := False;
      ... more Visible property settings ...
    end;
  end;
end;

The Visible property value of the fields will not survive an Close / Open action on the Query. (The fields are destroyed and recreated then (unless you add all fields to the Query in design time)). You can solve this problem by assigning a AfterOpen event to the Query1 (you can do this by selecting the query on the form going to the object inspector and clicking on the events page then double clicking on AfterOpen):

procedure TForm1.QueryAfterOpen(Sender: TObject);
begin
  MyComboChange(nil);
end;

This way you act as if the ComboBox has changed when the Query is opened. And this set (or resets the Visible properties of the fields)

I hope this helps,

Have fun with Delphi!!

Regards Jacco

Regards Jacco
Sendo:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.

Commented:
I think I gave a good suggestion.
CERTIFIED EXPERT

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept Jacco's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.