Solved

switch between tables

Posted on 2001-08-12
13
157 Views
Last Modified: 2010-04-06
How can I switch between tables by means of radiobuttons?
(Using ADO)
0
Comment
Question by:Bosanac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6377632
Hello

in onclick event for the radiobutton assgin the caption to the tablename for adotable

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
  if RadioButton1.Checked then
    ADOTable1.TableName := RadioButton1.Caption ;
    ADOTable1.Open;
end;

Best regards
Mohammed Nasman
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6377643
sorry forget to add this line   ADOTable1.Close;
so the code will be like the following

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
 if RadioButton1.Checked then
 begin
   ADOTable1.Close;
   ADOTable1.TableName := RadioButton1.Caption ;
   ADOTable1.Open;
end;
end;

but if I prefer to use RadioGroup instead of radiobutton for each table, you will right the code one time, and will work for the all items in the radiogroup, but in radiobutton you need to right the code for each radiobutton

for the RadioGroup the code will be as following

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  if RadioGroup1.ItemIndex =0 then
  begin
    AdoTable1.Close;
    AdoTable1.TableName := RadioGroup1.Items[RadioGroup1.ItemIndex];
    AdoTable1.Open;
  end;
end;

Mohammed
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6377686
sorry again

 change this line
if RadioGroup1.ItemIndex =0 then

to

if RadioGroup1.ItemIndex >=0 then
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Bosanac
ID: 6377747
And how do I tell my edit which table to search?
Also I want first option to be checked by default and shown when form opens....So 1st table is shown when form opens and so on....
CurrentTable:ADOTable ....something like this..???
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6377860
Hello Bosanac

  if you want the first option to be the default in oncreate event will look like

procedure TForm1.FormCreate(Sender: TObject);
begin
  RadioGroup1.ItemIndex := 0;
  AdoTable1.Close;
  AdoTable1.TableName := RadioGroup1.Items[RadioGroup1.ItemIndex];
  AdoTable1.Open;
end;

and if you want to know the current table, simply u can know that by TableName property

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(AdoTable1.TableName);
end;

I hope that what you need :)

Mohammed
0
 

Author Comment

by:Bosanac
ID: 6385225
It is easier to pass different datasource to grid by means of radiobuttons than manipulating tables.Also I do not like opening tables by their names as I call my tables all sorts,ha,ha....
Any other way???
0
 

Author Comment

by:Bosanac
ID: 6390035
Should it not go like this:

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
if RadioGroup1.ItemIndex =0 then
 begin
   ADOTable2.Close;
   AdoTable1.Close;
   AdoTable1.Open;
   RXDBGrid1.Datasource:=Datasource1;
   DBNavigator1.Datasource:=Datasource1;
   end else begin
   ADOTable1.Close;
   AdoTable2.Close;
   AdoTable2.Open;
   RXDBGrid1.Datasource:=Datasource2;
   DBNavigator1.Datasource:=Datasource2;
end;
end;

??????

0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6391729
Hello again

  I think that what you need?

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  Case RadioGroup1.ItemIndex of
  0 :
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable1.Open;
      DataSource1.DataSet :=ADOTable1;
    end;
  1 :
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable2.Open;
      DataSource1.DataSet :=ADOTable2;
    end;
  2:
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable3.Open;
      DataSource1.DataSet :=ADOTable3;
    end;
  end; // case statment
  // no need to duplicate the code for each section, just here only
  RXDBGrid1.DataSource := DataSource1;
  DBNavigator1.DataSource := DataSource1;
end;

// if you click here you will know which talbe assign to the datasource1
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(DataSource1.DataSet.GetNamePath);
end;

Best regards
Mohammed
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 100 total points
ID: 6391756
Hello again

  I think that what you need?

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  Case RadioGroup1.ItemIndex of
  0 :
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable1.Open;
      DataSource1.DataSet :=ADOTable1;
    end;
  1 :
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable2.Open;
      DataSource1.DataSet :=ADOTable2;
    end;
  2:
    begin
      ADOTable1.Close;
      ADOTable2.Close;
      ADOTable3.Close;
      ADOTable3.Open;
      DataSource1.DataSet :=ADOTable3;
    end;
  end; // case statment
  // no need to duplicate the code for each section, just here only
  RXDBGrid1.DataSource := DataSource1;
  DBNavigator1.DataSource := DataSource1;
end;

// if you click here you will know which talbe assign to the datasource1
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(DataSource1.DataSet.GetNamePath);
end;

Best regards
Mohammed
0
 

Author Comment

by:Bosanac
ID: 6393152
By the way Mohammed...I fully support you and your people in Palestine.
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6394458
Thanks alot
are you from Bosna?
0
 

Author Comment

by:Bosanac
ID: 6394873
Yep!
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6399260
I'm care and support your people too
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question