Solved

switch between tables

Posted on 2001-08-12
13
156 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 104
Tembedded WB animatid gifs not animated on some pcs 2 84
DBGrid or StringGrid ? 6 105
Delphi: sending SMS on android platform 1 37
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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