Solved

switch between tables

Posted on 2001-08-12
13
151 Views
Last Modified: 2010-04-06
How can I switch between tables by means of radiobuttons?
(Using ADO)
0
Comment
Question by:Bosanac
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now