Solved

switch between tables

Posted on 2001-08-12
13
148 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:mnasman
Comment Utility
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:mnasman
Comment Utility
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:mnasman
Comment Utility
sorry again

 change this line
if RadioGroup1.ItemIndex =0 then

to

if RadioGroup1.ItemIndex >=0 then
0
 

Author Comment

by:Bosanac
Comment Utility
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:mnasman
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Bosanac
Comment Utility
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:mnasman
Comment Utility
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:
mnasman earned 100 total points
Comment Utility
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
Comment Utility
By the way Mohammed...I fully support you and your people in Palestine.
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
Thanks alot
are you from Bosna?
0
 

Author Comment

by:Bosanac
Comment Utility
Yep!
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
I'm care and support your people too
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

7 Experts available now in Live!

Get 1:1 Help Now